Advertisement
Guest User

Untitled

a guest
Nov 26th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package com.example.dipl_stickman_dirt_jumping;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.ByteOrder;
  5. import java.nio.FloatBuffer;
  6. import java.nio.ShortBuffer;
  7.  
  8. import javax.microedition.khronos.opengles.GL10;
  9.  
  10. public class Mesh {
  11.  
  12. public float x = 0;
  13. public float y = 0;
  14. public float z = 0
  15. ;
  16. private FloatBuffer verticesBuffer;
  17. private ShortBuffer indicesBuffer;
  18.  
  19. private int numOfIndices = -1;
  20.  
  21. public void draw(GL10 gl)
  22. {
  23. gl.glFrontFace(GL10.GL_CCW);
  24. gl.glEnable(GL10.GL_CULL_FACE);
  25. gl.glCullFace(GL10.GL_BACK);
  26. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  27. gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
  28.  
  29. gl.glPushMatrix();
  30. gl.glTranslatef(x, y, z);
  31. gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices, GL10.GL_UNSIGNED_SHORT, indicesBuffer);
  32. gl.glPopMatrix();
  33.  
  34. gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  35. gl.glDisable(GL10.GL_CULL_FACE);
  36. }
  37.  
  38. protected void setVertices(float[] vertices)
  39. {
  40. ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
  41. vbb.order(ByteOrder.nativeOrder());
  42. verticesBuffer = vbb.asFloatBuffer();
  43. verticesBuffer.put(vertices);
  44. verticesBuffer.position(0);
  45. }
  46.  
  47. protected void setIndices(short[] indices)
  48. {
  49. ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length*2);
  50. ibb.order(ByteOrder.nativeOrder());
  51. indicesBuffer = ibb.asShortBuffer();
  52. indicesBuffer.put(indices);
  53. indicesBuffer.position(0);
  54. numOfIndices = indices.length;
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement