## Joint animation: what's wrong with this?

### Joint animation: what's wrong with this?

Due to a lack of clues, I'm here again with this annoying (very much indeed) problem, begging help again to our panda gurus

Let's suppose to have a bone-animated model like this:

for simplicity suppose to animate Bone.001 along the z axis , just like this:

Sadly what I got with my exporter is the correct joint Bone001 axis rotation along the z axis but of the bone structure origin instead of the joint origin such as:

So my question is: what's wrong with this code? His structure looks good to me and the behaviour, wrong rotation origin apart, is close to be correct so is there some good soul that is able to tellme what the heck is wrong with it?

astelix

Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

Sorry it took me a while to get a chance to take a look at this.

In Panda joints, as in the scene graph, when you set a rotation, it always rotates about the origin of the joint: the local (0, 0, 0) point. In many animation packages, however, it is possible to specify an explicit rotate pivot, which is different from the (0, 0, 0) point.

Your joint Bone.001 does not have any translation offset from its parent, so its local (0, 0, 0) point is the same as that of its parent, and thus when you rotate Bone.001, it rotates around the parent's origin.

It might be that you intended to include a translation offset for Bone.001. Or, maybe the offset is indeed supposed to be (0, 0, 0), but you intended to specify an explicit rotate pivot, so that it rotate around some point other than (0, 0, 0). In order to implement a rotate pivot, you have to build a matrix for the joint animation, of the form:

joint = LMatrix4f::translate_mat(-pivot) * rotate_mat * LMatrix4f::translate_mat(pivot).

A matrix of this form translates the pivot to the origin, performs the rotation, and then translates the pivot back. When you compose matrices like this, you end up with one matrix that performs the overall resulting transform. You can therefore perform this matrix compose for each frame, and add the resulting matrix to the animation table for each frame; the result will be the appropriate animation.

David
drwr

Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

drwr wrote:Sorry it took me a while to get a chance to take a look at this.

dunno if is true also for you Americans, but here wa say 'better late than never'

drwr wrote:In Panda joints, as in the scene graph, when you set a rotation, it always rotates about the origin of the joint: the local (0, 0, 0) point. In many animation packages, however, it is possible to specify an explicit rotate pivot, which is different from the (0, 0, 0) point.

Your joint Bone.001 does not have any translation offset from its parent, so its local (0, 0, 0) point is the same as that of its parent, and thus when you rotate Bone.001, it rotates around the parent's origin.

It might be that you intended to include a translation offset for Bone.001. Or, maybe the offset is indeed supposed to be (0, 0, 0), but you intended to specify an explicit rotate pivot, so that it rotate around some point other than (0, 0, 0). In order to implement a rotate pivot, you have to build a matrix for the joint animation, of the form:

joint = LMatrix4f::translate_mat(-pivot) * rotate_mat * LMatrix4f::translate_mat(pivot).

A matrix of this form translates the pivot to the origin, performs the rotation, and then translates the pivot back. When you compose matrices like this, you end up with one matrix that performs the overall resulting transform. You can therefore perform this matrix compose for each frame, and add the resulting matrix to the animation table for each frame; the result will be the appropriate animation.

so, to put it simple, this means that I got to add a <Scalar> {xyz} for each animation frame even if the bone is just rotating?

astelix

Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA

so, to put it simple, this means that I got to add a <Scalar> {xyz} for each animation frame even if the bone is just rotating?

Right. And this same translation should be in the rest matrix, as well as in the per-frame data.

David
drwr

Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

astelix wrote:dunno if is true also for you Americans, but here wa say 'better late than never'
Yeah, Americans say that too.
I got to add a <Scalar> {xyz} for each animation frame
If that's too much to do by hand, it should be easy enough to write a Python script to do it for you. Or better yet, add the correction code to the exporter script.

Which exporter are you using anyway?

Cyan

Posts: 215
Joined: Fri Jul 14, 2006 12:26 pm
Location: Utah

Cyan wrote:
astelix wrote:dunno if is true also for you Americans, but here wa say 'better late than never'
Yeah, Americans say that too.
I got to add a <Scalar> {xyz} for each animation frame
If that's too much to do by hand, it should be easy enough to write a Python script to do it for you. Or better yet, add the correction code to the exporter script.

Which exporter are you using anyway?

This problem is related to my own python Blender exporter - I'm stuck here from before holidays...
http://panda3d.org/phpbb2/viewtopic.php?t=1627

astelix

Posts: 866
Joined: Mon Mar 27, 2006 4:36 pm
Location: Milano, ITA