Advertisement
Guest User

Example

a guest
Feb 23rd, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. public void render() {
  2.     /** Transform shape **/
  3.     mvpMatrix = Core.getRenderer().getMvp();
  4.     for (int i = 0; i< 16; i++) {
  5.         scratchMatrix[i] = mvpMatrix[i];
  6.         scratchMatrix2[i] = mvpMatrix[i];
  7.     }  
  8.     // (Applied Last) Move the shape to its world position
  9.     Matrix.multiplyMM(scratchMatrix2, 0, scratchMatrix, 0, positionMatrix, 0);
  10.     // Unshift the shape from its center point
  11.     Matrix.multiplyMM(scratchMatrix, 0, scratchMatrix2, 0, invertedCenterMatrix, 0);
  12.     // Apply the rotation
  13.     Matrix.multiplyMM(scratchMatrix2, 0, scratchMatrix, 0, rotationMatrix, 0);
  14.     // Shift the shape to its center point
  15.     Matrix.multiplyMM(scratchMatrix, 0, scratchMatrix2, 0, centerMatrix, 0);       
  16.        
  17.         /** Render shape **/
  18.        
  19.     // Add program to OpenGL environment
  20.         GLES20.glUseProgram(this.shaderProgram);
  21.         // Get the vertex position attribute
  22.         int mPositionHandle = GLES20.glGetAttribLocation(this.shaderProgram, "vPosition");
  23.         // Enable generic vertex attribute array
  24.         GLES20.glEnableVertexAttribArray(mPositionHandle);
  25.         // Prepare the shape coordinate data
  26.         GLES20.glVertexAttribPointer(
  27.             mPositionHandle,
  28.             COORDS_PER_VERTEX,
  29.             GLES20.GL_FLOAT,
  30.             false,
  31.             this.vertexStride,
  32.             this.vertexBuffer
  33.         );
  34.         // Get the program's transformation matrix
  35.         int mtrxhandle = GLES20.glGetUniformLocation(this.shaderProgram, "uMVPMatrix");
  36.         // Apply the projection and view transformation        
  37.         GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, scratchMatrix, 0);
  38.         // Draw the shape
  39.         GLES20.glDrawElements(
  40.             GLES20.GL_TRIANGLES,
  41.             this.indicesLength,
  42.             GLES20.GL_UNSIGNED_SHORT,
  43.             this.drawListBuffer
  44.         );
  45.         // Disable vertex array
  46.         GLES20.glDisableVertexAttribArray(mPositionHandle);  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement