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 int position() 

Source Link

Document

Returns the position of this buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/*from   w w w. ja  va 2 s. c  o m*/
    FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
    System.out.println("Float Buffer");
    while (fb.hasRemaining())
        System.out.println(fb.position() + " -> " + fb.get());

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();/*ww  w  .  j a v  a  2 s . co  m*/
    System.out.println("Byte Buffer");
    while (bb.hasRemaining())
        System.out.println(bb.position() + " -> " + bb.get());
    CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
    System.out.println("Char Buffer");
    while (cb.hasRemaining())
        System.out.println(cb.position() + " -> " + cb.get());
    FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
    System.out.println("Float Buffer");
    while (fb.hasRemaining())
        System.out.println(fb.position() + " -> " + fb.get());
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
        System.out.println(ib.position() + " -> " + ib.get());
    LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
    System.out.println("Long Buffer");
    while (lb.hasRemaining())
        System.out.println(lb.position() + " -> " + lb.get());
    ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
    System.out.println("Short Buffer");
    while (sb.hasRemaining())
        System.out.println(sb.position() + " -> " + sb.get());
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
        System.out.println(db.position() + " -> " + db.get());
}

From source file:Main.java

public static FloatBuffer ensureLargeEnough(FloatBuffer buf, final int required) {
    if (buf == null || (buf.remaining() < required)) {
        final int position = (buf != null ? buf.position() : 0);
        final FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buf != null) {
            buf.rewind();//w  w  w  . j a  va  2 s  .c  o m
            newVerts.put(buf);
            newVerts.position(position);
        }
        buf = newVerts;
    }
    return buf;
}

From source file:Main.java

public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, final int required) {
    if (buffer == null || (buffer.remaining() < required)) {
        final int position = (buffer != null ? buffer.position() : 0);
        final FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buffer != null) {
            buffer.rewind();/*from  w w w. ja  v a 2 s. c  o m*/
            newVerts.put(buffer);
            newVerts.position(position);
        }
        buffer = newVerts;
    }
    return buffer;
}

From source file:org.deegree.tools.rendering.manager.buildings.PrototypeManager.java

/**
 * @param rqm/*from ww w .j  av a  2s.  c o m*/
 */
private RenderableQualityModel createScaledQualityModel(RenderableQualityModel rqm) {
    float minX = Float.MAX_VALUE;
    float minY = Float.MAX_VALUE;
    float minZ = Float.MAX_VALUE;
    float maxX = Float.MIN_VALUE;
    float maxY = Float.MIN_VALUE;
    float maxZ = Float.MIN_VALUE;
    ArrayList<RenderableQualityModelPart> qualityModelParts = rqm.getQualityModelParts();
    for (RenderableQualityModelPart rqmp : qualityModelParts) {
        if (rqmp != null) {
            RenderableGeometry geom = (RenderableGeometry) rqmp;
            FloatBuffer fb = geom.getCoordBuffer();
            fb.rewind();
            int position = fb.position();
            while (position < fb.capacity()) {
                float x = fb.get();
                float y = fb.get();
                float z = fb.get();

                minX = Math.min(minX, x);
                minY = Math.min(minY, y);
                minZ = Math.min(minZ, z);

                maxX = Math.max(maxX, x);
                maxY = Math.max(maxY, y);
                maxZ = Math.max(maxZ, z);
                position = fb.position();
            }
        }
    }

    double scaleX = 1d / (maxX - minX);
    double scaleY = 1d / (maxY - minY);
    double scaleZ = 1d / (maxZ - minZ);

    for (RenderableQualityModelPart rqmp : qualityModelParts) {
        if (rqmp != null) {
            RenderableGeometry geom = (RenderableGeometry) rqmp;
            FloatBuffer fb = geom.getCoordBuffer();
            fb.rewind();
            int i = 0;
            while ((i + 3) <= fb.capacity()) {
                float x = fb.get(i);
                x -= minX;
                x *= scaleX;
                fb.put(i, x);

                float y = fb.get(i + 1);
                y -= minY;
                y *= scaleY;
                fb.put(i + 1, y);

                float z = fb.get(i + 2);
                z -= minZ;
                z *= scaleZ;
                fb.put(i + 2, z);
                i += 3;
            }
        }
    }
    return rqm;

}