Original Post
I've been delving into quaternions for a while with animation and I found a tutorial to help me out, everything works fine with bone animation and whatnot but I still didn't understand them fully. Now I want to use quaternions for all my orientation for all entities which means I need to understand them more. I tried to put in a certain value into my quaternion and render it at that orientation but it's not coming out right. I'm trying to render a simple quad with orientation Quat(0.0, 0.0, 1.0f, PI/4) and it's definitely not looking correctly, should look like a diamond and barely turned maybe PI/12 or something much smaller
// in Main
// ....
camera.SetOrientation(sWQuaternion(0.0f, 0.0f, 1.0f, W_PI_4));
// ...
window.RunMainLoop();
// in main render loop
// ...
// update camera in camera::update()
{
m_matView.SetRotationQuaternion(m_orientation);
m_matView.SetTranslation(-m_position);
}
// ...
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cam->GetViewMatrix().mat);
// render objects
// in Matrix4x4::SetRotationQuaternion(Quaternion quat)
{
float x2, y2, z2, w2, xy, xz, yz, wx, wy, wz;
LoadIdentity();
x2 = quat.X * quat.X;
y2 = quat.Y * quat.Y;
z2 = quat.Z * quat.Z;
w2 = quat.W * quat.W;
xy = quat.X * quat.Y;
xz = quat.X * quat.Z;
yz = quat.Y * quat.Z;
wx = quat.X * quat.W;
wy = quat.Y * quat.W;
wz = quat.Z * quat.W;
mat[0] = 1.0f - 2.0f * ( y2 + z2 );
mat[1] = 2.0f * ( xy + wz );
mat[2] = 2.0f * ( xz - wy );
mat[3] = 0.0f;
mat[4] = 2.0f * ( xy - wz );
mat[5] = 1.0f - 2.0f * ( x2 + z2 );
mat[6] = 2.0f * ( yz + wx );
mat[7] = 0.0f;
mat[8] = 2.0f * ( xz + wy );
mat[9] = 2.0f * ( yz - wx );
mat[10] = 1.0f - 2.0f * ( x2 + y2 );
mat[11] = 0.0f;
}
// in Matrix4x4::SetTranslation(Vector3 vec)
{
mat[12] = vec.X;
mat[13] = vec.Y;
mat[14] = vec.Z;
mat[15] = 1.0f;
}