Hi all,
Using the view matrix, computed like that :
const CMatrix4 ViewMatrix = m_WorldMatrix.Inverse();
You can get the local-axis :
// Forward vector.
m_ForwardVector.x = ViewMatrix( 2, 0 );
m_ForwardVector.y = ViewMatrix( 2, 1 );
m_ForwardVector.z = ViewMatrix( 2, 2 );
m_ForwardVector.Normalize();
// Right vector.
m_RightVector.x = ViewMatrix( 0, 0 );
m_RightVector.y = ViewMatrix( 0, 1 );
m_RightVector.z = ViewMatrix( 0, 2 );
m_RightVector.Normalize();
// Up vector.
m_UpVector.x = ViewMatrix( 1, 0 );
m_UpVector.y = ViewMatrix( 1, 1 );
m_UpVector.z = ViewMatrix( 1, 2 );
m_UpVector.Normalize();
Using quaternion you can get the local-axis like that :
CVector3 CQuaternion::GetForwardVector() const
{
const float x2 = 2.0f * x;
const float y2 = 2.0f * y;
const float z2 = 2.0f * z;
const float x2w = x2 * w;
const float y2w = y2 * w;
const float x2x = x2 * x;
const float z2x = z2 * x;
const float y2y = y2 * y;
const float z2y = z2 * y;
return CVector3( z2x + y2w, z2y - x2w, 1.0f - ( x2x + y2y ) );
}
CVector3 CQuaternion::GetRightVector() const
{
const float y2 = 2.0f * y;
const float z2 = 2.0f * z;
const float y2w = y2 * w;
const float z2w = z2 * w;
const float y2x = y2 * x;
const float z2x = z2 * x;
const float y2y = y2 * y;
const float z2z = z2 * z;
return CVector3( 1.0f - ( y2y + z2z ), y2x + z2w, z2x - y2w );
}
CVector3 CQuaternion::GetUpVector() const
{
const float x2 = 2.0f * x;
const float y2 = 2.0f * y;
const float z2 = 2.0f * z;
const float x2w = x2 * w;
const float z2w = z2 * w;
const float x2x = x2 * x;
const float y2x = y2 * x;
const float z2y = z2 * y;
const float z2z = z2 * z;
return CVector3( y2x - z2w, 1.0f - ( x2x + z2z ), z2y + x2w );
}
When I compare the value from the quaternion and from the view matrix, I don't get the same values.
Compute euler from a matrix or a quaternion is not possible, is it the same for local-axis from a quaternion ?
Thanks