Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android.view.visualization;
00018
00019 import com.google.common.base.Preconditions;
00020
00021 import java.nio.ByteBuffer;
00022 import java.nio.ByteOrder;
00023 import java.nio.FloatBuffer;
00024
00025 import javax.microedition.khronos.opengles.GL10;
00026
00030 public class Vertices {
00031
00032 private static final int FLOAT_BYTE_SIZE = Float.SIZE / 8;
00033
00034 private Vertices() {
00035
00036 }
00037
00038 public static FloatBuffer allocateBuffer(int size) {
00039 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(size * FLOAT_BYTE_SIZE);
00040 byteBuffer.order(ByteOrder.nativeOrder());
00041 return byteBuffer.asFloatBuffer();
00042 }
00043
00044 public static FloatBuffer toFloatBuffer(float[] floats) {
00045 FloatBuffer floatBuffer = allocateBuffer(floats.length);
00046 floatBuffer.put(floats);
00047 floatBuffer.position(0);
00048 return floatBuffer;
00049 }
00050
00051 public static void drawPoints(GL10 gl, FloatBuffer vertices, Color color, float size) {
00052 color.apply(gl);
00053 gl.glPointSize(size);
00054 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
00055 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
00056 gl.glDrawArrays(GL10.GL_POINTS, 0, countVertices(vertices, 3));
00057 gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
00058 }
00059
00060 public static void drawTriangleFan(GL10 gl, FloatBuffer vertices, Color color) {
00061 color.apply(gl);
00062 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
00063 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
00064 gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, countVertices(vertices, 3));
00065 gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
00066 }
00067
00068 private static int countVertices(FloatBuffer vertices, int size) {
00069
00070 Preconditions.checkArgument(vertices.remaining() % size == 0);
00071 return vertices.remaining() / size;
00072 }
00073 }