Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void render() {
- /** Transform shape **/
- mvpMatrix = Core.getRenderer().getMvp();
- for (int i = 0; i< 16; i++) {
- scratchMatrix[i] = mvpMatrix[i];
- scratchMatrix2[i] = mvpMatrix[i];
- }
- // (Applied Last) Move the shape to its world position
- Matrix.multiplyMM(scratchMatrix2, 0, scratchMatrix, 0, positionMatrix, 0);
- // Unshift the shape from its center point
- Matrix.multiplyMM(scratchMatrix, 0, scratchMatrix2, 0, invertedCenterMatrix, 0);
- // Apply the rotation
- Matrix.multiplyMM(scratchMatrix2, 0, scratchMatrix, 0, rotationMatrix, 0);
- // Shift the shape to its center point
- Matrix.multiplyMM(scratchMatrix, 0, scratchMatrix2, 0, centerMatrix, 0);
- /** Render shape **/
- // Add program to OpenGL environment
- GLES20.glUseProgram(this.shaderProgram);
- // Get the vertex position attribute
- int mPositionHandle = GLES20.glGetAttribLocation(this.shaderProgram, "vPosition");
- // Enable generic vertex attribute array
- GLES20.glEnableVertexAttribArray(mPositionHandle);
- // Prepare the shape coordinate data
- GLES20.glVertexAttribPointer(
- mPositionHandle,
- COORDS_PER_VERTEX,
- GLES20.GL_FLOAT,
- false,
- this.vertexStride,
- this.vertexBuffer
- );
- // Get the program's transformation matrix
- int mtrxhandle = GLES20.glGetUniformLocation(this.shaderProgram, "uMVPMatrix");
- // Apply the projection and view transformation
- GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, scratchMatrix, 0);
- // Draw the shape
- GLES20.glDrawElements(
- GLES20.GL_TRIANGLES,
- this.indicesLength,
- GLES20.GL_UNSIGNED_SHORT,
- this.drawListBuffer
- );
- // Disable vertex array
- GLES20.glDisableVertexAttribArray(mPositionHandle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement