use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method createFloatBuffer.
/**
* Generate a new FloatBuffer using the given array of Quaternion objects.
* The FloatBuffer will be 4 * data.length long and contain the vector data.
*
* @param data
* array of Quaternion objects to place into a new FloatBuffer
*/
public static FloatBuffer createFloatBuffer(Quaternion... data) {
if (data == null) {
return null;
}
FloatBuffer buff = createFloatBuffer(4 * data.length);
for (Quaternion element : data) {
if (element != null) {
buff.put(element.getX()).put(element.getY()).put(element.getZ()).put(element.getW());
} else {
buff.put(0).put(0).put(0).put(0);
}
}
buff.flip();
return buff;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method createFloatBuffer.
/**
* Generate a new FloatBuffer using the given array of float primitives.
*
* @param data
* array of float primitives to place into a new FloatBuffer
*/
public static FloatBuffer createFloatBuffer(float... data) {
if (data == null) {
return null;
}
FloatBuffer buff = createFloatBuffer(data.length);
buff.clear();
buff.put(data);
buff.flip();
return buff;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class BinaryInputCapsule method readFloatBuffer.
// NIO BUFFERS
// float buffer
protected FloatBuffer readFloatBuffer(byte[] content) throws IOException {
int length = readInt(content);
if (length == BinaryOutputCapsule.NULL_OBJECT)
return null;
if (BinaryImporter.canUseFastBuffers()) {
ByteBuffer value = BufferUtils.createByteBuffer(length * 4);
value.put(content, index, length * 4).rewind();
index += length * 4;
return value.asFloatBuffer();
} else {
FloatBuffer value = BufferUtils.createFloatBuffer(length);
for (int x = 0; x < length; x++) {
value.put(readFloatForBuffer(content));
}
value.rewind();
return value;
}
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method clone.
/**
* Creates a new FloatBuffer with the same contents as the given
* FloatBuffer. The new FloatBuffer is separate from the old one and changes
* are not reflected across. If you want to reflect changes, consider using
* Buffer.duplicate().
*
* @param buf
* the FloatBuffer to copy
* @return the copy
*/
public static FloatBuffer clone(FloatBuffer buf) {
if (buf == null) {
return null;
}
buf.rewind();
FloatBuffer copy;
if (isDirect(buf)) {
copy = createFloatBuffer(buf.limit());
} else {
copy = FloatBuffer.allocate(buf.limit());
}
copy.put(buf);
return copy;
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method createFloatBuffer.
// // -- VECTOR2F METHODS -- ////
/**
* Generate a new FloatBuffer using the given array of Vector2f objects. The
* FloatBuffer will be 2 * data.length long and contain the vector data as
* data[0].x, data[0].y, data[1].x... etc.
*
* @param data
* array of Vector2f objects to place into a new FloatBuffer
*/
public static FloatBuffer createFloatBuffer(Vector2f... data) {
if (data == null) {
return null;
}
FloatBuffer buff = createFloatBuffer(2 * data.length);
for (Vector2f element : data) {
if (element != null) {
buff.put(element.x).put(element.y);
} else {
buff.put(0).put(0);
}
}
buff.flip();
return buff;
}
Aggregations