python - 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 移动播放器和相机。
解决方案
与 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);
推荐阅读
- ffmpeg - 为什么带有 libfdk_aac 编码的 ffmpeg 会在音频文件的开头减少 25 毫秒?
- java - Android 是否支持第三方库的设备相关实现?
- excel - 是否有一个函数可以让我根据另一个单元格中的值范围用文本填充单元格
- python - 如何复制数组元素
- c# - 在 c# 中使用 office interop 时得到的格式代码 (\r\a) 是什么?
- java - 从 Vaadin 事件监听器更新组件
- java - 如何点击按钮
- python - 我无法通过 USB 从 arduino 获取数据到树莓派
- html - 我有一个引导导航栏,它不会与按钮和搜索框保持一致 - 我如何使其保持一致?
- javascript - PM2 - 如何从日志文件名中删除标识符