Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dipl_stickman_dirt_jumping;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import java.nio.FloatBuffer;
- import java.nio.ShortBuffer;
- import javax.microedition.khronos.opengles.GL10;
- public class Mesh {
- public float x = 0;
- public float y = 0;
- public float z = 0
- ;
- private FloatBuffer verticesBuffer;
- private ShortBuffer indicesBuffer;
- private int numOfIndices = -1;
- public void draw(GL10 gl)
- {
- gl.glFrontFace(GL10.GL_CCW);
- gl.glEnable(GL10.GL_CULL_FACE);
- gl.glCullFace(GL10.GL_BACK);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
- gl.glPushMatrix();
- gl.glTranslatef(x, y, z);
- gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices, GL10.GL_UNSIGNED_SHORT, indicesBuffer);
- gl.glPopMatrix();
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glDisable(GL10.GL_CULL_FACE);
- }
- protected void setVertices(float[] vertices)
- {
- ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
- vbb.order(ByteOrder.nativeOrder());
- verticesBuffer = vbb.asFloatBuffer();
- verticesBuffer.put(vertices);
- verticesBuffer.position(0);
- }
- protected void setIndices(short[] indices)
- {
- ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length*2);
- ibb.order(ByteOrder.nativeOrder());
- indicesBuffer = ibb.asShortBuffer();
- indicesBuffer.put(indices);
- indicesBuffer.position(0);
- numOfIndices = indices.length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement