[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | #include "btCylinderShape.h" |
---|
| 16 | #include "LinearMath/btPoint3.h" |
---|
| 17 | |
---|
| 18 | btCylinderShape::btCylinderShape (const btVector3& halfExtents) |
---|
| 19 | :btBoxShape(halfExtents), |
---|
| 20 | m_upAxis(1) |
---|
| 21 | { |
---|
| 22 | m_shapeType = CYLINDER_SHAPE_PROXYTYPE; |
---|
| 23 | recalcLocalAabb(); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents) |
---|
| 28 | :btCylinderShape(halfExtents) |
---|
| 29 | { |
---|
| 30 | m_upAxis = 0; |
---|
| 31 | recalcLocalAabb(); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents) |
---|
| 36 | :btCylinderShape(halfExtents) |
---|
| 37 | { |
---|
| 38 | m_upAxis = 2; |
---|
| 39 | recalcLocalAabb(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const |
---|
| 43 | { |
---|
| 44 | //skip the box 'getAabb' |
---|
| 45 | btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v) |
---|
| 50 | { |
---|
| 51 | const int cylinderUpAxis = 0; |
---|
| 52 | const int XX = 1; |
---|
| 53 | const int YY = 0; |
---|
| 54 | const int ZZ = 2; |
---|
| 55 | |
---|
| 56 | //mapping depends on how cylinder local orientation is |
---|
| 57 | // extents of the cylinder is: X,Y is for radius, and Z for height |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | btScalar radius = halfExtents[XX]; |
---|
| 61 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | btVector3 tmp; |
---|
| 65 | btScalar d ; |
---|
| 66 | |
---|
| 67 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 68 | if (s != btScalar(0.0)) |
---|
| 69 | { |
---|
| 70 | d = radius / s; |
---|
| 71 | tmp[XX] = v[XX] * d; |
---|
| 72 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 73 | tmp[ZZ] = v[ZZ] * d; |
---|
| 74 | return tmp; |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | { |
---|
| 78 | tmp[XX] = radius; |
---|
| 79 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 80 | tmp[ZZ] = btScalar(0.0); |
---|
| 81 | return tmp; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | inline btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v) |
---|
| 93 | { |
---|
| 94 | |
---|
| 95 | const int cylinderUpAxis = 1; |
---|
| 96 | const int XX = 0; |
---|
| 97 | const int YY = 1; |
---|
| 98 | const int ZZ = 2; |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | btScalar radius = halfExtents[XX]; |
---|
| 102 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | btVector3 tmp; |
---|
| 106 | btScalar d ; |
---|
| 107 | |
---|
| 108 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 109 | if (s != btScalar(0.0)) |
---|
| 110 | { |
---|
| 111 | d = radius / s; |
---|
| 112 | tmp[XX] = v[XX] * d; |
---|
| 113 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 114 | tmp[ZZ] = v[ZZ] * d; |
---|
| 115 | return tmp; |
---|
| 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
| 119 | tmp[XX] = radius; |
---|
| 120 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 121 | tmp[ZZ] = btScalar(0.0); |
---|
| 122 | return tmp; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v) |
---|
| 128 | { |
---|
| 129 | const int cylinderUpAxis = 2; |
---|
| 130 | const int XX = 0; |
---|
| 131 | const int YY = 2; |
---|
| 132 | const int ZZ = 1; |
---|
| 133 | |
---|
| 134 | //mapping depends on how cylinder local orientation is |
---|
| 135 | // extents of the cylinder is: X,Y is for radius, and Z for height |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | btScalar radius = halfExtents[XX]; |
---|
| 139 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | btVector3 tmp; |
---|
| 143 | btScalar d ; |
---|
| 144 | |
---|
| 145 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 146 | if (s != btScalar(0.0)) |
---|
| 147 | { |
---|
| 148 | d = radius / s; |
---|
| 149 | tmp[XX] = v[XX] * d; |
---|
| 150 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 151 | tmp[ZZ] = v[ZZ] * d; |
---|
| 152 | return tmp; |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | tmp[XX] = radius; |
---|
| 157 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 158 | tmp[ZZ] = btScalar(0.0); |
---|
| 159 | return tmp; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | btVector3 btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 166 | { |
---|
| 167 | return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | btVector3 btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 172 | { |
---|
| 173 | return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec); |
---|
| 174 | } |
---|
| 175 | btVector3 btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 176 | { |
---|
| 177 | return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | void btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 181 | { |
---|
| 182 | for (int i=0;i<numVectors;i++) |
---|
| 183 | { |
---|
| 184 | supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | void btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 189 | { |
---|
| 190 | for (int i=0;i<numVectors;i++) |
---|
| 191 | { |
---|
| 192 | supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | void btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 200 | { |
---|
| 201 | for (int i=0;i<numVectors;i++) |
---|
| 202 | { |
---|
| 203 | supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|