Example usage for java.nio FloatBuffer position

List of usage examples for java.nio FloatBuffer position

Introduction

In this page you can find the example usage for java.nio FloatBuffer position.

Prototype

public final Buffer position(int newPosition) 

Source Link

Document

Sets the position of this buffer.

Usage

From source file:Main.java

public static FloatBuffer makeFloatBuffer(int i_len) {
    ByteBuffer bb = ByteBuffer.allocateDirect(i_len * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.position(0);
    return fb;/*from  ww w .  j  a v a2  s  . c o m*/
}

From source file:Main.java

public static FloatBuffer makeFloatBufferFromArray(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);// w  w  w. j a  v a 2 s.co m
    fb.position(0);
    return fb;
}

From source file:Main.java

static void toArray(FloatBuffer src, float[] dst, int offset) {
    src.position(0);
    src.get(dst, offset, dst.length - offset);
}

From source file:Main.java

/**
 * Make a direct NIO FloatBuffer from an array of floats
 * @param arr The array/*w w  w .  ja va2 s . c  om*/
 * @return The newly created FloatBuffer
 */
public static FloatBuffer makeFloatBuffer(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);
    fb.position(0);
    return fb;
}

From source file:Main.java

public static FloatBuffer replaceFloats(int destPos, FloatBuffer dest, int srcPos, float... src) {
    dest.position(destPos);
    dest.put(src, srcPos, src.length - srcPos);
    dest.position(0);//from  www .  ja  va2  s .c o  m
    return dest;
}

From source file:Main.java

public static FloatBuffer toFloatBuffer(float[] v) {
    ByteBuffer buff = ByteBuffer.allocateDirect(v.length * 4);
    buff.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = buff.asFloatBuffer();
    buffer.put(v);//from  w w w . j a  v a2s.c o m
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(float[] i_arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(i_arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(i_arr);//from   w  w w .j  ava 2  s .c  om
    fb.position(0);
    return fb;
}

From source file:Main.java

/**
 * //from  w w  w. j a va2  s  .c  o m
 * @since 1.0.0
 * @param v
 * @return the FloatBuffer
 */
public static FloatBuffer toFloatBuffer(float[] v) {
    ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 4);
    buf.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = buf.asFloatBuffer();
    buffer.put(v);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(float[] coords) {
    // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(coords);//from w w  w . j a  va 2  s.  com
    fb.position(0);
    return fb;
}

From source file:Main.java

public static void copy(final float[] data, final FloatBuffer buf, final int fromPos, final int toPos) {
    buf.position(fromPos);
    buf.get(data);/*from w w w.  ja  va  2 s. c o  m*/
    buf.position(toPos);
    buf.put(data);
}