[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 | |
---|
| 17 | btCylinderShape::btCylinderShape (const btVector3& halfExtents) |
---|
| 18 | :btBoxShape(halfExtents), |
---|
| 19 | m_upAxis(1) |
---|
| 20 | { |
---|
| 21 | m_shapeType = CYLINDER_SHAPE_PROXYTYPE; |
---|
| 22 | recalcLocalAabb(); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents) |
---|
| 27 | :btCylinderShape(halfExtents) |
---|
| 28 | { |
---|
| 29 | m_upAxis = 0; |
---|
| 30 | recalcLocalAabb(); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents) |
---|
| 35 | :btCylinderShape(halfExtents) |
---|
| 36 | { |
---|
| 37 | m_upAxis = 2; |
---|
| 38 | recalcLocalAabb(); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const |
---|
| 42 | { |
---|
| 43 | //skip the box 'getAabb' |
---|
| 44 | btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v) |
---|
| 49 | { |
---|
| 50 | const int cylinderUpAxis = 0; |
---|
| 51 | const int XX = 1; |
---|
| 52 | const int YY = 0; |
---|
| 53 | const int ZZ = 2; |
---|
| 54 | |
---|
| 55 | //mapping depends on how cylinder local orientation is |
---|
| 56 | // extents of the cylinder is: X,Y is for radius, and Z for height |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | btScalar radius = halfExtents[XX]; |
---|
| 60 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | btVector3 tmp; |
---|
| 64 | btScalar d ; |
---|
| 65 | |
---|
| 66 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 67 | if (s != btScalar(0.0)) |
---|
| 68 | { |
---|
| 69 | d = radius / s; |
---|
| 70 | tmp[XX] = v[XX] * d; |
---|
| 71 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 72 | tmp[ZZ] = v[ZZ] * d; |
---|
| 73 | return tmp; |
---|
| 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
| 77 | tmp[XX] = radius; |
---|
| 78 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 79 | tmp[ZZ] = btScalar(0.0); |
---|
| 80 | return tmp; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | inline btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v) |
---|
| 92 | { |
---|
| 93 | |
---|
| 94 | const int cylinderUpAxis = 1; |
---|
| 95 | const int XX = 0; |
---|
| 96 | const int YY = 1; |
---|
| 97 | const int ZZ = 2; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | btScalar radius = halfExtents[XX]; |
---|
| 101 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | btVector3 tmp; |
---|
| 105 | btScalar d ; |
---|
| 106 | |
---|
| 107 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 108 | if (s != btScalar(0.0)) |
---|
| 109 | { |
---|
| 110 | d = radius / s; |
---|
| 111 | tmp[XX] = v[XX] * d; |
---|
| 112 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 113 | tmp[ZZ] = v[ZZ] * d; |
---|
| 114 | return tmp; |
---|
| 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | tmp[XX] = radius; |
---|
| 119 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 120 | tmp[ZZ] = btScalar(0.0); |
---|
| 121 | return tmp; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v) |
---|
| 127 | { |
---|
| 128 | const int cylinderUpAxis = 2; |
---|
| 129 | const int XX = 0; |
---|
| 130 | const int YY = 2; |
---|
| 131 | const int ZZ = 1; |
---|
| 132 | |
---|
| 133 | //mapping depends on how cylinder local orientation is |
---|
| 134 | // extents of the cylinder is: X,Y is for radius, and Z for height |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | btScalar radius = halfExtents[XX]; |
---|
| 138 | btScalar halfHeight = halfExtents[cylinderUpAxis]; |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | btVector3 tmp; |
---|
| 142 | btScalar d ; |
---|
| 143 | |
---|
| 144 | btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); |
---|
| 145 | if (s != btScalar(0.0)) |
---|
| 146 | { |
---|
| 147 | d = radius / s; |
---|
| 148 | tmp[XX] = v[XX] * d; |
---|
| 149 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 150 | tmp[ZZ] = v[ZZ] * d; |
---|
| 151 | return tmp; |
---|
| 152 | } |
---|
| 153 | else |
---|
| 154 | { |
---|
| 155 | tmp[XX] = radius; |
---|
| 156 | tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; |
---|
| 157 | tmp[ZZ] = btScalar(0.0); |
---|
| 158 | return tmp; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | btVector3 btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 165 | { |
---|
| 166 | return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | btVector3 btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 171 | { |
---|
| 172 | return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec); |
---|
| 173 | } |
---|
| 174 | btVector3 btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const |
---|
| 175 | { |
---|
| 176 | return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | void btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 180 | { |
---|
| 181 | for (int i=0;i<numVectors;i++) |
---|
| 182 | { |
---|
| 183 | supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | void btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 188 | { |
---|
| 189 | for (int i=0;i<numVectors;i++) |
---|
| 190 | { |
---|
| 191 | supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | void btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const |
---|
| 199 | { |
---|
| 200 | for (int i=0;i<numVectors;i++) |
---|
| 201 | { |
---|
| 202 | supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|