If you think the Android project android-plotter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.solovyev.android.plotter.meshes;
/*www.java2s.com*/import org.solovyev.android.plotter.Check;
import javax.annotation.Nonnull;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
finalclass Arrays {
// create on the background thread and accessed from GL thread
privatevolatile FloatBuffer verticesBuffer;
privatevolatile ShortBuffer indicesBuffer;
float[] vertices;
short[] indices;
int vertex = 0;
int index = 0;
public Arrays() {
}
public Arrays(int verticesCount, int indicesCount) {
this.vertices = newfloat[verticesCount];
this.indices = newshort[indicesCount];
}
publicboolean isCreated() {
return vertices != null && indices != null;
}
publicvoid add(int i, float x, float y, float z) {
add((short) i, x, y, z);
}
publicvoid add(short i, float x, float y, float z) {
Check.isTrue(vertex < vertices.length, "Vertices must be allocated properly");
Check.isTrue(index < indices.length, "Indices must be allocated properly");
indices[index++] = i;
vertices[vertex++] = x;
vertices[vertex++] = y;
vertices[vertex++] = z;
}
publicvoid init() {
vertex = 0;
index = 0;
verticesBuffer = null;
indicesBuffer = null;
}
publicvoid init(int verticesCount, int indicesCount) {
if (vertices == null || vertices.length != verticesCount) {
vertices = newfloat[verticesCount];
}
if (indices == null || indices.length != indicesCount) {
indices = newshort[indicesCount];
}
init();
}
publicvoid createBuffers() {
Check.isTrue(isCreated(), "Arrays should be initialized");
verticesBuffer = Meshes.allocateOrPutBuffer(vertices, verticesBuffer);
indicesBuffer = Meshes.allocateOrPutBuffer(indices, indicesBuffer);
}
@Nonnull
public FloatBuffer getVerticesBuffer() {
Check.isTrue(isCreated(), "Arrays should be initialized");
Check.isNotNull(verticesBuffer);
return verticesBuffer;
}
@Nonnull
public ShortBuffer getIndicesBuffer() {
Check.isTrue(isCreated(), "Arrays should be initialized");
Check.isNotNull(indicesBuffer);
return indicesBuffer;
}
}