python第一人称照相机

2024-04-26 07:16:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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_位置是鼠标位置,但我无法计算最后一个值,所以我暂时将其设置为0

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


Tags: 游戏场景positioncurrentatopenglplayerlook
1条回答
网友
1楼 · 发布于 2024-04-26 07:16:59

工作原理与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);

相关问题 更多 >