# Limit a rotation matrix for skeleton animations

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

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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.

• 16
• 9
• 13
• 41
• 15