Need help with rotating a car

I’m new to opengl and studying it for one of my modules and for one of our assignments we have to make a car move through a maze and reach the top

The thing is my car starts facing a horizontal position but when i click up I try to rotate the car so it faces the right direction or up but even when I put the glRotate(0,0,0,0) code it doesn’t work… Instead it moves up and when I press right it goes diagonal between up and right and it doesn’t go down

I used the glRotate(90,0,0,0) code but all it never rotated the car up

what do the four 0s stand for, one degree and x y z???

here is half of my code

I made a function for my car drawcar… do I have to put the rotate code in display or in my movement special keys code?

void SpecialKeys(int key, int x, int y) // a function for the movement key - car moves

if(key == GLUT_KEY_UP)


drawCary = drawCary + carSpeed;

if(key == GLUT_KEY_DOWN)
drawCary = drawCary - carSpeed;

if(key == GLUT_KEY_LEFT)
drawCarx = drawCarx - carSpeed;

if(key == GLUT_KEY_RIGHT)
drawCarx = drawCarx + carSpeed;



/* display callback function
called whenever contents of window need to be re-displayed */
//this is the all important drawing method - all drawing code goes in here
void display(void)

glClear (GL_COLOR_BUFFER_BIT); /* clear window */

glLoadIdentity(); // so it doesn’t multiply
glTranslatef(drawCarx-15,drawCary-15,0); //

drawCar(6,0,0); //displays the car function

glFlush(); /* execute drawing commands in buffer */

glLoadIdentity(); // so it doesn’t multiply

drawBorder(6,0,0); //displays the car function

glFlush(); /* execute drawing commands in buffer */


/* graphics initialisation /
void init(void)
glClearColor (0.0, 0.0, 0.0, 0.0); /
window will be cleared to black */

//rename this to main(…) and change example 2 to run this main function
int main(int argc, char** argv)
/* window management code … /
initialises GLUT and processes any command line arguments */

glutInit(&argc, argv);
/* use single-buffered window and RGBA colour model /
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
window width = 400 pixels, height = 400 pixels /
glutInitWindowSize (600, 600);
window upper left corner at (100, 100) /
glutInitWindowPosition (100, 100);
creates an OpenGL window with command argument in its title bar */
glutCreateWindow (“Example 1”);




return 0;

Read more:

glRotate requires one of the axis x,y,z to be set eg glRotate(90,0,1,0) rotate 90 degrees around the y axis.

These questions are better posted in the “beginners” forum because they can be answered by anyone using OpenGL not just MS Windows users

thank you it works now but when it rotates i kind of moves a bit but it’s better than nothing I guess

[QUOTE=Tezelia;1244428]thank you it works now but when it rotates i kind of moves a bit but it’s better than nothing I guess[/QUOTE] This is probably because you aren’t rotating around the geometric center of the car, which is probably because the car is not modeled around its geometric center. Put a glTranslate command in your draw_car routine somewhere between the Rotate command and the commands which draw the car. Try different values for X and Y until the car rotates around the point you want it to.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.