PDA

View Full Version : Bone Hierarchies; finding absolute position


MacFiend
2003.03.24, 03:19 AM
In my ongoing escapade of skeletal animation...

lets say I have 2 bones: BoneA and BoneB. BoneB is a child bone of BoneA. When BoneA moves, BoneB moves, and likewise for rotations.

Now thats fine for getting a bone-based mesh to the screen, but I need to know the actual position of BoneB after it has undergone the series of translations/rotations yielded by its parent bone. To clarify what I mean, let me apply this to a real situation...*wink*


A model of a Hummer has a model of a .50 cal machine gun mounted on top of it. The mesh of the Hummer is attached to Joint A. The machine gun is attached to the Hummer at Joint B as a child of Joint A, and the mesh of the machine gun is attached to Joint C as a child of Joint B. When the machine gun fires a round, the round starts at Joint C (the tip of the barrel). As Joint A moves, Joints B and C move along. Now if the machine gun is pitched upwards (Joint B X-Axis), Joint C will rotate as well around Joint B.


I hope you follow me so far. Now if none of the bones (Joints) are rotated, it would be fairly easy to plot the starting point of a round fired by the machine gun. But since that's not the case, does anybody know of a way to figure out the absolute position of Joint C (world coordinates) based on the transformations of its parent?

codemattic
2003.03.24, 03:57 AM
Each bone has a rotation matrix for the direction it is rotated in relative to its parent bone. You may also want to store in each bone an accumulation matrix - which is the accumulation of all the matricies from the root bone up to (but not including) itself. You also have a location *vector* which is its location relative to its parent bone.

Each rotation matrix is a 3x3 matrix - which is really made up of three vectors. A forward vector - a right vector - and an up vector.
So take the bone's location vector's X component and multiply that by the right vector, Y by the up vector and Z by the forward vector. This new vector is the rotated offset from the parents location.

When you have the identity matrix (no rotation) - the forward vector is the same as the positive z axis, the right vector is the same as positive x and up the same as positive y. So the vector doesnt change.

hth,
Codemattic