Game Development Reference
In-Depth Information
and let q be a quaternion:
q = [n, x i + y j + z k ]
Then each element in R is calculated from q as follows:
r 11 = n 2 + x 2 − y 2 − z 2
r 21 = 2xy+2zn
r 31 = 2zx − 2yn
r 12 = 2xy − 2zn
r 22 = n 2 − x 2 + y 2 − z 2
r 32 = 2zy + 2xn
r 13 = 2xz + 2yn
r 23 = 2yz − 2xn
r 33 = n 2 − x 2 − y 2 + z 2
To extract the Euler angles, yaw (ψ), pitch (τ), and roll (φ), from R , you can use these
relations:
sin τ = −r 31
tan φ = r 32 / r 33
tan ψ = r 21 / r 11
Here's the code that extracts the three Euler angles, returned in the form of a Vector ,
from a given quaternion:
inline Vector MakeEulerAnglesFromQ(Quaternion q)
{
double r11, r21, r31, r32, r33, r12, r13;
double q00, q11, q22, q33;
double tmp;
Vector u;
q00 = q.n * q.n;
q11 = q.v.x * q.v.x;
q22 = q.v.y * q.v.y;
q33 = q.v.z * q.v.z;
r11 = q00 + q11 - q22 - q33;
r21 = 2 * (q.v.x*q.v.y + q.n*q.v.z);
r31 = 2 * (q.v.x*q.v.z - q.n*q.v.y);
Search Nedrilad ::




Custom Search