Jump to content




Recent Status Updates

  • Photo
      30 Sep
    rhossis

    laptop hard disk seated beneath motherboard but with no access panel. 7 hours to replace :(

    Show comments (3)
  • Photo
      19 Sep
    Chall

    I love it when you go to write a help thread, then while writing, you reach an enlightenment, and figure it out yourself.

    Show comments (3)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

Need help with rotating car opengl c++


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Tezelia

Tezelia

    CC Newcomer

  • New Member
  • PipPip
  • 15 posts

Posted 07 November 2012 - 05:00 PM

basically for my coursework i got to draw a car, boundary and obstacles and the car has to move so i i drew a car, got it moving but nowi want it to rotate every time i press up and when it ry it never works, i

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 my 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;
}

why isn't it working, sorry i'm new to this ):

Edited by BenW, 09 November 2012 - 11:42 AM.
Added code tags


#2 speculatius

speculatius

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 12 December 2012 - 05:28 AM

Hi,

it is some time since I have been using opengl, but I will try :)

1)

glRotate(angle, x, y, z)

...this will rotate space by given angle around vector (x, y, z).

2) glRotate is used the same way as glTranslate. You need to store your rotation in some variable and then call it just before you start drawing objects. Ordering of transformations (translate, rotate, scale...) matters.


void display(void) {
  glClear (GL_COLOR_BUFFER_BIT);
  glLoadIdentity(); // so it doesn't multiply
  glRotatef(carRotationY, 0.0f, 1.0f, 0.0f); // rotation around axis Y
  glTranslatef(carX, carY, carZ);
  // ...
}