首页 > 解决方案 > python gluLookAt 用于第一人称相机

问题描述

我是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 移动播放器和相机。

标签: pythonopengl3dglu

解决方案


与 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);

推荐阅读