kazmalak

02-08-2005, 06:23 AM

I am still trying to rotate my draw using quaternions and still could't succeed.

I have two rotations in Euler represantation

glRotatef(angx,1,0,0);

glRotatef(angy,0,1,0);

I create my local rotation quaternion by first converting those eulers to quaternion and then multiplying them. And it doesn't work. Still I have gimbal lock problem. Here is the code. Can anyone show where I am doing wrong?

quaternion quarti1;

quaternion quarti2;

quaternion local;

quaternion total;

quarti1.quax=sin(rti1*M_PI/360);

quarti1.quay=0;

quarti1.quaz=0;

quarti1.quaw=cos(rti1*M_PI/360);

quarti2.quax=0;

quarti2.quay=sin(rti2*M_PI/360);

quarti2.quaz=0;

quarti2.quaw=cos(rti2*M_PI/360);

local=mult(normalize(quarti2),normalize(quarti1));

total.quax=0;

total.quay=0;

total.quaz=0;

total.quaw=1;

total=mult(total,local);

GLfloat Matrix[16];

Matrix[0]=1-2*total.quay*total.quay-2*total.quaz*total.quaz;

Matrix[1]=2*total.quax*total.quay+2*total.quaw*total.quaz;

Matrix[2]=2*total.quax*total.quaz-2*total.quaw*total.quay;

Matrix[3]=0;

Matrix[4]=2*total.quax*total.quay-2*total.quaw*total.quaz;

Matrix[5]=1-2*total.quax*total.quax-2*total.quaz*total.quaz;

Matrix[6]=2*total.quay*total.quaz+2*total.quaw*total.quax;

Matrix[7]=0;

Matrix[8]=2*total.quax*total.quaz+2*total.quaw*total.quay;

Matrix[9]=2*total.quay*total.quaz-2*total.quaw*total.quax;

Matrix[10]=1-2*total.quax*total.quax-2*total.quay*total.quay;

Matrix[11]=0;

Matrix[12]=0;

Matrix[13]=0;

Matrix[14]=0;

Matrix[15]=1;

glMultMatrixf(Matrix);

I have two rotations in Euler represantation

glRotatef(angx,1,0,0);

glRotatef(angy,0,1,0);

I create my local rotation quaternion by first converting those eulers to quaternion and then multiplying them. And it doesn't work. Still I have gimbal lock problem. Here is the code. Can anyone show where I am doing wrong?

quaternion quarti1;

quaternion quarti2;

quaternion local;

quaternion total;

quarti1.quax=sin(rti1*M_PI/360);

quarti1.quay=0;

quarti1.quaz=0;

quarti1.quaw=cos(rti1*M_PI/360);

quarti2.quax=0;

quarti2.quay=sin(rti2*M_PI/360);

quarti2.quaz=0;

quarti2.quaw=cos(rti2*M_PI/360);

local=mult(normalize(quarti2),normalize(quarti1));

total.quax=0;

total.quay=0;

total.quaz=0;

total.quaw=1;

total=mult(total,local);

GLfloat Matrix[16];

Matrix[0]=1-2*total.quay*total.quay-2*total.quaz*total.quaz;

Matrix[1]=2*total.quax*total.quay+2*total.quaw*total.quaz;

Matrix[2]=2*total.quax*total.quaz-2*total.quaw*total.quay;

Matrix[3]=0;

Matrix[4]=2*total.quax*total.quay-2*total.quaw*total.quaz;

Matrix[5]=1-2*total.quax*total.quax-2*total.quaz*total.quaz;

Matrix[6]=2*total.quay*total.quaz+2*total.quaw*total.quax;

Matrix[7]=0;

Matrix[8]=2*total.quax*total.quaz+2*total.quaw*total.quay;

Matrix[9]=2*total.quay*total.quaz-2*total.quaw*total.quax;

Matrix[10]=1-2*total.quax*total.quax-2*total.quay*total.quay;

Matrix[11]=0;

Matrix[12]=0;

Matrix[13]=0;

Matrix[14]=0;

Matrix[15]=1;

glMultMatrixf(Matrix);