Game Development Reference
In-Depth Information
In fact, in the acceleration equation
θ
I 1 τ
=
the torque τ and the resulting angular acceleration θ are both given relative to the
world axes. So the inertia tensor we need should also be given in world coordinates.
We don't want to have to recalculate the inertia tensor by summing masses at
each frame, so we need a simpler way to get the inertia tensor in world coordinates.
We can achieve this by creating a new derived quantity: the inverse inertia tensor
in world coordinates. At each frame we can apply a change of basis transformation
to convert the constant inertia tensor in object coordinates into the corresponding
matrix in world coordinates.
As with the transform matrix we add an update to recalculate the derived quantity
at each frame. It gets put together in this way:
Excerpt from src/body.cpp
/**
* Internal function to do an inertia tensor transform by a quaternion.
* Note that the implementation of this function was created by an
* automated code generator and optimizer.
*/
static inline void _transformInertiaTensor(Matrix3 &iitWorld,
const Quaternion &q,
const Matrix3 &iitBody,
const Matrix4 &rotmat)
{
real t4 = rotmat.data[0]*iitBody.data[0]+
rotmat.data[1]*iitBody.data[3]+
rotmat.data[2]*iitBody.data[6];
real t9 = rotmat.data[0]*iitBody.data[1]+
rotmat.data[1]*iitBody.data[4]+
rotmat.data[2]*iitBody.data[7];
real t14 = rotmat.data[0]*iitBody.data[2]+
rotmat.data[1]*iitBody.data[5]+
rotmat.data[2]*iitBody.data[8];
real t28 = rotmat.data[4]*iitBody.data[0]+
rotmat.data[5]*iitBody.data[3]+
rotmat.data[6]*iitBody.data[6];
real t33 = rotmat.data[4]*iitBody.data[1]+
rotmat.data[5]*iitBody.data[4]+
rotmat.data[6]*iitBody.data[7];
real t38 = rotmat.data[4]*iitBody.data[2]+
rotmat.data[5]*iitBody.data[5]+
rotmat.data[6]*iitBody.data[8];
Search Nedrilad ::




Custom Search