public void orthof(float left, float right, float bottom, float top, float zNear, float zFar) { orthoproj[0] = left; orthoproj[1] = right; orthoproj[2] = bottom; orthoproj[3] = top; pvmat.glMatrixMode(GL2.GL_PROJECTION); pvmat.glLoadIdentity(); pvmat.glOrthof(left, right, bottom, top, zNear, zFar); pvmat.update(); }
public void updateModelMatrix(GL2GL3 gl, Shader shader, PMVMatrix model) { model.update(); // if(gl.glGetUniformLocation(shader.getID(), "model") == -1) // System.out.println("uniform model error"); gl.glUniformMatrix4fv( gl.glGetUniformLocation(shader.getID(), "model"), 1, false, model.glGetMatrixf(GL2.GL_MODELVIEW)); }
public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); mats.glMatrixMode(GL2.GL_MODELVIEW); mats.glLoadIdentity(); mats.glTranslatef(0f, 0f, -2.0f); // t = t+0.5f; t = 40f; mats.glRotatef(t, 0f, 1f, 0f); mats.glMatrixMode(GL2.GL_PROJECTION); mats.glLoadIdentity(); mats.glFrustumf(-1f, 1f, -1f, 1f, 1f, 100f); mats.update(); gl.glUseProgram(shader.getID()); gl.glUniformMatrix4fv(uniformMat, 3, false, mats.glGetPMvMviMatrixf()); obj.display(gl, mats); gl.glFlush(); gl.glUseProgram(0); }
/** * Creates an instance of PMVMatrix. * * @param useBackingArray <code>true</code> for non direct NIO Buffers with guaranteed backing * array, which allows faster access in Java computation. * <p><code>false</code> for direct NIO buffers w/o a guaranteed backing array. In most Java * implementations, direct NIO buffers have no backing array and hence the Java computation * will be throttled down by direct IO get/put operations. * <p>Depending on the application, ie. whether the Java computation or JNI invocation and * hence native data transfer part is heavier, this flag shall be set to <code>true</code> or * <code>false</code>. */ public PMVMatrix(boolean useBackingArray) { this.usesBackingArray = useBackingArray; // I Identity // T Texture // P Projection // Mv ModelView // Mvi Modelview-Inverse // Mvit Modelview-Inverse-Transpose if (useBackingArray) { matrixBufferArray = new float[6 * 16 + ProjectFloat.getRequiredFloatBufferSize()]; matrixBuffer = null; } else { matrixBufferArray = null; matrixBuffer = Buffers.newDirectByteBuffer( (6 * 16 + ProjectFloat.getRequiredFloatBufferSize()) * Buffers.SIZEOF_FLOAT); matrixBuffer.mark(); } matrixIdent = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 0 * 16, 1 * 16); // I matrixTex = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 1 * 16, 1 * 16); // T matrixPMvMvit = Buffers.slice2Float( matrixBuffer, matrixBufferArray, 2 * 16, 4 * 16); // P + Mv + Mvi + Mvit matrixPMvMvi = Buffers.slice2Float( matrixBuffer, matrixBufferArray, 2 * 16, 3 * 16); // P + Mv + Mvi matrixPMv = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 2 * 16, 2 * 16); // P + Mv matrixP = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 2 * 16, 1 * 16); // P matrixMv = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 3 * 16, 1 * 16); // Mv matrixMvi = Buffers.slice2Float( matrixBuffer, matrixBufferArray, 4 * 16, 1 * 16); // Mvi matrixMvit = Buffers.slice2Float( matrixBuffer, matrixBufferArray, 5 * 16, 1 * 16); // Mvit projectFloat = new ProjectFloat(matrixBuffer, matrixBufferArray, 6 * 16); if (null != matrixBuffer) { matrixBuffer.reset(); } FloatUtil.makeIdentityf(matrixIdent); vec3f = new float[3]; matrixMult = new float[16]; matrixTrans = new float[16]; matrixRot = new float[16]; matrixScale = new float[16]; matrixOrtho = new float[16]; matrixFrustum = new float[16]; FloatUtil.makeIdentityf(matrixTrans, 0); FloatUtil.makeIdentityf(matrixRot, 0); FloatUtil.makeIdentityf(matrixScale, 0); FloatUtil.makeIdentityf(matrixOrtho, 0); FloatUtil.makeZero(matrixFrustum, 0); matrixPStack = new ArrayList<float[]>(); matrixMvStack = new ArrayList<float[]>(); // default values and mode glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL.GL_TEXTURE); glLoadIdentity(); setDirty(); update(); }