Hi all
I’ve got this IK problem with meeting DOF restrictions with a 3D skeleton character, I think my problem is in some bit of code where I do Quaternion->EulerAngles, I’ve tried searching around for a function to do this just in case mine was incorrect, but found none, so now I would like to ask another question in order to try a different approach. Please have in mind that I’m no math expert so make it easy
I’ve got this skeleton system where DOF restrictions of the bones are saved as euler angles, in degrees (e.g. upper arm is restricted to ±45 deg in the z axis, ±90 in the x axis, etc.). So I’m calculating IK rotations of the limbs by using quaternions and the CCD method, but when it comes to verifying DOF restricts, I don’t know how to “compare” the current rotation (quaternion) with the DOF restrictions (degrees) in order to make them meet the restrictions, without doing what I’m currently doing, that is converting quats to euler and then viceversa.
Currently I’m doing this:
void CSkeleton::CheckDOFRestrictions(CBone *link)
{
/// Local Variables ///////////////////////////////////////////////////////////
CVertex euler; // PLACE TO STORE EULER ANGLES
///////////////////////////////////////////////////////////////////////////////
//if(quat
// FIRST STEP IS TO CONVERT LINK QUATERNION BACK TO EULER ANGLES
QuatToEuler(&link->quat, &euler);
//prev = link->quat;
//printf("Ángulo %f,%f,%f
", euler.x,euler.y,euler.z);
// CHECK THE DOF SETTINGS
if (euler.x > (float)link->max_rx)
euler.x = (float)link->max_rx;
if (euler.x < (float)link->min_rx)
euler.x = (float)link->min_rx;
if (euler.y > (float)link->max_ry)
euler.y = (float)link->max_ry;
if (euler.y < (float)link->min_ry)
euler.y = (float)link->min_ry;
if (euler.z > (float)link->max_rz)
euler.z = (float)link->max_rz;
if (euler.z < (float)link->min_rz)
euler.z = (float)link->min_rz;
// BACK TO QUATERNION
EulerToQuaternion(&euler, &link->quat);
}
But I’m getting no good results as when a limb reaches -180 degrees it goes back to 180 degs.
For you to see the effect, let me show you a video:
http://www.youtube.com/watch?v=XC2W4C-peD8
The tiny white dot on the left is the IK desired position, based on which the arm is rotated as to reach the point.
And this image shows the output which currently displays the angle of the main arm bone being rotated. As you can see as it reaches -180 on the z axis it goes back to +180 so DOF restricts return it to its original state at about -113 deg.
(DOF restrictions for that bone are set to -234 deg max, -111 deg min, so I don’t think they’re being a problem.)