PDA

View Full Version : rotation problem



MarsuGL
10-26-2000, 08:16 AM
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

DFrey
10-26-2000, 08:57 AM
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.

MarsuGL
10-27-2000, 12:06 PM
tanks but it didn't work
it's visually the same.
Dominique

10-27-2000, 12:38 PM
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

MarsuGL
10-27-2000, 12:51 PM
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

10-27-2000, 01:56 PM
do you have an exe I can run (or the code) email it to me at jefferypeters1@home.com

10-30-2000, 09:04 AM
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...

MarsuGL
11-13-2000, 01:34 AM
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

Eric
11-13-2000, 04:08 AM
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

monson
11-13-2000, 01:51 PM
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