Search in sources :

Example 36 with FloatBuffer

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;
}
Also used : Quaternion(com.jme3.math.Quaternion) FloatBuffer(java.nio.FloatBuffer)

Example 37 with FloatBuffer

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;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 38 with FloatBuffer

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;
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 39 with FloatBuffer

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;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 40 with FloatBuffer

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;
}
Also used : Vector2f(com.jme3.math.Vector2f) FloatBuffer(java.nio.FloatBuffer)

Aggregations

FloatBuffer (java.nio.FloatBuffer)291 ByteBuffer (java.nio.ByteBuffer)82 IntBuffer (java.nio.IntBuffer)43 ShortBuffer (java.nio.ShortBuffer)39 Vector3f (com.jme3.math.Vector3f)27 VertexBuffer (com.jme3.scene.VertexBuffer)27 DoubleBuffer (java.nio.DoubleBuffer)17 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)16 LongBuffer (java.nio.LongBuffer)10 Mesh (com.jme3.scene.Mesh)9 CharBuffer (java.nio.CharBuffer)9 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)8 OutputPort (androidx.media.filterfw.OutputPort)7 Matrix4f (com.jme3.math.Matrix4f)7 Buffer (java.nio.Buffer)7 TempVars (com.jme3.util.TempVars)6 IOException (java.io.IOException)6 BufferOverflowException (java.nio.BufferOverflowException)6 BufferUnderflowException (java.nio.BufferUnderflowException)6 ArrayList (java.util.ArrayList)6