Hi all
Yet another question from me and hope some one shoots the answer immediately.. very simple though
I have been tryin to do a rigid body simulation ... things work fine until i hit a nan ..
What I am trying to do is retrieve a angle from a quaternion for which i wrote this following function...
This is being refered in the code by this wayCode:
void get_AxisAngle_from_Quat(float &angle, Xlib::vec3d &axis)
{
float squareLength = get4d_X()*get4d_X() + get4d_Y()*get4d_Y() + get4d_Z()*get4d_Z();
if (squareLength>C_EPSILON)
{
angle = 2.0f * (float) acos(get4d_Z());
//assert (!XlibMath::is__nan(angle));
float inverseLength ;
inverseLength = 1.0f / (float) pow(squareLength, 0.5f) ;
axis.x = get4d_X() * inverseLength;
axis.y = get4d_Y() * inverseLength;
axis.z = get4d_Z() * inverseLength;
}
else
{
angle = 0.0f;
axis.x = 1.0f;
axis.y = 0.0f;
axis.z = 0.0f;
}
}
but This hits a nan and everytime it hits nan my object disappears from the screen.... (DevMsg is a overload for cout i use) When i try printing out the values at the point where i hit the nan this shows thisCode:Xlib::vec3d axis(1,0,0);
float angle=0.0f;
RBody[0].q.get_AxisAngle_from_Quat(angle,axis);
Xlib::DevMsg("Quat ",RBody[0].q);
Xlib::DevMsg("Angle ", angle);
I read online but it states nan is got by dividing by 0 .. but clearly i am not using any divisions at al...Code:DevMsg: Quat 1.442195 0.698514 1.700220 0.403262
Angle nan
can someone clarify me on where i went wrong ????
Cheers and regards