我在64x64x64立方體內繪製了一堆點,但無法弄清楚如何置換原點,以便圍繞立方體的中心進行旋轉。 我的頂點數據存儲在一維數組內,從{(0,0,0),(0,0,1),...,(63,63,63)}。利用OpenGL將立方體置換成原點
這是我當前的代碼來設置矩陣的每個幀:
// Set ProjectionMatrix
projectionMatrix = glm::perspective(90.0f, (GLfloat)width/(GLfloat) height,0.1f, 1000.f);
glUniformMatrix4fv(location_projectionMatrix, 1, GL_FALSE, glm::value_ptr(projectionMatrix));
// Set ModelViewMatrix
glm::mat4 identity = glm::mat4(1.0);
glm::mat4 viewTranslate = glm::translate(identity, glm::vec3(0.0f, 0.0f, -translate_z));
glm::mat4 viewRotateX = glm::rotate(viewTranslate, rotate_x, glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 viewRotateY = glm::rotate(viewRotateX, rotate_y, glm::vec3(0.0f, 1.0f, 0.0f));
modelViewMatrix = viewRotateY;
glUniformMatrix4fv(location_modelViewMatrix, 1, GL_FALSE, glm::value_ptr(modelViewMatrix));
我試圖-32到僅僅翻譯成立方體的x,y方向,但沒有成功。
你是什麼意思*沒有成功*? –
立方體被取代,但不是我想要的方式。旋轉和縮放應該與立方體的中心相關,目前這個原點是其中一個角落。 – Schnigges
所以先翻譯一半大小。 –