Return the local inertia tensor of the capsule * @param mass Mass to use to compute the inertia tensor of the collision shape */
| 49 | * @param mass Mass to use to compute the inertia tensor of the collision shape |
| 50 | */ |
| 51 | Vector3 CapsuleShape::getLocalInertiaTensor(decimal mass) const { |
| 52 | |
| 53 | // The inertia tensor formula for a capsule can be found in : Game Engine Gems, Volume 1 |
| 54 | |
| 55 | const decimal height = mHalfHeight + mHalfHeight; |
| 56 | const decimal radiusSquare = mMargin * mMargin; |
| 57 | const decimal heightSquare = height * height; |
| 58 | const decimal radiusSquareDouble = radiusSquare + radiusSquare; |
| 59 | const decimal factor1 = decimal(2.0) * mMargin / (decimal(4.0) * mMargin + decimal(3.0) * height); |
| 60 | const decimal factor2 = decimal(3.0) * height / (decimal(4.0) * mMargin + decimal(3.0) * height); |
| 61 | const decimal sum1 = decimal(0.4) * radiusSquareDouble; |
| 62 | const decimal sum2 = decimal(0.75) * height * mMargin + decimal(0.5) * heightSquare; |
| 63 | const decimal sum3 = decimal(0.25) * radiusSquare + decimal(1.0 / 12.0) * heightSquare; |
| 64 | const decimal IxxAndzz = factor1 * mass * (sum1 + sum2) + factor2 * mass * sum3; |
| 65 | const decimal Iyy = factor1 * mass * sum1 + factor2 * mass * decimal(0.25) * radiusSquareDouble; |
| 66 | return Vector3(IxxAndzz, Iyy, IxxAndzz); |
| 67 | } |
| 68 | |
| 69 | // Return true if a point is inside the collision shape |
| 70 | bool CapsuleShape::testPointInside(const Vector3& localPoint, Collider* /*collider*/) const { |