0
我有以下代碼初始化我的兩個矩陣中LWJGL:Opengl的攝像頭*投影*座標=無
GL20.glUseProgram(shaderProgramID);
Matrix4f camera = new Matrix4f();
Matrix4f.translate(new Vector3f(0, 0, 0), camera, camera);
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
camera.store(buffer);
buffer.flip();
GL20.glUniformMatrix2(GL20.glGetUniformLocation(shaderProgramID, "camera"), false, buffer);
GL20.glUseProgram(0);
float near = 0.1f, far = 100.0f, top = 300, bottom = -300, left = -400, right = 400;
Matrix4f projection = new Matrix4f();
projection.setIdentity();
projection.m00 = 2*near/(right - left);
projection.m11 = 2*near/(top - bottom);
projection.m22 = -(far +near)/(far - near);
projection.m23 = -1;
projection.m32 = -2*far*near/(far - near);
projection.m20 = (right+left)/(right -left);
projection.m21 = (top + bottom)/(top-bottom);
projection.m33 = 0;
FloatBuffer buffer2 = BufferUtils.createFloatBuffer(16);
projection.store(buffer2);
buffer.flip();
GL20.glUniformMatrix2(GL20.glGetUniformLocation(shaderProgramID, "projection"), false, buffer);
GL20.glUseProgram(0);
頂點着色器執行以下操作:
gl_Position = projection * camera * vec4(vert, 1);
我不知道有什麼事情對它有錯誤...任何人的想法?
如果你的'Matrix4f'類有一個叫做'setIdentity(...)'的函數,並且這不是一個在構造時執行的操作,那你爲什麼只把它叫做你的投影矩陣?翻譯***身份相機矩陣也是有意義的。 –
它不是我的班,它來自org.lwjgl.util ...是的,它有方法setIdentity(),但是這實際上是什麼意思?我也添加了它,但它沒有幫助...... –
'setIdentity(...)'設置矩陣,使其在主對角線上具有值** 1.0 **('m00','m11' ,'m22','m33')以及所有其他值爲** 0.0 **。最重要的是,這分配** 1.0 **到'm33'。爲了正確的翻譯和縮放,這很重要並且經常被忽略。 –