Rotating an object around a fixed point in opengl

后端 未结 4 364
我在风中等你
我在风中等你 2020-12-16 01:19

I have a problem with this openGL code:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix(); // put current matrix on stack

//glTranslatef(0.0f, 0.         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 02:06

    Use this

    house();
    
    glTranslatef(x, y, 0.0); // 3. Translate back to original
    glRotatef(theta, 0.0, 0.0, 1.0); // 2. Rotate the object around angle
    glTranslatef(-m, -n, 0.0); // 1. Move to origin
    
    house();
    

    where m and n are the point on the object around which you want to rotate and x and y are the points around which you want to rotate.

提交回复
热议问题