If you think the Android project splott 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 com.wordsaretoys.rise.meshutil;
//www.java2s.com/**
* growable short int buffer
*
* @namespace rise
* @class IndexBuffer
*/publicclass IndexBuffer {
publicshort[] data;
publicint length;
finalstaticprivatedouble LN2 = Math.log(2);
privateint limit;
public IndexBuffer() {
data = newshort[16];
length = 0;
}
/**
* grow the vertex buffer if necessary
* @param n number of shorts to grow by
*/privatevoid grow(int n) {
int newSize = length + n;
if (newSize > limit) {
// find smallest power of 2 greater than newSize
limit = (int) Math.pow(2, Math.ceil(Math.log(newSize) / LN2));
short[] newBuffer = newshort[limit];
System.arraycopy(data, 0, newBuffer, 0, length);
data = newBuffer;
}
}
/**
* reset the mesh for use with a new data set
*/publicvoid reset() {
length = 0;
}
/**
* add values to the buffer
* @param i0...in values to add
*/publicvoid set(int i0) {
grow(1);
data[length++] = (short)i0;
}
publicvoid set(int i0, int i1, int i2) {
grow(3);
data[length++] = (short)i0;
data[length++] = (short)i1;
data[length++] = (short)i2;
}
publicvoid set(int i0, int i1, int i2, int i3, int i4, int i5) {
grow(6);
data[length++] = (short)i0;
data[length++] = (short)i1;
data[length++] = (short)i2;
data[length++] = (short)i3;
data[length++] = (short)i4;
data[length++] = (short)i5;
}
}