Bone Position/Rotation

Topics: User Forum
Mar 5, 2007 at 9:22 PM
i looked for this, but didn't see anything relevant. is there a method to get the current position and rotation of a given bone?

i am asking this because i am implementing a bounding box system which consists of a box for each relevant bone, on humanoids this would fit the body shape quite well, providing that you are able to move around and rotate the boxes according to the bones transformations.

surprise surprise, to do this i need access to the bones positions and rotations. so is there a way to get that data? oh, and if there is, how do i choose the correct bone?
Coordinator
Mar 7, 2007 at 3:35 AM
Edited Mar 7, 2007 at 3:49 AM
When I get the time to post the tutorials and the next release (something I intended to do a week ago but I've been very busy), I was going to post a tutorial on collision detection using bounding boxes on a per-bone basis. I have working code for this. You actually don't need to split up the transform into translation/rotation; instead, you can just create an initial bounding box for a bone, and just transform its corners by the absolute bone transform * world matrix to get the corners of the bounding box for the current frame.

Assuming you have an animator, here is how you can get the bone transform for a joint at the current frame:
        Matrix[] bones = new Matrix[model.Bones.Count];
        animator.CopyAbsoluteTransformsTo(bones);
        Matrix transform = bones[animator.BonePoses["MyBoneName"].Index];

If you still want to split it up into translation and rotation, you can do this:

Assuming you have an animator, here is how you can add this code:
        Vector3 translation = transform.Translation;
        Quaternion rotation = Quaternion.CreateFromRotationMatrix(transform);

The latest source allows you to call animator.GetAbsoluteTransform(int boneIndex) so you don't have to copy over all the transforms every frame.
Coordinator
Mar 8, 2007 at 6:52 PM
Check out the new collision detection tutorial. It does exactly what you want.
Mar 9, 2007 at 1:56 PM
thank you, i have done this, but surely confrontation with your way will be at least interesting, if not improving my code