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();
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations