Search in sources :

Example 6 with FloatBuffer

use of java.nio.FloatBuffer in project Rajawali by Rajawali.

the class BoundingBox method calculateBounds.

public void calculateBounds(Geometry3D geometry) {
    mMin.setAll(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
    mMax.setAll(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
    FloatBuffer vertices = geometry.getVertices();
    if (vertices != null) {
        calculateMinMaxVertices(vertices, mMin, mMax);
        calculatePoints();
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 7 with FloatBuffer

use of java.nio.FloatBuffer in project Rajawali by Rajawali.

the class BoundingSphere method calculateBounds.

public void calculateBounds(Geometry3D geometry) {
    double radius = 0, maxRadius = 0;
    Vector3 vertex = new Vector3();
    FloatBuffer vertices = geometry.getVertices();
    vertices.rewind();
    while (vertices.hasRemaining()) {
        vertex.x = vertices.get();
        vertex.y = vertices.get();
        vertex.z = vertices.get();
        radius = vertex.length();
        if (radius > maxRadius)
            maxRadius = radius;
    }
    mRadius = maxRadius;
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) FloatBuffer(java.nio.FloatBuffer)

Example 8 with FloatBuffer

use of java.nio.FloatBuffer in project Rajawali by Rajawali.

the class DebugBoundingBox method updateBox.

private void updateBox(BoundingBox bb) {
    FloatBuffer b = mGeometry.getVertices();
    int index = 0;
    bb.copyPoints(mBBoxVertices);
    addVertexToBuffer(b, index++, mBBoxVertices[0]);
    addVertexToBuffer(b, index++, mBBoxVertices[1]);
    addVertexToBuffer(b, index++, mBBoxVertices[2]);
    addVertexToBuffer(b, index++, mBBoxVertices[3]);
    addVertexToBuffer(b, index++, mBBoxVertices[0]);
    addVertexToBuffer(b, index++, mBBoxVertices[4]);
    addVertexToBuffer(b, index++, mBBoxVertices[5]);
    addVertexToBuffer(b, index++, mBBoxVertices[1]);
    addVertexToBuffer(b, index++, mBBoxVertices[5]);
    addVertexToBuffer(b, index++, mBBoxVertices[6]);
    addVertexToBuffer(b, index++, mBBoxVertices[2]);
    addVertexToBuffer(b, index++, mBBoxVertices[6]);
    addVertexToBuffer(b, index++, mBBoxVertices[7]);
    addVertexToBuffer(b, index++, mBBoxVertices[3]);
    addVertexToBuffer(b, index++, mBBoxVertices[7]);
    addVertexToBuffer(b, index++, mBBoxVertices[4]);
    mGeometry.changeBufferData(mGeometry.getVertexBufferInfo(), mGeometry.getVertices(), 0);
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 9 with FloatBuffer

use of java.nio.FloatBuffer in project Rajawali by Rajawali.

the class DebugCamera method updateFrustum.

public void updateFrustum() {
    mCamera.setProjectionMatrix(mRenderer.getOverrideViewportWidth(), mRenderer.getOverrideViewportHeight());
    if (mPoints == null) {
        if (!mCamera.isInitialized()) {
            return;
        }
        mPoints = new Stack<>();
        mFrustumCornersTransformed = new Vector3[8];
        for (int i = 0; i < 16; i++) {
            if (i < 8)
                mFrustumCornersTransformed[i] = new Vector3();
            mPoints.push(new Vector3());
        }
        init(true);
        getGeometry().changeBufferUsage(mGeometry.getVertexBufferInfo(), GLES20.GL_DYNAMIC_DRAW);
        setMaterial(mMaterial);
    }
    mCamera.getFrustumCorners(mFrustumCornersTransformed, true, true);
    FloatBuffer b = mGeometry.getVertices();
    int index = 0;
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[0]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[1]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[2]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[3]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[0]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[4]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[5]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[1]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[5]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[6]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[2]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[6]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[7]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[3]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[7]);
    addVertexToBuffer(b, index++, mFrustumCornersTransformed[4]);
    mGeometry.changeBufferData(mGeometry.getVertexBufferInfo(), mGeometry.getVertices(), 0);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) FloatBuffer(java.nio.FloatBuffer)

Example 10 with FloatBuffer

use of java.nio.FloatBuffer in project Horizon by Yalantis.

the class Buffers method makeInterleavedBuffer.

public static FloatBuffer makeInterleavedBuffer(float[] tData, int triangles) {
    int dataLength = tData.length;
    final FloatBuffer interleavedBuffer = ByteBuffer.allocateDirect(dataLength * Const.BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
    int tOffset = 0;
    for (int i = 0; i < triangles; i++) {
        for (int j = 0; j < Const.POINTS_PER_TRIANGLE; j++) {
            /**
                 * This doesn't seem to do make much sense for one array, but we might need to scale it up
                 */
            interleavedBuffer.put(tData, tOffset, Const.T_DATA_SIZE);
            tOffset += Const.T_DATA_SIZE;
        }
    }
    interleavedBuffer.position(0);
    return interleavedBuffer;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Aggregations

FloatBuffer (java.nio.FloatBuffer)287 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