///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia ///and the center of mass to the current coordinate system. A mass of 1 is assumed, for other masses just multiply the computed "inertia" ///by the mass. The resulting transform "principal" has to be applied inversely to the mesh in order for the local coordinate system of the ///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform ///of the collision object by the principal transform. This method also computes the volume of the convex mesh. public void CalculatePrincipalAxisTransform(ref IndexedMatrix principal, out IndexedVector3 inertia, float volume) { CenterCallback centerCallback = new CenterCallback(); IndexedVector3 aabbMax = MathUtil.MAX_VECTOR; IndexedVector3 aabbMin = MathUtil.MIN_VECTOR; m_stridingMesh.InternalProcessAllTriangles(centerCallback, ref aabbMin, ref aabbMax); IndexedVector3 center = centerCallback.GetCenter(); principal._origin = center; volume = centerCallback.GetVolume(); InertiaCallback inertiaCallback = new InertiaCallback(ref center); m_stridingMesh.InternalProcessAllTriangles(inertiaCallback, ref aabbMax, ref aabbMax); IndexedBasisMatrix i = inertiaCallback.GetInertia(); i.Diagonalize(out principal, 0.00001f, 20); //i.diagonalize(principal.getBasis(), 0.00001f, 20); inertia = new IndexedVector3(i[0, 0], i[1, 1], i[2, 2]); inertia /= volume; }
///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia ///and the center of mass to the current coordinate system. A mass of 1 is assumed, for other masses just multiply the computed "inertia" ///by the mass. The resulting transform "principal" has to be applied inversely to the mesh in order for the local coordinate system of the ///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform ///of the collision object by the principal transform. This method also computes the volume of the convex mesh. public void CalculatePrincipalAxisTransform(ref IndexedMatrix principal, out IndexedVector3 inertia, float volume) { CenterCallback centerCallback = new CenterCallback(); IndexedVector3 aabbMax = MathUtil.MAX_VECTOR; IndexedVector3 aabbMin = MathUtil.MIN_VECTOR; m_stridingMesh.InternalProcessAllTriangles(centerCallback, ref aabbMin, ref aabbMax); IndexedVector3 center = centerCallback.GetCenter(); principal._origin = center; volume = centerCallback.GetVolume(); InertiaCallback inertiaCallback = new InertiaCallback(ref center); m_stridingMesh.InternalProcessAllTriangles(inertiaCallback, ref aabbMax, ref aabbMax); IndexedBasisMatrix i = inertiaCallback.GetInertia(); i.Diagonalize(out principal, 0.00001f, 20); //i.diagonalize(principal.getBasis(), 0.00001f, 20); inertia = new IndexedVector3(i[0,0],i[1,1],i[2,2]); inertia /= volume; }