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)
//THIS IS WHERE I WOULD TRY AND PUT THE ROTATION CODE PUT IT NEVER WORKS
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;
glutPostRedisplay();
}
/* 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”);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutSpecialFunc(SpecialKeys);
glutMainLoop();
return 0;
}
Read more: http://forum.codecall.net/topic/72795-need-help-with-rotating-car-opengl-c/#ixzz2BdenRrk6