Hello, here’s what i’m trying to do :
I make a rectangle in 3d (like a long room)
i enter in the room, if i push the up key using glTranslate()
i go back if i push the down key
now i want to rotate when i’m in the room
i have tried with glRotate()
but the problem is that i rotate from the origin (0,0,0) and the center of the room is not at 0,0,0 but something like 0,0,25
how to do? i post a piece of code below:
Ok, I see a couple things, first, do the rotation before the translation. Second, is it really necessary to push the modelview matrix after loading it with the identity matrix? I think you meant to do the push before loading the identity.
Tanks for the reply, but it still doesn’t work and i don’t understand why, or maybe it works but doesn’t do what i want it to do(rotate from inside the room to see the how it is around).it still seems to rotate from the origin
glRotatef(angY, 0.0, 0.0, 1.0); /* This is your heading…
glTranslatef(-trans_x, -trans_y,-trans_z); /* you need to put your location with “-” sign
glRotatef(90, 1.0, 0.0, 0.0); /* You need this if you want axis z positive pointing the sky.
glPushMatrix();
doSquare(); //the room
glPopMatrix();
glutSwapBuffers();
I’ll check the code I really have and I let you know…
Despite the help from everyone i havn’t solved my problem yet, could someone take a look at my c files ? i can send the project by mail, please reply your email if you agree
tanks
dominique
you said that the center of the room is 0,0,25 right? then to rotate the room while you’re in the center you do this:
glLoadIndentity(); //reset the view
// first translate to the center of the room
glTranslatef(0.0f,0.0f,25.f); // or -25 which ever, depending where the room is
glRotatef(Angy,0.0f,1.0f,0.0f);
or make sure your trans_x=trans_y=0.0f; and trans_z=25.f