How to rotate a non-camera model in OpenGL?

I have the same thing as in the title: / I am doing something like:

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0.0f, 0, -zoom);
  glRotatef(yr*20+moveYr*20, 0.0f, 1.0f, 0.0f);
  glRotatef(zr*20+moveZr*20, 1.0f, 0.0f, 0.0f);

  //Here model render :/

And in my application, the camera does not rotate the model: /

+5
source share
3 answers

Presumably, for what reason do you think your camera is moving, not your model, because all the objects in the scene are moving together?

After rendering your model and before rendering other objects, will you reset the MODELVIEW matrix? In other words, do you execute other glLoadIdentity () or glPopMatrix () after you say the model you are talking about and before rendering other objects?

, , , , , , ( ).

, :

  glTranslatef(0.0f, 0, -zoom);
  glRotatef(yr*20+moveYr*20, 0.0f, 1.0f, 0.0f);
  glRotatef(zr*20+moveZr*20, 1.0f, 0.0f, 0.0f);
  //Here model render :/

(0, 0, -zoom)?

, (x, y, z), :

  • (x, y, z) (0,0,0), (-x, -y, -z)
  • (x, y, z), (x, y, z)
  • Draw

(0,0, ), 3. , :

glTranslatef(0.0f, 0, zoom); // translate back from origin

, (0,0,0), z, , , @nonVirtual .

reset MODELVIEW, . , :

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

#if you want to rotate around (0, 0, -zoom):
  glTranslatef(0.0f, 0, -zoom);
  glRotatef(yr*20+moveYr*20, 0.0f, 1.0f, 0.0f);
  glRotatef(zr*20+moveZr*20, 1.0f, 0.0f, 0.0f);
  glTranslatef(0.0f, 0, zoom); // translate back from origin
#else if you want to rotate around (0, 0, 0):
  glRotatef(yr*20+moveYr*20, 0.0f, 1.0f, 0.0f);
  glRotatef(zr*20+moveZr*20, 1.0f, 0.0f, 0.0f);
  glTranslatef(0.0f, 0, -zoom);
#endif    
  //Here model render :/

  glLoadIdentity();
  // translate/rotate for other objects if necessary
  // draw other objects
+5

GL_PROJECTION GL_MODELVIEW, .

0

, , . glRotate glTranslate. , , , . , , , . , .

0

All Articles