Sign in to follow this  
spek

Limit a rotation matrix for skeleton animations

Recommended Posts

spek    1240
Hi, How to limit a rotation matrix? I made an animation system with skeletons where each bone has a matrix. Now I'd like to focus a joint at a certain point, for example aim the head at you. So far it works as follow: - create a rotation matrix where its directions aim at the target matrix[2] = normalize( targetPoint.xyz - jointWorldPos.xyz ); matrix[1] = up, matrix[0] = cross( up, matrix[2] ) - multiply this matrix with the basePose joint matrix - set the result matrix into the joint This works, but the rotation won't be limited. My character can turn its head 360 degrees like the Exorcist :) I guess I need to know the current parentBone matrix and apply a maximum pitch/turn/roll or cone angle like often seen in physical ball-socket joints. But how?

Share this post


Link to post
Share on other sites
haegarr    7372
E.g. after computing the forward vector by normalize( targetPoint.xyz - jointWorldPos.xyz ), compare that vector with the standard (i.e. rest pose) forward vector by using the dot-product. Since both vectors are of unit length, the dot-product gives you
a . b = cos( <a, b> )
the cosine of the angle between the both vectors. If the cosine is less than the cosine of your limit angle, then proceed as usual. Otherwise re-calculate the forward vector using the limit angle, and then proceed as usual.

That should work like a cone limitation. Just an idea.

Share this post


Link to post
Share on other sites
spek    1240
Hmmm... I was able to get the forward vector. But instead of the base pose, I used the current forward(world) vector of its parent bone. The absolute limit vectors of your head would also depend on the rest of your bodypose.

Anyway, it works! That is rare, most times I get completely lost when the "math hits the fan". Maybe I need to define two seperate limits though. In some situations the maximum twist might be bigger than the pitch, or vice versa. But for now I'm happy :)

Thanks

Share this post


Link to post
Share on other sites
Buckeye    10747
Quote:
But instead of the base pose, I used the current forward(world) vector of its parent bone.

Yeah, you should be using the animated reference frame. However, you may be just lucky using the parent. Apparently the angular alignment of the parent and child are the same. [WINK]

If you have the forward world vector of the joint in the rest pose, you can use that with the joint's world animation matrix to get the animated forward vector of the joint.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this