Skip to main content
gamedev.net
🔒 Locked

Simple Rotation Problem

Started by jef3189 Aug 22, 2006 at 11:00 AM 0 replies 600+ views
Original Post
jef3189
jef3189
Just started with opengl in class. Was wondering why when I use the rotatef function, and then translate (for example in asteroids), instead of the rotation point changing WITH my object, it stays at the center of the screen. This means when I move the object anywhere from the center, instead of turning in place, it is swung around the center of the screen like a lasso. int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The Modelview Matrix glTranslatef(0.0f,0.0f, -6.0f); // Move Left And Into The Screen glRotatef(rtriz,0.0f,0.0f,200.0f); // Rotate The Cube On X, Y & Z glTranslatef(mtrix,mtriy, 0.0f); DrawTriangle(); return TRUE; // Keep Going } ....... while(!done) // Loop That Runs While done=FALSE { if(keys['D']) { rtriz-=5; ptrix = mtrix; ptriy = mtriy; ptriz = mtriz; } if(keys['A']) { rtriz+=5; ptrix = mtrix; ptriy = mtriy; ptriz = mtriz; } if(keys['W']) { mtriy-=.01; } if(keys['S']) { mtriy+=.01; }
ToohrVyk
ToohrVyk
Rotation always occurs around the origin. To rotate around a given point in space:
  1. Translate everything so that point becomes the origin.
  2. Apply the rotation.
  3. Apply the inverse of the translation in step 1
In your case, you could simply translate after you have rotated.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.