【问题标题】:python gluLookAt for first person camerapython gluLookAt 用于第一人称相机
【发布时间】:2020-08-06 03:48:02
【问题描述】:

我是 openGL 的新手,我正在尝试将相机移动为第一人称射击游戏。我想使用 gluLookAt 进行移动和环视场景,但我无法弄清楚相机部分

gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
glu.gluLookAt(current_player.position[0], current_player.position[1] ,
              current_player.position[2], look_at_position[0], look_at_position[1], 0,
              0, 1 ,0)

look_at_position 是鼠标位置,但我无法计算最后一个值,所以我暂时设为 0

我只想知道如何使用 glLookAt 移动播放器和相机。

【问题讨论】:

    标签: python opengl 3d glu


    【解决方案1】:

    与 glm::lookAt() 工作方式相同。第一个参数是您正在查看的位置(您是正确的),然后是您正在查看的位置,然后是向上向量(也是正确的)。这是我调用的:

    //this code is in the mouse callback, both yaw and pitch are mouse inputs
    glm::vec3 front;
    glm::vec3 right;
    front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
    front.y = sin(glm::radians(pitch));
    front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
    cameraFront = glm::normalize(front);
    front.x = cos(glm::radians(yaw));
    front.z = sin(glm::radians(yaw));
    movementFront = glm::normalize(front);
    
    //this is in int main()
    view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      相关资源
      最近更新 更多