Rotation Matrices, very weird

Hi

i called glRotatef(90,0,0,1) then glGetFloatv(GL_MODELVIEW_MATRIX, mv); mv[0] and mv[5] is where cos(90) and should equal 0. but they equal 1.2, why is this? the places in the matrix defined by sin(90) are correct i.e 1. why are the cos(90) incorrect and the sin(90) correct.

then i called glRotatef(180,0,0,1) this time the places defined by cos(180) where correct and the places defined by sin(180) were incorrect(2.4) when sin(90) = 0.

i dont get whats going on. i set up a simple example.

glRotatef(90,0,0,1)
glGetFloatv(GL_MODELVIEW_MATRIX, mv);

CVector3 p2(0,0,0);//the new point

lpos.x = lpos.z = 0;
lpos.y = 5; //the original point

//get the matrix
CVector3 xtrans(mv[0],mv[4],mv[8]);
CVector3 ytrans(mv[1],mv[5],mv[9]);
CVector3 ztrans(mv[2],mv[6],mv[10]);

//transform the point
p2.x = (lpos * xtrans) + (mv[12]);
p2.y = (lpos * ytrans) + (mv[13]);
p2.z = (lpos * ztrans) + (mv[14]);

should put p2 at -5,0,0; and it did when i wrote out the matrices on paper, but in the app i got p2 = -5,6.08,0; and it all comes down to the cos(90) = 1.2 again

im really confused here could someone please help me out,

EDIT: thought id post the z rotation matrix to stop people from haing to look it up

cos(a) -sin(a) 0 0
sin(a) cos(a) 0 0
0 0 1 0
0 0 0 1

x = xCos(a) - ySin(a)
y = xSin(a) + yCos(a)

thanks for your time.

[This message has been edited by break_stuff247 (edited 11-29-2002).]

My guess is that the modelview matrix was not the identity matrix before you called glRotatef.

Originally posted by Coriolis:
My guess is that the modelview matrix was not the identity matrix before you called glRotatef.

it was, its the only thing the program does

glLoadIdentity();
glRotatef(90,0,0,1)
glGetFloatv(GL_MODELVIEW_MATRIX, mv);

CVector3 p2(0,0,0);//the new point

lpos.x = lpos.z = 0;
lpos.y = 5; //the original point

//get the matrix
CVector3 xtrans(mv[0],mv[4],mv[8]);
CVector3 ytrans(mv[1],mv[5],mv[9]);
CVector3 ztrans(mv[2],mv[6],mv[10]);

//transform the point
p2.x = (lpos * xtrans) + (mv[12]);
p2.y = (lpos * ytrans) + (mv[13]);
p2.z = (lpos * ztrans) + (mv[14]);

Is the modelview matrix the current matrix when you call glRotate?

Originally posted by bakery2k:
Is the modelview matrix the current matrix when you call glRotate?

yes it is.

would anyone else be willing to try it? i had someone check on there machine and they got the same answer as me, but if you want to see do:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(90,0,0,1);
glGetFloatv(GL_MODELVIEW_MATRIX, mv);

and post what mv[0] and mv[5] are. (it should be 0)

id appreciate if anyone could give this a try.

thanks

I get 1.2 * 10^-8… which is approximately 0.

Originally posted by Coriolis:
I get 1.2 * 10^-8… which is approximately 0.

sorry math isnt my strong point was the actual value stored at mv[0] and mv[5] zero ?
i.e. mv[0] = 0; mv[5] = 0;

Edit: i know that im missing something here. im not saying theres a bug in ogl i sure theres a reason why 1.2 is put there but i just dont know what that reason is. my calculator gives the result as cos(90) = 0,
im just confused as to how ogl derived that value.

[This message has been edited by break_stuff247 (edited 11-29-2002).]

Originally posted by break_stuff247:
sorry math isnt my strong point was the actual value stored at mv[0] and mv[5] zero ?
i.e. mv[0] = 0; mv[5] = 0;

Not exactly 0, but very very close to 0. The “e-08” at the end of the number means it is in scientific notation. You have to multiply by 10 ^ -8, which is the same as dividing by 10 ^ 8, or dividing by 100 million.

Computers don’t work in degrees, they work in radians. To take the cosine of 90 degrees they have to convert it into PI/2 radians, which is a transcendental number (ie, it cannot be stored exactly in a finite number of digits any number base). So, the computer approximates PI/2, causing the sine and cosine to be off in the 8th decimal place.

Originally posted by Coriolis:
[b] Not exactly 0, but very very close to 0. The “e-08” at the end of the number means it is in scientific notation. You have to multiply by 10 ^ -8, which is the same as dividing by 10 ^ 8, or dividing by 100 million.

Computers don’t work in degrees, they work in radians. To take the cosine of 90 degrees they have to convert it into PI/2 radians, which is a transcendental number (ie, it cannot be stored exactly in a finite number of digits any number base). So, the computer approximates PI/2, causing the sine and cosine to be off in the 8th decimal place.[/b]

Seems i was misinterpreting the results, tbhanks very much Coriolis for the explanation