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