PDA

View Full Version : My rotations is not correct.



dew
05-13-2001, 10:22 AM
Hi.
I have tried to do some scene lately where I want to rotate my object around it self and after that translate it to an arbitrary point in space. After that I want to use gluLookAt... But when I do this I get my object to rotate around itself but then after the gluLookAt it continue to rotate but now in reference to its new point in space. How do I solve this?
Here is my code:

glLoadIdentity();
gluLookAt(-wld->cam->posx,-wld->cam->posy,-wld->cam->posz,wld->cam->lx,wld->cam->ly,wld->cam->lz,0,1,0);

glRotatef(obj->xv, 1.0f, 0.0f, 0.0f);
glRotatef(obj->zv, 0.0f, 1.0f, 0.0f);
glRotatef(obj->yv, 0.0f, 0.0f, 1.0f);
glTranslatef(float(obj->xp),float(obj->yp),float(obj->zp));

I have tried to put the gluLookAt after the rotations and the translations but then it disappears from the screen.
What am I doing wrong?

/Dew

ipo
05-13-2001, 10:45 AM
If i understand correctly in order to make the object rotate about itself at an arbitrary point in space you should do this

glLoadIdentity()
glGluLookAt(...);
glTranslatef(...);
glRotatef(xAngle, 1.0, 0.0, 0.0);
glRotatef(yAngle, 0.0, 1.0, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);
draw(...);

BTW, check your second rotate as it uses the z-angle to rotate about the y-axis.

ffish
05-13-2001, 04:00 PM
One other thing to be aware of: if you perform your rotations around the x, y and z axes in order like that, you could come across everyone's favourite topic "gimbal lock". I won't go into it here - it's been covered many times already. Do a search of the discussion boards for "gimbal lock" and "quaternions" and you'll find heaps of links.

Cheers.