use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class TestTangentGen method createTriangleStripMesh.
private Mesh createTriangleStripMesh() {
Mesh strip = new Mesh();
strip.setMode(Mode.TriangleStrip);
// 3 rows * 3 columns * 3 floats
FloatBuffer vb = BufferUtils.createFloatBuffer(3 * 3 * 3);
vb.rewind();
vb.put(new float[] { 0, 2, 0 });
vb.put(new float[] { 1, 2, 0 });
vb.put(new float[] { 2, 2, 0 });
vb.put(new float[] { 0, 1, 0 });
vb.put(new float[] { 1, 1, 0 });
vb.put(new float[] { 2, 1, 0 });
vb.put(new float[] { 0, 0, 0 });
vb.put(new float[] { 1, 0, 0 });
vb.put(new float[] { 2, 0, 0 });
FloatBuffer nb = BufferUtils.createFloatBuffer(3 * 3 * 3);
nb.rewind();
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
nb.put(new float[] { 0, 0, 1 });
FloatBuffer tb = BufferUtils.createFloatBuffer(3 * 3 * 2);
tb.rewind();
tb.put(new float[] { 0, 0 });
tb.put(new float[] { 0.5f, 0 });
tb.put(new float[] { 1, 0 });
tb.put(new float[] { 0, 0.5f });
tb.put(new float[] { 0.5f, 0.5f });
tb.put(new float[] { 1, 0.5f });
tb.put(new float[] { 0, 1 });
tb.put(new float[] { 0.5f, 1 });
tb.put(new float[] { 1, 1 });
int[] indexes = new int[] { 0, 3, 1, 4, 2, 5, 5, 3, 3, 6, 4, 7, 5, 8 };
IntBuffer ib = BufferUtils.createIntBuffer(indexes.length);
ib.put(indexes);
strip.setBuffer(Type.Position, 3, vb);
strip.setBuffer(Type.Normal, 3, nb);
strip.setBuffer(Type.TexCoord, 2, tb);
strip.setBuffer(Type.Index, 3, ib);
strip.updateBound();
return strip;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class FilteredBasis method clip.
public FloatBuffer clip(FloatBuffer buf, int origSize, int newSize, int offset) {
FloatBuffer result = FloatBuffer.allocate(newSize * newSize);
float[] orig = buf.array();
for (int i = offset; i < offset + newSize; i++) {
result.put(orig, i * origSize + offset, newSize);
}
return result;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class AbstractFilter method doFilter.
@Override
public FloatBuffer doFilter(float sx, float sy, float base, FloatBuffer data, int size) {
if (!this.isEnabled()) {
return data;
}
FloatBuffer retval = data;
for (Filter f : this.preFilters) {
retval = f.doFilter(sx, sy, base, retval, size);
}
retval = this.filter(sx, sy, base, retval, size);
for (Filter f : this.postFilters) {
retval = f.doFilter(sx, sy, base, retval, size);
}
return retval;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class OSVR method getHMDMatrixProjectionLeftEye.
@Override
public Matrix4f getHMDMatrixProjectionLeftEye(Camera cam) {
if (eyeLeftInfo == null)
return cam.getProjectionMatrix();
if (eyeMatrix[EYE_LEFT] == null) {
FloatBuffer tfb = FloatBuffer.allocate(16);
com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte) EYE_LEFT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short) 0, tfb);
eyeMatrix[EYE_LEFT] = new Matrix4f();
eyeMatrix[EYE_LEFT].set(tfb.get(0), tfb.get(4), tfb.get(8), tfb.get(12), tfb.get(1), tfb.get(5), tfb.get(9), tfb.get(13), tfb.get(2), tfb.get(6), tfb.get(10), tfb.get(14), tfb.get(3), tfb.get(7), tfb.get(11), tfb.get(15));
}
return eyeMatrix[EYE_LEFT];
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class TerrainPatch method setHeight.
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
final float[] heightArray = geomap.getHeightArray();
final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
for (LocationHeight lh : locationHeights) {
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
continue;
}
int idx = lh.z * size + lh.x;
if (overrideHeight) {
heightArray[idx] = lh.h;
} else {
float currentHeight = floatBuffer.get(idx * 3 + 1);
heightArray[idx] = currentHeight + lh.h;
}
}
floatBuffer.clear();
geomap.writeVertexArray(floatBuffer, stepScale, false);
vertexBuffer.setUpdateNeeded();
}
Aggregations