當我使用旋轉矩陣在 openGL 中旋轉我的正方形時,當我想圍繞 X 或 Y 軸旋轉它時,整個對象消失并拉伸。Z 軸工作正常。問題可能是什么?我嘗試在 DrawArrays 之前加載uniformMatrix4f,但它不起作用。仍然是同樣的問題。翻譯工作正常且可擴展。渲染方法public void render(Player model, Cube cube_model, StaticShader shader) { GL30.glBindVertexArray(model.vaoID); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); shader.loadModelMatrix(Maths.createModelMatrix(new Vector3f(move_X,-Display.getHeight(),0f), 0f,0f,tilt_Y,1f)); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); GL30.glBindVertexArray(cube_model.vaoID); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); shader.loadModelMatrix(Maths.createModelMatrix(new Vector3f(0f,Display.getHeight() - 200f,0f), 0f,increaseRotation,0f,0.5f)); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6); increaseRotation += 1f; GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL30.glBindVertexArray(0); }矩陣數學:public static Matrix4f createModelMatrix(Vector3f t, float rx, float ry, float rz, float s) { Matrix4f modelMatrix = new Matrix4f(); modelMatrix.setIdentity(); Matrix4f.translate(t, modelMatrix, modelMatrix); Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), modelMatrix, modelMatrix); Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), modelMatrix, modelMatrix); Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), modelMatrix, modelMatrix); Matrix4f.scale(new Vector3f(s,s,s), modelMatrix, modelMatrix); return modelMatrix; }我期望立方體正常地在 Y 軸上旋轉到位,但它實際上正在旋轉并消失,然后它的一條線在中間出現拉伸并消失。
1 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
我想圍繞 X 或 Y 軸旋轉它,整個對象消失并拉伸。Z 軸工作正常。
當然。
你的物體是一個二維物體。它只是一個具有二維 x 和 y 的平面。x 軸和 y 軸平行于視口。z 軸指向視口之外。
如果繞 z 軸(在 xy 平面中)旋轉,對象將保持其大小并旋轉。
但如果繞 x 軸旋轉,則對象似乎沿 y 軸拉伸并以 90° 和 270° 的角度消失。如果繞 y 軸旋轉,則對象似乎沿 x 軸拉伸。
由于正交投影,圍繞 x 和 y 軸的旋轉看起來“平坦” 。實際上,您沒有投影矩陣,因此場景是并行投影的(正交)。
如果你想“看到”3維旋轉,那么你必須使用透視投影
添加回答
舉報
0/150
提交
取消