Original Post
Hello, Thanks for the help of several websites I'm near completion of my quaternion class. I have one function in there(GLvoid P3DXQUATERNION::CreateMatrix(P3DXMATRIX* p_mParam); ) that takes a matrix as a function argument and using the Q-to-M formula[as I call it] I convert the quaternion, which contains euler angles, into a 4x4 column major homogeneous matrix. Although I have the function completed I'm still left in the dark trying to figure out the actual process : Know of a website that demystifies this? Also how comes I have to declare three different quaternions just to represent my camera's orientation[along with a translation matrix] ? Before I introduced myself to quaternions I used four different matrices to make a camera. Three rotational matrices where each handles rotation around the x-, y-, and z-axises respectively. Declaring three quaternions, setting the euler angles, and converting each to a matrix is the same as my previous method. How do quaternions simplify creating a camera's orientation? [Edit:] Alright they're not euler angles, they're axis-angle values. But you get the point....I hope. [Edited by - Khaosifix on January 21, 2005 6:08:39 AM]
void P3DXQUATERNION::ConvertAxisAngle( SCALAR CONST& p_Degree, SCALAR CONST& p_X, SCALAR CONST& p_Y, SCALAR CONST& p_Z )
{
SCALAR fRadian = DEGTORAD( p_Degree ),
fSine = sinf( fRadian / 2.0f ) ;
// w = cos( theta / 2 )
// x = X * sin( theta / 2 )
// y = Y * sin( theta / 2 )
// z = Z * sin( theta / 2 )
w = cosf( fRadian / 2.0f ) ;
x = p_X * fSine ;
y = p_Y * fSine ;
z = p_Z * fSine ;
}
// ---------------------------------------------------------------------------------------------------
void P3DXQUATERNION::CreateMatrix( P3DXMATRIX* p_mParam )
{
p_mParam->m11 = 1.0f - 2.0f * ( y*y + z*z ) ;
p_mParam->m12 = 2.0f * ( x * y + z * w ) ;
p_mParam->m13 = 2.0f * ( x * z - y * w ) ;
p_mParam->m14 = 0.0f ;
p_mParam->m21 = 2.0f * ( x * y - z * w ) ;
p_mParam->m22 = 1.0f - 2.0f * ( x*x + z*z ) ;
p_mParam->m23 = 2.0f * ( z * y + x * w ) ;
p_mParam->m24 = 0.0f ;
p_mParam->m31 = 2.0f * ( x * z + y * w ) ;
p_mParam->m32 = 2.0f * ( y * z - x * w ) ;
p_mParam->m33 = 1.0f - 2.0f * ( x*x + y*y ) ;
p_mParam->m34 = 0.0f ;
p_mParam->m41 = 0.0f ;
p_mParam->m42 = 0.0f ;
p_mParam->m43 = 0.0f ;
p_mParam->m44 = 1.0f ;
}
// ---------------------------------------------------------------------------------------------------