Advertisement
Guest User

Player Class

a guest
Jun 15th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package Objects;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.ByteOrder;
  5. import java.nio.FloatBuffer;
  6.  
  7. import javax.microedition.khronos.opengles.GL10;
  8.  
  9. import Physics.Physics;
  10. import android.opengl.GLES10;
  11. import android.util.Log;
  12.  
  13. public class Player
  14. {
  15.     // Physics Variables //
  16.    
  17.     public double v = 0.0;
  18.    
  19.     // // // // // // // //
  20.    
  21.     Physics phy = new Physics();
  22.     private FloatBuffer vertexBuffer;
  23.  
  24.     private float vertices[] = {
  25.         -0.15f,  1.0f,  0.0f,       // V1 - bottom left
  26.         -0.15f,  0.85f,  0.0f,          // V2 - top left
  27.         0.15f, 1.0f,  0.0f,         // V3 - bottom right
  28.         0.15f,  0.85f,  0.0f            // V4 - top right
  29.     };
  30.  
  31.     public Player()
  32.     {
  33.        
  34.     }
  35.  
  36.     public void getVertex()
  37.     {
  38.         // a float has 4 bytes so we allocate for each coordinate 4 bytes
  39.             ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
  40.             vertexByteBuffer.order(ByteOrder.nativeOrder());
  41.  
  42.             // allocates the memory from the byte buffer
  43.             vertexBuffer = vertexByteBuffer.asFloatBuffer();
  44.  
  45.             // fill the vertexBuffer with the vertices
  46.             vertexBuffer.put(vertices);
  47.  
  48.             // set the cursor position to the beginning of the buffer
  49.             vertexBuffer.position(0);
  50.     }
  51.    
  52.     /** The draw method for the square with the GL context */
  53.     public void draw(GL10 gl)
  54.     {
  55.         //move();
  56.         getVertex();
  57.        
  58.         Log.i("DRAWING", "0 : DRAWING SQUARE");
  59.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  60.  
  61.         // set the colour for the square
  62.         //gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
  63.  
  64.         gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  65.        
  66.         // Point to our vertex buffer
  67.         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
  68.  
  69.         // Draw the vertices as triangle strip
  70.         gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
  71.        
  72.         //Disable the client state before leaving
  73.         //gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  74.        
  75.         Log.i("1 : DRAWING", "DRAWING SQUARE");
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement