Rotating an object around a fixed point in opengl

后端 未结 4 365
我在风中等你
我在风中等你 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 01:59

    try rotating after translation:

        glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix(); // put current matrix on stack
    
    //glTranslatef(0.0f, 0.0f, 0.0f);   
    //glTranslatef(-4*1.5, 0.0, 4*1.5);
    
    glTranslatef(xpos, ypos, zpos);
    glRotatef(rotationAngle, 0.0f, 1.0f, 0.0f); // rotate the robot on its y-axis
    DrawRobot(xpos, ypos, zpos); // draw the robot
    glPopMatrix();
    

提交回复
热议问题