Example usage for java.nio FloatBuffer allocate

List of usage examples for java.nio FloatBuffer allocate

Introduction

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

Prototype

public static FloatBuffer allocate(int capacity) 

Source Link

Document

Creates a float buffer based on a newly allocated float array.

Usage

From source file:org.goko.tools.viewer.jogl.utils.render.basic.PolylineRenderer.java

/** (inheritDoc)
 * @see org.goko.tools.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer#buildGeometry()
 *///w  w  w  . j  av a  2s .c o  m
@Override
protected void buildGeometry() throws GkException {
    if (closed) {
        setVerticesCount(CollectionUtils.size(points) + 1);
    } else {
        setVerticesCount(CollectionUtils.size(points));
    }
    FloatBuffer vertices = FloatBuffer.allocate(getVerticesCount() * 4);
    FloatBuffer colors = FloatBuffer.allocate(getVerticesCount() * 4);

    if (CollectionUtils.isNotEmpty(points)) {
        for (Point3d p : points) {
            vertices.put(new float[] { (float) p.x, (float) p.y, (float) p.z, 1 });
            colors.put(new float[] { color.x, color.y, color.z, color.w });
        }

        if (closed) {
            Point3d p = points.get(0);
            vertices.put(new float[] { (float) p.x, (float) p.y, (float) p.z, 1 });
            colors.put(new float[] { color.x, color.y, color.z, color.w });
        }
    }
    vertices.rewind();
    colors.rewind();
    setVerticesBuffer(vertices);
    setColorsBuffer(colors);
}

From source file:org.rifidi.jme.quadtree.QuadTree.java

/**
 * Helpermethod to create a boundingbox from a node.
 * @param node/*from  w  w w . ja  v  a 2  s  .c  o  m*/
 * @return
 */
private BoundingBox createBoundingBox(Node node) {
    FloatBuffer vertexBuffer = null;
    BoundingBox bbox = new BoundingBox();
    //walk through all children
    for (Spatial child : node.getChildren()) {
        //check if it contains tri data
        if (child instanceof Geometry) {
            Geometry geom = ((Geometry) child);
            for (int count = 0; count < geom.getBatchCount(); count++) {
                if (vertexBuffer == null) {
                    vertexBuffer = geom.getVertexBuffer(count);
                } else {
                    FloatBuffer tempBuffer = FloatBuffer
                            .allocate(vertexBuffer.capacity() + geom.getVertexBuffer(count).capacity());
                    tempBuffer.put(vertexBuffer);
                    tempBuffer.put(geom.getVertexBuffer(count));
                    vertexBuffer = tempBuffer;
                }
            }
            //compute the boundingbox
            bbox.computeFromPoints(vertexBuffer);
        }
    }
    if (node.getLocalTranslation() == new Vector3f()) {
        bbox.setCenter(node.getLocalTranslation());
    }
    return bbox;
}

From source file:ummisco.gama.opengl.vaoGenerator.GeomMathUtils.java

static public FloatBuffer getFloatBuffer(final Matrix4f matrix) {
    final FloatBuffer result = FloatBuffer.allocate(16);
    result.put(0, matrix.m00);//ww  w .ja v a 2 s .  c o m
    result.put(1, matrix.m01);
    result.put(2, matrix.m02);
    result.put(3, matrix.m03);
    result.put(4, matrix.m10);
    result.put(5, matrix.m11);
    result.put(6, matrix.m12);
    result.put(7, matrix.m13);
    result.put(8, matrix.m20);
    result.put(9, matrix.m21);
    result.put(10, matrix.m22);
    result.put(11, matrix.m23);
    result.put(12, matrix.m30);
    result.put(13, matrix.m31);
    result.put(14, matrix.m32);
    result.put(15, matrix.m33);
    return result;
}