我无法理解如何实际翻译 vbo 中包含的单个对象。所以首先我设置 vao 和 vbo 并绑定并输入立方体的顶点......
glGenVertexArrays(1, &_vertexArray1); //Bind to first VAO
glBindVertexArray(_vertexArray1);
glGenBuffers(1, &_vertexBufferCube1);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferCube1);
glBufferData(GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vp[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(loc1);
glVertexAttribPointer(loc1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(loc2);
glVertexAttribPointer(loc2, 3, GL_FLOAT, GL_FALSE, 0, NULL);`
然后在我的显示功能中......
// tell GL to only draw onto a pixel if the shape is closer to the viewer
glEnable (GL_DEPTH_TEST); // enable depth-testing
glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer"
glClearColor (0.5f, 0.5f, 0.5f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram (shaderProgramID);
//Declare your uniform variables that will be used in your shader
int matrix_location = glGetUniformLocation (shaderProgramID, "model");
int view_mat_location = glGetUniformLocation (shaderProgramID, "view");
int proj_mat_location = glGetUniformLocation (shaderProgramID, "proj");
mat4 view = identity_mat4 ();
mat4 persp_proj = perspective(45.0, (float)width/(float)height, 0.1, 100.0);
mat4 model = identity_mat4 ();
view = translate (view, vec3 (0.0, 0.0, -5.0f));
glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, persp_proj.m);
glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view.m);
glUniformMatrix4fv (matrix_location, 1, GL_FALSE, model.m);
glBindVertexArray(_vertexArray1);
//model = translate (view, vec3 (0.0, -3.0F, 0.0));
glDrawArrays (GL_TRIANGLES, 0, g_point_count);
glBindVertexArray(0);
现在我的问题是我想在一个 vao 中独立地移动对象。我应该怎么做?我应该只是翻译模型矩阵然后解除绑定 vao 并绑定另一个并再次翻译相同的模型矩阵吗?在谷歌搜索了一段时间后,我认为我应该使用 glPushMatrix 和 glTranslatef 但我要推送什么矩阵?
本质上,我的 vao 的矩阵在哪里需要翻译才能移动 vao 中的对象?