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

后端 未结 3 1917
时光说笑
时光说笑 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();
    
    0 讨论(0)
  • 2021-01-21 04:18

    I think you first have to translate your camera to point (0,0,0) then rotate, then translate it back.

    0 讨论(0)
  • 2021-01-21 04:25

    Swap your rotate and translate calls around :)

    Since they post-multiply the matrix stack the last the be called is the 'first' to be applied conceptually, if you care about that sort of thing.

    0 讨论(0)
提交回复
热议问题