Search in sources :

Example 91 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 92 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 93 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 94 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 95 with FloatBuffer

use of java.nio.FloatBuffer in project android_frameworks_base by ParanoidAndroid.

the class GLLogWrapper method doArrayElement.

private void doArrayElement(StringBuilder builder, boolean enabled, String name, PointerInfo pointer, int index) {
    if (!enabled) {
        return;
    }
    builder.append(" ");
    builder.append(name + ":{");
    if (pointer == null || pointer.mTempByteBuffer == null) {
        builder.append("undefined }");
        return;
    }
    if (pointer.mStride < 0) {
        builder.append("invalid stride");
        return;
    }
    int stride = pointer.getStride();
    ByteBuffer byteBuffer = pointer.mTempByteBuffer;
    int size = pointer.mSize;
    int type = pointer.mType;
    int sizeofType = pointer.sizeof(type);
    int byteOffset = stride * index;
    for (int i = 0; i < size; i++) {
        if (i > 0) {
            builder.append(", ");
        }
        switch(type) {
            case GL_BYTE:
                {
                    byte d = byteBuffer.get(byteOffset);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_UNSIGNED_BYTE:
                {
                    byte d = byteBuffer.get(byteOffset);
                    builder.append(Integer.toString(0xff & d));
                }
                break;
            case GL_SHORT:
                {
                    ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
                    short d = shortBuffer.get(byteOffset / 2);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_FIXED:
                {
                    IntBuffer intBuffer = byteBuffer.asIntBuffer();
                    int d = intBuffer.get(byteOffset / 4);
                    builder.append(Integer.toString(d));
                }
                break;
            case GL_FLOAT:
                {
                    FloatBuffer intBuffer = byteBuffer.asFloatBuffer();
                    float d = intBuffer.get(byteOffset / 4);
                    builder.append(Float.toString(d));
                }
                break;
            default:
                builder.append("?");
                break;
        }
        byteOffset += sizeofType;
    }
    builder.append("}");
}
Also used : IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

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