我目前正在使用此:http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/
到目前为止,我所做的就是更换模型,更换相机以使其等距,并使光标再次显示。没什么大不了的。
我的新模型与其纹理完美搭配。我想知道如何通过按W,A,S和& D,我可以移动我的模型吗?
我打算制作一款非常简单的游戏"我只是移动我的模型,并与散落在地图周围的其他物体碰撞。
任何帮助表示赞赏!谢谢大家!
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Use our shader
glUseProgram(programID);
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
// Bind our texture in Texture Unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Texture);
// Set our "myTextureSampler" sampler to user Texture Unit 0
glUniform1i(TextureID, 0);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer : UVs
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glVertexAttribPointer(
1, // attribute
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, vertices.size() );
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
答案 0 :(得分:1)
MVP matricies编码模型的平移,旋转和缩放。它是Projection * View * Modelmatrix的产品。如果您应用了Modelmatrix的翻译并重新计算mvp,那么您应该看到对象正在移动。