OpenGL Rotations around World Origin when they should be around Local Origin

后端 未结 3 1923
时光说笑
时光说笑 2021-01-21 03:29

I\'m implementing a simple camera system in OpenGL. I set up gluPerspective under the projection matrix and then use gluLookAt on the ModelView matrix. After this I have my main

3条回答
  •  时光取名叫无心
    2021-01-21 04:04

    glRotate() rotates the ModelView Matrix around the World Origin, so to rotate around some arbitrary point, you need to translate your matrix to have that point at the origin, rotate and then translate back to where you started.

    I think what you need is this

    float x, y, z;//point you want to rotate around
    
    glTranslatef(0,0,view.forwardSpeed*deltaTime); //move forwards
    
    glTranslatef(x,y,z); //translate to origin
    glRotatef(view.angularSpeed*deltaTime,0,1,0); //rotate
    glTranslatef(-x,-y,-z); //translate back
    //draw our vertices
    draw();
    //swap buffers
    Swap_Buffers();
    

提交回复
热议问题