I read the link and it was very useful but i am still having the same problem. the code i am using for my quats are
float QuatX = 0, QuatY = 0, QuatZ = 0, QuatW = 1;
void multQuat(float x, float y, float z, float w)
{
float W = QuatW * w - QuatX * x - QuatY * y - QuatZ * z;
float X = QuatX * w + QuatW * x + QuatZ * y - QuatY * z;
float Y = QuatY * w - QuatZ * x + QuatW * y + QuatX * z;
float Z = QuatZ * w + QuatY * x - QuatX * y + QuatW * z;
QuatW = W; QuatX = X; QuatY = Y; QuatZ = Z;
}
void normalizeQuat()
{
float len = QuatXQuatX + QuatYQuatY + QuatZQuatZ + QuatWQuatW;
if (len != 1.0) {
len = sqrt(len);
QuatX /= len;
QuatY /= len;
QuatZ /= len;
QuatW /= len;
}
}
void quatToMatrix(float mat[16])
{
float X = QuatX, Y = QuatY, Z = QuatZ, W = QuatW;
float xx, xy, xz, xw, yy, yz, yw, zz, zw;
xx = X * X;
xy = X * Y;
xz = X * Z;
xw = X * W;
yy = Y * Y;
yz = Y * Z;
yw = Y * W;
zz = Z * Z;
zw = Z * W;
mat[0] = 1 - 2 * ( yy + zz );
mat[1] = 2 * ( xy - zw );
mat[2] = 2 * ( xz + yw );
mat[4] = 2 * ( xy + zw );
mat[5] = 1 - 2 * ( xx + zz );
mat[6] = 2 * ( yz - xw );
mat[8] = 2 * ( xz - yw );
mat[9] = 2 * ( yz + xw );
mat[10] = 1 - 2 * ( xx + yy );
mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
mat[15] = 1;
}
In my update function i have something like
multQuat(sin(.05), 0, 0, cos(.5));
when i press up and each direction having its own thing.
in my display function i call the following before i draw my sphere where m is my 16 element matrix i am storing the rotation.
normalizeQuat();
quatToMatrix(m);
glMultMatrixf (m);
I am still not rotating right. It works if i move in the 8 directions from the origin. once i leave the origin and start to rotate into another direction i have a gimbal lock.
I am sorry for this long post but please can someone point me into the right direction?