PDA

View Full Version : rotating in 3D



02-16-2002, 01:35 AM
I am trying to rotate my model in 3D using a series of

glrotatef xangle,1,0,0
glrotatef yangle,0,1,0
glrotatef zangle,0,0,1

The rotation about z is always correct presumably because it is the last command.

Say for example I change the values of xangle and yangle. Then when I change the value of xangle afterwards, the model does not rotate around my global x-axis. How do get round this problem

satan
02-16-2002, 04:48 AM
the last rotation works because it is done first
all rotations thereafter (in the code they are before) are done using your new rotated matrix
to avoid this use glpushmatrix and glpopmatrix to save and restore your matrix

glpushmatrix (save matrix)
glrotate (do rotation)
glpopmatrix (restore matrix)
.
.
.

hope this helps

Dies_Irae
02-17-2002, 08:53 AM
Hey,

Cant you just use one glrotate?

like:

glRotatef(maxspeed, xrot, yrot, zrot);

maxspeed could be increased with a constant number, and you only change the x-z values from 0 to 1?

satan
02-17-2002, 10:19 AM
Originally posted by Dies_Irae:
Hey,

Cant you just use one glrotate?

like:

glRotatef(maxspeed, xrot, yrot, zrot);

maxspeed could be increased with a constant number, and you only change the x-z values from 0 to 1?



could you explain this to me, please
do you want to load the identity matrix every time ?
than i think it will not work, because you always rotate from you starting position just around different axis
and if you don't load the identity matrix your rotations will work on the rotated system and you have the same problems as above
or am i just to stupid to get it

to dave:

forget my first post it would not solve your problem
the only thing i can imagine at the moment is calculating your own transformation matrix

[This message has been edited by satan (edited 02-17-2002).]