gpt4 book ai didi

c++ - openGL,C++,如何移动导入的 OBJ 对象?

转载 作者:行者123 更新时间:2023-11-28 01:48:18 25 4
gpt4 key购买 nike

我目前正在使用这个:http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/

到目前为止,我所做的只是替换模型,更改相机使其等距,并再次显示光标。所以没什么大不了的。

我的新模型及其纹理完美呈现。我想知道如何通过按 W、A、S 和 D 来移动我的模型?

我打算制作一个非常简单的“游戏”,我只需四处移动我的模型,然后与散布在 map 上的其他对象发生碰撞。

感谢任何帮助!谢谢大家!

// 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();

最佳答案

MVP 矩阵对模型的平移、旋转和缩放进行编码。它是Projection * View * Modelmatrix的乘积。如果您应用模型矩阵的平移并重新计算 mvp,那么您应该会看到对象在移动。

关于c++ - openGL,C++,如何移动导入的 OBJ 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43994880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com