Changeset 8393 for code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
- Timestamp:
- May 3, 2011, 5:07:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
r8351 r8393 48 48 void btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 49 49 { 50 //approximation of box shape, todo: implement cylinder shape inertia before people notice ;-) 50 51 //Until Bullet 2.77 a box approximation was used, so uncomment this if you need backwards compatibility 52 //#define USE_BOX_INERTIA_APPROXIMATION 1 53 #ifndef USE_BOX_INERTIA_APPROXIMATION 54 55 /* 56 cylinder is defined as following: 57 * 58 * - principle axis aligned along y by default, radius in x, z-value not used 59 * - for btCylinderShapeX: principle axis aligned along x, radius in y direction, z-value not used 60 * - for btCylinderShapeZ: principle axis aligned along z, radius in x direction, y-value not used 61 * 62 */ 63 64 btScalar radius2; // square of cylinder radius 65 btScalar height2; // square of cylinder height 66 btVector3 halfExtents = getHalfExtentsWithMargin(); // get cylinder dimension 67 btScalar div12 = mass / 12.f; 68 btScalar div4 = mass / 4.f; 69 btScalar div2 = mass / 2.f; 70 int idxRadius, idxHeight; 71 72 switch (m_upAxis) // get indices of radius and height of cylinder 73 { 74 case 0: // cylinder is aligned along x 75 idxRadius = 1; 76 idxHeight = 0; 77 break; 78 case 2: // cylinder is aligned along z 79 idxRadius = 0; 80 idxHeight = 2; 81 break; 82 default: // cylinder is aligned along y 83 idxRadius = 0; 84 idxHeight = 1; 85 } 86 87 // calculate squares 88 radius2 = halfExtents[idxRadius] * halfExtents[idxRadius]; 89 height2 = btScalar(4.) * halfExtents[idxHeight] * halfExtents[idxHeight]; 90 91 // calculate tensor terms 92 btScalar t1 = div12 * height2 + div4 * radius2; 93 btScalar t2 = div2 * radius2; 94 95 switch (m_upAxis) // set diagonal elements of inertia tensor 96 { 97 case 0: // cylinder is aligned along x 98 inertia.setValue(t2,t1,t1); 99 break; 100 case 2: // cylinder is aligned along z 101 inertia.setValue(t1,t1,t2); 102 break; 103 default: // cylinder is aligned along y 104 inertia.setValue(t1,t2,t1); 105 } 106 #else //USE_BOX_INERTIA_APPROXIMATION 107 //approximation of box shape 51 108 btVector3 halfExtents = getHalfExtentsWithMargin(); 52 109 … … 58 115 mass/(btScalar(12.0)) * (lx*lx + lz*lz), 59 116 mass/(btScalar(12.0)) * (lx*lx + ly*ly)); 60 117 #endif //USE_BOX_INERTIA_APPROXIMATION 61 118 } 62 119
Note: See TracChangeset
for help on using the changeset viewer.