btCylinderShape.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "btCylinderShape.h"
00017
00018 btCylinderShape::btCylinderShape (const btVector3& halfExtents)
00019 :btConvexInternalShape(),
00020 m_upAxis(1)
00021 {
00022 btVector3 margin(getMargin(),getMargin(),getMargin());
00023 m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin;
00024 m_shapeType = CYLINDER_SHAPE_PROXYTYPE;
00025 }
00026
00027
00028 btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents)
00029 :btCylinderShape(halfExtents)
00030 {
00031 m_upAxis = 0;
00032
00033 }
00034
00035
00036 btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents)
00037 :btCylinderShape(halfExtents)
00038 {
00039 m_upAxis = 2;
00040
00041 }
00042
00043 void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00044 {
00045 btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
00046 }
00047
00048 void btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
00049 {
00050
00051 btVector3 halfExtents = getHalfExtentsWithMargin();
00052
00053 btScalar lx=btScalar(2.)*(halfExtents.x());
00054 btScalar ly=btScalar(2.)*(halfExtents.y());
00055 btScalar lz=btScalar(2.)*(halfExtents.z());
00056
00057 inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
00058 mass/(btScalar(12.0)) * (lx*lx + lz*lz),
00059 mass/(btScalar(12.0)) * (lx*lx + ly*ly));
00060
00061 }
00062
00063
00064 SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v)
00065 {
00066 const int cylinderUpAxis = 0;
00067 const int XX = 1;
00068 const int YY = 0;
00069 const int ZZ = 2;
00070
00071
00072
00073
00074
00075 btScalar radius = halfExtents[XX];
00076 btScalar halfHeight = halfExtents[cylinderUpAxis];
00077
00078
00079 btVector3 tmp;
00080 btScalar d ;
00081
00082 btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00083 if (s != btScalar(0.0))
00084 {
00085 d = radius / s;
00086 tmp[XX] = v[XX] * d;
00087 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00088 tmp[ZZ] = v[ZZ] * d;
00089 return tmp;
00090 }
00091 else
00092 {
00093 tmp[XX] = radius;
00094 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00095 tmp[ZZ] = btScalar(0.0);
00096 return tmp;
00097 }
00098
00099
00100 }
00101
00102
00103
00104
00105
00106
00107 inline btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v)
00108 {
00109
00110 const int cylinderUpAxis = 1;
00111 const int XX = 0;
00112 const int YY = 1;
00113 const int ZZ = 2;
00114
00115
00116 btScalar radius = halfExtents[XX];
00117 btScalar halfHeight = halfExtents[cylinderUpAxis];
00118
00119
00120 btVector3 tmp;
00121 btScalar d ;
00122
00123 btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00124 if (s != btScalar(0.0))
00125 {
00126 d = radius / s;
00127 tmp[XX] = v[XX] * d;
00128 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00129 tmp[ZZ] = v[ZZ] * d;
00130 return tmp;
00131 }
00132 else
00133 {
00134 tmp[XX] = radius;
00135 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00136 tmp[ZZ] = btScalar(0.0);
00137 return tmp;
00138 }
00139
00140 }
00141
00142 inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v)
00143 {
00144 const int cylinderUpAxis = 2;
00145 const int XX = 0;
00146 const int YY = 2;
00147 const int ZZ = 1;
00148
00149
00150
00151
00152
00153 btScalar radius = halfExtents[XX];
00154 btScalar halfHeight = halfExtents[cylinderUpAxis];
00155
00156
00157 btVector3 tmp;
00158 btScalar d ;
00159
00160 btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
00161 if (s != btScalar(0.0))
00162 {
00163 d = radius / s;
00164 tmp[XX] = v[XX] * d;
00165 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00166 tmp[ZZ] = v[ZZ] * d;
00167 return tmp;
00168 }
00169 else
00170 {
00171 tmp[XX] = radius;
00172 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
00173 tmp[ZZ] = btScalar(0.0);
00174 return tmp;
00175 }
00176
00177
00178 }
00179
00180 btVector3 btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00181 {
00182 return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec);
00183 }
00184
00185
00186 btVector3 btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00187 {
00188 return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec);
00189 }
00190 btVector3 btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
00191 {
00192 return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec);
00193 }
00194
00195 void btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00196 {
00197 for (int i=0;i<numVectors;i++)
00198 {
00199 supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]);
00200 }
00201 }
00202
00203 void btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00204 {
00205 for (int i=0;i<numVectors;i++)
00206 {
00207 supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]);
00208 }
00209 }
00210
00211
00212
00213
00214 void btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
00215 {
00216 for (int i=0;i<numVectors;i++)
00217 {
00218 supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]);
00219 }
00220 }
00221
00222