translation+rotation
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
I suggest that you dont use rotations or translations for the kind of thing you want to do. You should concentrate on using the gluLookAt function and altering the parameters given there. It gets complex when you make a 3d-world, and you make it come towards you everytime you press the up arrow rather than you going towards it.
I hope i understood the question right.
-- wAVaRiaN
I hope i understood the question right.
-- wAVaRiaN
Ya, I think you got the gist of it... Another thing to point out tho... You have a line of code there...
glRotatef(angY, 0.0, 1.0, 0.0);
Maybe I''m mistaken about your intent here, but I think you want to spin about the Y axis with the given angle angY... This should be actually written like this...
glRotatef(0.0, 1.0, 0.0, angY);
In your code you rotate 0.0 degrees (or radians, whatever) about the vector (angY, 0.0, 1.0).
glRotatef(x, y, z, angle);
This is the general use of the glRotate function. Just so you know.
S.
glRotatef(angY, 0.0, 1.0, 0.0);
Maybe I''m mistaken about your intent here, but I think you want to spin about the Y axis with the given angle angY... This should be actually written like this...
glRotatef(0.0, 1.0, 0.0, angY);
In your code you rotate 0.0 degrees (or radians, whatever) about the vector (angY, 0.0, 1.0).
glRotatef(x, y, z, angle);
This is the general use of the glRotate function. Just so you know.
S.
His glRotatef(angY, 0, 1, 0); is correct, I''ve mixed up parameter order before as well, and, after having the same problem I thought you may be right so I fired up the MSDN library to check it out, and his original order was correct. It''s great to see people trying to help each other here.
In reply to the original question, try rotating and THEN translating, that''s how I solved the problem.
hope I helped
In reply to the original question, try rotating and THEN translating, that''s how I solved the problem.
hope I helped
[email=JValentine_13@hotmail.com]contact[/email]
Wow, what was _I_ on? ... Ugh, ya, that''s right, man, I should learn what I''m talking about one of these days.
S.
S.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement