Jump to content
  • Advertisement
Sign in to follow this  
howie_007

writing my own joint animation class

This topic is 3337 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 tackling this issue because I want to fully understand how it is done and one way to do this is write one from scratch. I believe I understand how this is done but I have a few questions just to confirm my thoughts. 1) Since we are talking about a series of joints and each joint effects the verts assigned to them as well as child joints and their verts, here is my thinking. My understanding is that rotation can only happen around 0,0,0 so since a given joint is not at 0,0,0, the verts assigned to that joint (including child joints and their verts) need to be translated to an offset where the parent joint is 0,0,0 before they can be rotated and then translated back after rotation. The same process is done for each child down the line. 2) During joint animation, triangle faces are rotated into new positions so new vertex normals will need to be calculated for each frame of the animation so that the model will react correctly to lighting conditions. Please let me know what you think.

Share this post


Link to post
Share on other sites
Advertisement
With respect to 1), you have the correct idea. The "base offset" matrix for each joint is the matrix which translates the joint from the rest pose to the origin.

With respect to 2), you don't need to recalculate the normal. You can use just the "rotation" portion of the joint animation matrix to transform it to the new orientation. The "rotation" portion is, instead of the full 4x4 matrix, just the upper left-hand 3x3 portion of the matrix. That rotates a vector (without translation).

Share this post


Link to post
Share on other sites
back to 2) Say you have a model of a dog and it's one mesh with all tri's connected. With the joints in place, the mesh is being deformed. I assume since the movement of the mesh changes most tri's in relation with other tri's, new vertex normals need to be generated for the light to be properly calculated.

Granted, if your model is a series of separate pieces moved by joints, each separate piece of mesh wouldn't need to have the vertex normals recalculated because each piece is only rotated and not changed on the vertex level. Is that what your talking about?

Share this post


Link to post
Share on other sites
You're correct if faces themselves are distorted during the animation. That is, if you have only 2 of the 3 vertices in a face associated with a joint.

It doesn't really matter if you have one mesh with all triangles connected, which would be the norm. It's only a matter of the faces themselves. If an entire face (3 vertices forming a triangle) is rotated, the method I described will still be valid.

Share this post


Link to post
Share on other sites
Now I understand. I keep forgetting that a surface normal or a vertex normal can be translated by the matrix. Since normals only describe direction, they don't have any inherent position which is why you only rotate them with the rotation part of the matrix. Got it.

Let's see if I have my matrix transformation concept correct.

Say for example we have a parent joint and one child joint. Each joint has it's own matrix class associated to it. This is what I think I would do.

// Move joint to 0,0,0
matrix.Translate( -(joint offset) );

// add rotation value
matrix.Rotate( joint rotation );

// Move the joint back
matrix.Translate( joint offset );

Now use the matrix to transform the assigned verts and their vertex normals.

For the child joint, I assume you do the same as above with one extra step at the end, merge the parent matrix into the child matrix and then do the transform of the child verts and vert normals.


Share this post


Link to post
Share on other sites
You have the general idea, but you need to check a few things for your implementation. I don't know your details.

You'll need three sets of matrices, if you want an animated mesh:
1. offset transforms (base pose with no animations) for each joint. Static.
2. "combined" transforms for each joint - the result of the animation rotations. Changes each frame.
3. "final" transforms for each joint - the total transform to be applied to the vertices that results in animation. Changes each frame.

The combined transforms are:
joint combined = joint animated transform * parent's animated transform

where the parent's animated transform is calculated before being applied to child joint. That's usually done recursively.

// instead of identity in the following,
// you can translate or rotate the entire animated mesh in the world
combineJointTransforms(root joint, identity);
...
void combineJointTransforms(joint, parent_tranform)
{
joint_combined = joint_animated * parent_transform;

if(joint has child) combineJointTransforms(joint_child, joint_combined);
}

Once that's done, then you apply the joint inverse transform

for each joint:
joint_final = -joint_offset * joint_combined;

In words, the joint_final transform is:
translate to origin
apply the joint's animation rotations
translate to parent's animated orientation

I've probably screwed something up, but that's the basic idea (which it appears you understand anyway).

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!