What is the right / best way to limit 3D rotation (using Euler angles and / or quaternions)?
There seems to be something wrong with my way of doing this. I apply rotations to bones in the skeletal hierarchy for animation, and the bones sometimes noticeably “skip” to the wrong orientation, and individual Euler components wrap at the opposite end of their ranges.
I use Euler angles to represent the current orientation, turning into quaternions to rotate, and clamp each axis of the Euler angle independently. Here the C ++ pseudo-code shows basically what I am doing:
Euler min = ...;
Euler max = ...;
Quat rotation = ...;
Euler eCurrent = ...;
// do rotation
Quat qCurrent = eCurrent.toQuat();
qCurrent = qCurrent * rotation;
eCurrent = qCurrent.toEuler();
// constrain
for (unsigned int i = 0; i < 3; i++)
eCurrent[i] = clamp(eCurrent[i], min[i], max[i]);
Ktc source
share