protected void MakeInverseTransform( Vector3 position, Vector3 scale, Quaternion orientation, ref Matrix4 destMatrix )
{
// Invert the parameters
Vector3 invTranslate = -position;
Vector3 invScale = Vector3.Zero;
invScale.x = 1.0f / scale.x;
invScale.y = 1.0f / scale.y;
invScale.z = 1.0f / scale.z;
Quaternion invRot = orientation.Inverse();
// Because we're inverting, order is translation, rotation, scale
// So make translation relative to scale & rotation
invTranslate.x *= invScale.x; // scale
invTranslate.y *= invScale.y; // scale
invTranslate.z *= invScale.z; // scale
invTranslate = invRot * invTranslate; // rotate
// Next, make a 3x3 rotation matrix and apply inverse scale
Matrix3 rot3x3 = invRot.ToRotationMatrix();
Matrix3 scale3x3 = Matrix3.Zero;
scale3x3.m00 = invScale.x;
scale3x3.m11 = invScale.y;
scale3x3.m22 = invScale.z;
// Set up final matrix with scale & rotation
destMatrix = scale3x3 * rot3x3;
destMatrix.Translation = invTranslate;
}