calculateLocalInertia method

  1. @override
Vec3 calculateLocalInertia(
  1. double mass,
  2. Vec3 target
)
override

Calculates the inertia in the local frame for this shape. @see http://en.wikipedia.org/wiki/List_of_moments_of_inertia

Implementation

@override
Vec3 calculateLocalInertia(double mass, final Vec3 target) {
  // Approximate with box inertia
  // Exact inertia calculation is overkill, but see http://geometrictools.com/Documentation/PolyhedralMassProperties.pdf for the correct way to do it

  computeLocalAABB(aabbmin, aabbmax);
  final x = aabbmax.x - aabbmin.x;
  final y = aabbmax.y - aabbmin.y;
  final z = aabbmax.z - aabbmin.z;
  target.x = (1.0 / 12.0) * mass * (2 * y * 2 * y + 2 * z * 2 * z);
  target.y = (1.0 / 12.0) * mass * (2 * x * 2 * x + 2 * z * 2 * z);
  target.z = (1.0 / 12.0) * mass * (2 * y * 2 * y + 2 * x * 2 * x);

  return target;
}