Jump to content
  • Advertisement
Sign in to follow this  

Multiple Mesh World Transformation help

This topic is 2781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I hope you can help me out with this. I'm attempting to manipulate the position and orientation of a human skeleton in a 3D environment. The skeleton is made up of multiple meshes (skull, body core, left arm, right arm).

The skull and body have the same center of rotation, but the arms have a center of rotation located at the top of each arm. (This is because I need to manipulate the arms separately from the body, later on).

My problem is, I can't seem to figure out the correct transformation to keep the arms with the body. My current code looks as follows (using SlimDX):

_device.SetTransform(TransformState.World, Matrix.Scaling(_scale, _scale, _scale)
* Matrix.RotationY(_skullYPR.Y) //Rotation about the Y axis
* Matrix.Translation(_position)); //Location in 3D space

//Right Upper Arm
_device.SetTransform(TransformState.World, Matrix.Scaling(_scale, _scale, _scale)
* Matrix.RotationY(_skullYPR.Y)
* Matrix.Translation(_position.X - 5.0f, _position.Y - 5.5f, _position.Z)); //Offset of arm position

This results in the arm remaining in the same position (with a proper rotation around it's own center of rotation) I've attach a couple images for you to reference.

I've tried adding additional rotation matrices, but I'm just having a brain fart right now and can't think it through properly.

The question is how do I properly apply a rotation that takes into account the translation from the center of the body?

Facing Forward, everything is ok. (I know a collar bone is missing :) )
[attachment=2199:facing forward.png]
Rotated, rotates in position, doesn't move with body

Any help or direction would be greatly appreciated!!!

Share this post

Link to post
Share on other sites
You want to build the transform of the child bones by appending them to the transforms of the parent bones.

First, some abbrebiations to make things simpler:

Mb: body matrix
Ma: arm matrix

Sb: body scale
Rb: body rotation
Tb: body translation
Sa: arm scale
Ra: arm rotation
Ta: arm translation

If your body matrix is defined like this:

Mb = Sb * Rb * Tb,

then your arm matrix would be defined like this:

Ma = Sa * Ra * Ta * Mb
Ma = Sa * Ra * Ta * Sb * Rb * Tb

Basically everything that you put on the left hand side adds to the chain of transforms. In this case the arm translation is only the offset from the center of the body to the arm position, it has nothing to do with the arm's global position. Because you're chaining it together with the body translation, you can say that the arm translation is defined in "body space", instead of "world space", where you would supply the actual coordinate of it. Again the arm rotation is only the rotation of the arm in its own local space, it doesn't have anything to do with the rotation of the body.

You could do a similar thing with a hand mesh, by defining its rotation and translation relative to the position of the arm.

Mh = Sh * Rh * Th * Sa * Ra * Ta * Sb * Rb * Tb.

This concept comes up a lot when doing animation, basically in the simplest explanation is that when you have an object whose transform is a derivative of some parent, then you want to define the position of the sub object relative to the coordinate space of the parent, don't try to compute it directly in the world space. Its the same concept whether you're dealing with hands on arms on torsos or moons orbiting planets orbiting stars.

Share this post

Link to post
Share on other sites
The keyword to look for is "forward kinematics", often simply called "parenting"; karwosts has described its math for row vectors and the usual transformation chain scale -> rotation -> translation.

However, the things may be more complicated dependent on how the various co-ordinate spaces in use are placed and related. Each mesh, when imported for its own, has its local co-ordinate space. The 1st transformation applied uses it as its reference. The 2nd transformation then is applied w.r.t. the so transformed space. The 3rd transformation ... and so on. Hence, you may need to adapt the space in order to apply a transformation in the desired space if that space isn't accidentally coincident with the current one. That means extra steps to take if e.g. the center of scaling and the center of rotation isn't the same point, or e.g. (using karwosts' solution) the co-ordinate frame of the arm isn't directly given w.r.t. the frame of the body.

Share this post

Link to post
Share on other sites
Perfect, thank you both! This makes complete sense.

My skeleton is now whole. :)

Thank you again for the clear explanation!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!