1
\$\begingroup\$

I have a problem where I'm performing an axis-angle rotation and am trying to constrain my rotations. Specifically I have a skeleton (model/mesh with rig, transforms are hierarchy parented to pelvis which move the triangles of the mesh) and I am constraining the motions to prevent bad joint rotations (e.g. knees bending sideways or backwards). The rotations in this case can pretty much be constrained by saying "do not rotate about X/Y/Z."

I'm using the Unity3D RotateAround function which rotates about a specified axis at a point by an arbitrary angle. Given control over this point, axis, and angle how can I constrain this rotation to prevent "bad" rotations?

\$\endgroup\$
1
\$\begingroup\$

I spent a while chasing ways to change my problem to use Euler angles, but the easy solution was actually to just 0 the components of the axis I didn't want, i.e. (in C# Unity script)

Vector3 axis = Vector3.Cross(RD, RE);
axis.x = CanPitch() ? axis.x : 0.0f;
axis.y = CanYaw() ? axis.y : 0.0f;
axis.z = CanRoll() ? axis.z : 0.0f;

where RD and RE are Vector3's and CanRoll(), CanPitch(), and CanYaw() are functions that return a boolean value indicating if roll, pitch, and yaw are allowed on this joint (rotations about z, x, or y axes respectively).

This seems like a very obvious answer, but I spent awhile trying to verify that this actually does what I want.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.