在屏幕上转换对象可编程管道
Translating an object across the screen programmable-pipeline
我很难弄清楚如何在给定箭头键输入的情况下在屏幕上翻译对象。目前,我移动相机没有问题,但我似乎无法让物体而不是相机移动。
这是我正在做的计算视图矩阵的工作
ViewMatrix = glm::lookAt(
position, //camera position
position+direction, //look at origin
up //head up
);
位置和方向glm::vec3
因此,要更改对象的位置,我会修改模型矩阵吗?还是会用mvp
做一些事情?
模型矩阵目前仍为glm::mat4(1.0)
computeMatricesFromInputs(window,time); //function that handles input and computes viewMatrix
glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
glm::mat4 viewMatrix = getViewMatrix();
glm::mat4 modelMatrix = glm::mat4(1.0);
glm::mat4 MVP = projectionMatrix * viewMatrix * modelMatrix;
所以我最终在 @j-p 的帮助下解决了这个问题。我想做的是移动对象,所以我将 glm 函数translate()
应用于模型矩阵。为此,我转到了我的控件文件并创建了一个名为
glm::mat4 getModelMatrix();
它返回了我也在头文件中声明的变量glm::mat4 ModelMatrix
。代码和移动对象的实际部分如下所示:
//If the the corresponding key is pressed...
ModelMatrix = glm::translate(ModelMatrix, glm::vec3(0.0f, 1.0f, 0.0f); //move y 1.0f
//else If..etc..
然后回到我的主循环,最终代码将如下所示:
computeMatricesFromInputs(window,time); //function that handles input and computes viewMatrix
glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
glm::mat4 viewMatrix = getViewMatrix();
glm::mat4 modelMatrix = getModelMatrix();
glm::mat4 MVP = projectionMatrix * viewMatrix * modelMatrix;
相关文章:
- 可视化配置 VS 代码以进行 C++ 编程和开发
- 以编程方式防止重命名或删除文件,但仍使其可写
- 使自定义范围 v3 视图可管道化
- Linux C++编程:为什么连接是.so,生成的可执行依赖库是.so.version
- 用于Windows编程的可视化C++库
- 可编程访问正确的虚拟班级儿童
- 可视化 在C++编程中编写一个函数星号
- 是否有任何函数可用于在 c++ 编程中传输流程,以替代 while 或 do while 循环
- 具有读写功能的 UNIX 管道系统可执行"ls -la"命令
- 在编程中某些东西是可传递的是什么意思
- 手动编程Borland图形界面上的可点击按钮
- 在具有可替换阶段的C++中建模管道
- 在OpenGL中混合固定功能管道和可编程管道
- 可视C++编程错误:C4703、C4700
- OpenGL可编程管道运行速度较慢
- C/ c++ -可编程运行Makefile
- BB10核心原生SDK:可编程调整屏幕亮度
- 是否有一种可编程的方法来估计CPU执行fp操作所需的时间
- 可编程创建的tinyxml xml文件在Internet Explorer中无法加载
- 在屏幕上转换对象可编程管道