[C++] Math: Quaternion to Direction Vector
This is Pseudo Code:
struct Quaternion
{
float x, y, z, w;
bool ToDirectionVector(_Out_ Vector3* dir, _Out_ Vector3* up, _Out_ Vector3* right)
{
if (Normalize() == FALSE)
return false;
if (dir == NULL || up == NULL || right == NULL)
return false;
float xx = x * x;
float xy = x * y;
float xz = x * z;
float xw = x * w;
float yy = y * y;
float yz = y * z;
float yw = y * w;
float zz = z * z;
float zw = z * w;
right->Set(1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw));
up->Set(2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw));
dir->Set(2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy));
return true;
}
}