Game Development Reference
In-Depth Information
r32 = 2 * (q.v.y*q.v.z + q.n*q.v.x);
r33 = q00 - q11 - q22 + q33;
tmp = fabs(r31);
if(tmp > 0.999999)
{
r12 = 2 * (q.v.x*q.v.y - q.n*q.v.z);
r13 = 2 * (q.v.x*q.v.z + q.n*q.v.y);
u.x = RadiansToDegrees(0.0f); //roll
u.y = RadiansToDegrees((float) (-(pi/2) * r31/tmp)); // pitch
u.z = RadiansToDegrees((float) atan2(-r12, -r31*r13)); // yaw
return u;
}
u.x = RadiansToDegrees((float) atan2(r32, r33)); // roll
u.y = RadiansToDegrees((float) asin(-r31)); // pitch
u.z = RadiansToDegrees((float) atan2(r21, r11)); // yaw
return u;
}
Conversion Functions
These two functions are used to convert angles from degrees to radians and radians to
degrees. They are not specific to quaternions but are used in some of the code samples
shown earlier:
inline float DegreesToRadians(float deg)
{
return deg * pi / 180.0f;
}
inline float RadiansToDegrees(float rad)
{
return rad * 180.0f / pi;
}
Search Nedrilad ::




Custom Search