rotation problem

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:

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_TEXTURE_2D);
glLoadIdentity();

glPushMatrix();

glTranslatef(trans_x, trans_y,trans_z);
glRotatef(angY, 0.0, 1.0, 0.0);
doSquare(); //the room

    glPopMatrix();
glutSwapBuffers();

glDisable(GL_TEXTURE_2D);
}

when i push the key for rotate,angY=angY+1 and then glutPostRedisplay();

any help?
Dominique

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 but it didn’t work
it’s visually the same.
Dominique

try this

lets say you want to be at x,y,z

(this is assuming that you are at the origin from the get go (e.g. loadIdentity())
then you just need to glRotate(ang,…
then
glTranslate(x,y,z)
draw

this should work…

however if you are not at the origin then you need to

translate to origin
rotate
translate to position
draw

also if you are loading ident you do not need to push/pop matrices

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

the code:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
glRotatef(angY, 0.0, 1.0, 0.0);
glTranslatef(trans_x, trans_y, trans_z);
doSquare();
glutSwapBuffers();
glDisable(GL_TEXTURE_2D);
}
Dominique

do you have an exe I can run (or the code) email it to me at jefferypeters1@home.com

I had the same problem to do that…

I think thi should work…

glLoadIdentity();

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 can e-mail them to me…

My e-mail is available from the head with a question mark next to “posted xx-xx-xx” above this post.

Regards.

Eric

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