Java Cool Dude

04-09-2005, 04:11 PM

Say I have a hierarchy in my engine where nodes (TransformGroups) could have multiple children (TransformGroups and Shapes) and a single parent (again, a TransformGroup).

Every node has a private member Transform3D (Transformation matrix encapsulating Rotations, translations and Scalings).

Now the question is, how do I transform a 3D point from world position (The top node) to the node (object) space using the relationship that I described?

What I used to do is retrieving the inverse Transform of every node, multiply my world space position with it, and then seek the transform of the parent node (if it exists) and do the same thing until I reach the top node.

This worked great when I moved my objects around or even scaled them, however this implementation turned out to be flawed whenever I introduced rotations to the scene.

void TransformGroup::transformToObjectSpace(Tuple3f *result)

{

if(parent)

parent->transformToObjectSpace(result);

if(!transform.isInverseIdentity())

*result *= transform.getInverseMatrix4f();

}

void TransformGroup::transformToWorldSpace(Tuple3f *vPTR)

{

if(parent)

parent->transformToWorldSpace(vPTR);

*vPTR *= transform.getMatrix4f();

}

Every node has a private member Transform3D (Transformation matrix encapsulating Rotations, translations and Scalings).

Now the question is, how do I transform a 3D point from world position (The top node) to the node (object) space using the relationship that I described?

What I used to do is retrieving the inverse Transform of every node, multiply my world space position with it, and then seek the transform of the parent node (if it exists) and do the same thing until I reach the top node.

This worked great when I moved my objects around or even scaled them, however this implementation turned out to be flawed whenever I introduced rotations to the scene.

void TransformGroup::transformToObjectSpace(Tuple3f *result)

{

if(parent)

parent->transformToObjectSpace(result);

if(!transform.isInverseIdentity())

*result *= transform.getInverseMatrix4f();

}

void TransformGroup::transformToWorldSpace(Tuple3f *vPTR)

{

if(parent)

parent->transformToWorldSpace(vPTR);

*vPTR *= transform.getMatrix4f();

}