/** * @param[out] tensor The 3x3 inertia tensor matrix of the shape in local-space * coordinates * @param mass Mass to use to compute the inertia tensor of the collision shape */ void BoxShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const { decimal factor = (decimal(1.0) / decimal(3.0)) * mass; Vector3 realExtent = mExtent + Vector3(mMargin, mMargin, mMargin); decimal xSquare = realExtent.x * realExtent.x; decimal ySquare = realExtent.y * realExtent.y; decimal zSquare = realExtent.z * realExtent.z; tensor.setAllValues(factor * (ySquare + zSquare), 0.0, 0.0, 0.0, factor * (xSquare + zSquare), 0.0, 0.0, 0.0, factor * (xSquare + ySquare)); }
/** * @param[out] tensor The 3x3 inertia tensor matrix of the shape in local-space * coordinates * @param mass Mass to use to compute the inertia tensor of the collision shape */ void CapsuleShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const { // The inertia tensor formula for a capsule can be found in : Game Engine Gems, Volume 1 decimal height = mHalfHeight + mHalfHeight; decimal radiusSquare = mRadius * mRadius; decimal heightSquare = height * height; decimal radiusSquareDouble = radiusSquare + radiusSquare; decimal factor1 = decimal(2.0) * mRadius / (decimal(4.0) * mRadius + decimal(3.0) * height); decimal factor2 = decimal(3.0) * height / (decimal(4.0) * mRadius + decimal(3.0) * height); decimal sum1 = decimal(0.4) * radiusSquareDouble; decimal sum2 = decimal(0.75) * height * mRadius + decimal(0.5) * heightSquare; decimal sum3 = decimal(0.25) * radiusSquare + decimal(1.0 / 12.0) * heightSquare; decimal IxxAndzz = factor1 * mass * (sum1 + sum2) + factor2 * mass * sum3; decimal Iyy = factor1 * mass * sum1 + factor2 * mass * decimal(0.25) * radiusSquareDouble; tensor.setAllValues(IxxAndzz, 0.0, 0.0, 0.0, Iyy, 0.0, 0.0, 0.0, IxxAndzz); }