BoundingBox lightBox = new BoundingBox(mFrustumCorners); double distance = mFrustumCentroid.distanceTo(lightBox.getMin()); Vector3 lightDirection = light.getDirectionVector().clone(); lightDirection.normalize(); mFrustumCorners[i].multiply(mLightViewMatrix); BoundingBox b = new BoundingBox(mFrustumCorners); mLightProjectionMatrix.setToOrthographic(b.getMin().x, b.getMax().x, b.getMin().y, b.getMax().y, -b.getMax().z, -b.getMin().z);
public BoundingBox(Geometry3D geometry) { this(); mGeometry = geometry; calculateBounds(mGeometry); }
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(); } }
public boolean contains(IBoundingVolume boundingVolume) { if(!(boundingVolume instanceof BoundingBox)) return false; BoundingBox boundingBox = (BoundingBox)boundingVolume; Vector3 otherMin = boundingBox.getTransformedMin(); Vector3 otherMax = boundingBox.getTransformedMax(); Vector3 min = mTransformedMin; Vector3 max = mTransformedMax; return (max.x >= otherMax.x) && (min.x <= otherMin.x) && (max.y >= otherMax.y) && (min.y <= otherMin.y) && (max.z >= otherMax.z) && (min.z <= otherMin.z); }
public boolean boundsInFrustum(BoundingBox bounds) { for(int i=0; i<6; i++) { Plane p = mPlanes[i]; mPoint1.x = p.getNormal().x > 0 ? bounds.getMin().x : bounds.getMax().x; mPoint2.x = p.getNormal().x > 0 ? bounds.getMax().x : bounds.getMin().x; mPoint1.y = p.getNormal().y > 0 ? bounds.getMin().y : bounds.getMax().y; mPoint2.y = p.getNormal().y > 0 ? bounds.getMax().y : bounds.getMin().y; mPoint1.z = p.getNormal().z > 0 ? bounds.getMin().z : bounds.getMax().z; mPoint2.z = p.getNormal().z > 0 ? bounds.getMax().z : bounds.getMin().z; double distance1 = p.getDistanceTo(mPoint1); double distance2 = p.getDistanceTo(mPoint2); if ( distance1 < 0 && distance2 < 0 ) return false; } return true; }
/** * Gets the bounding box for this geometry. If there is no current bounding * box it will be calculated. * * @return */ public BoundingBox getBoundingBox() { if (mBoundingBox == null) { mBoundingBox = new BoundingBox(this); } return mBoundingBox; }
bbox.calculateBounds(o.getGeometry()); bbox.transform(o.getModelMatrix());
getBoundingBox().transform(getModelMatrix()); getBoundingBox().drawBoundingVolume(camera, vpMatrix, projMatrix, vMatrix, mMMatrix);
public BoundingBox(Vector3 min, Vector3 max) { this(); mMin.setAll(min.x, min.y, min.z); mMax.setAll(max.x, max.y, max.z); calculatePoints(); }
/** * The reload method is called whenever the OpenGL context needs to be re-created. When the OpenGL context was lost, * the vertex, uv coord, index etc data needs to be re-uploaded. */ public void reload() { if (!mIsContainerOnly) { mGeometry.reload(); } for (int i = 0, j = mChildren.size(); i < j; i++) { mChildren.get(i).reload(); } if (mGeometry.hasBoundingBox() && getBoundingBox().getVisual() != null) { getBoundingBox().getVisual().reload(); } if (mGeometry.hasBoundingSphere() && mGeometry.getBoundingSphere().getVisual() != null) { mGeometry.getBoundingSphere().getVisual().reload(); } }
public boolean isContainedBy(IBoundingVolume boundingVolume) { if(!(boundingVolume instanceof BoundingBox)) return false; BoundingBox boundingBox = (BoundingBox)boundingVolume; Vector3 otherMin = boundingBox.getTransformedMin(); Vector3 otherMax = boundingBox.getTransformedMax(); Vector3 min = mTransformedMin; Vector3 max = mTransformedMax; return (max.x <= otherMax.x) && (min.x >= otherMin.x) && (max.y <= otherMax.y) && (min.y >= otherMin.y) && (max.z <= otherMax.z) && (min.z >= otherMin.z); }
public SkeletalAnimationFrame() { mBounds = new BoundingBox(); mSkeleton = new Skeleton(); }
private void updateMaxMinCoords(Vector3 min, Vector3 max, Object3D child) { Vector3 maxVertex = child.getBoundingBox().getMax(); if (maxVertex.x > max.x) { max.x = maxVertex.x; } if (maxVertex.y > max.y) { max.y = maxVertex.y; } if (maxVertex.z > max.z) { max.z = maxVertex.z; } Vector3 minVertex = child.getBoundingBox().getMin(); if (minVertex.x < min.x) { min.x = minVertex.x; } if (minVertex.y < min.y) { min.y = minVertex.y; } if (minVertex.z < min.z) { min.z = minVertex.z; } }
bbox.calculateBounds(o.getGeometry()); bbox.transform(o.getModelMatrix());
if (mGeometry.hasBoundingBox()) mGeometry.getBoundingBox().transform(getModelMatrix()); if (mGeometry.hasBoundingSphere()) mGeometry.getBoundingSphere().transform(getModelMatrix()); mGeometry.getBoundingBox().drawBoundingVolume(camera, vpMatrix, projMatrix, vMatrix, mMMatrix); if (mGeometry.hasBoundingSphere()) mGeometry.getBoundingSphere().drawBoundingVolume(camera, vpMatrix, projMatrix, vMatrix, mMMatrix);
public void calculateBounds(Geometry3D geometry) { FloatBuffer vertices = geometry.getVertices(); vertices.rewind(); mMin.setAll(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); mMax.setAll(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); Vector3 vertex = new Vector3(); while (vertices.hasRemaining()) { vertex.x = vertices.get(); vertex.y = vertices.get(); vertex.z = vertices.get(); if (vertex.x < mMin.x) mMin.x = vertex.x; if (vertex.y < mMin.y) mMin.y = vertex.y; if (vertex.z < mMin.z) mMin.z = vertex.z; if (vertex.x > mMax.x) mMax.x = vertex.x; if (vertex.y > mMax.y) mMax.y = vertex.y; if (vertex.z > mMax.z) mMax.z = vertex.z; } calculatePoints(); }
/** * The reload method is called whenever the OpenGL context needs to be re-created. When the OpenGL context was lost, * the vertex, uv coord, index etc data needs to be re-uploaded. */ public void reload() { if (!mIsContainerOnly) { mGeometry.reload(); } for (int i = 0, j = mChildren.size(); i < j; i++) mChildren.get(i).reload(); if (mGeometry.hasBoundingBox() && mGeometry.getBoundingBox().getVisual() != null) mGeometry.getBoundingBox().getVisual().reload(); if (mGeometry.hasBoundingSphere() && mGeometry.getBoundingSphere().getVisual() != null) mGeometry.getBoundingSphere().getVisual().reload(); }
public boolean intersectsWith(IBoundingVolume boundingVolume) { if (!(boundingVolume instanceof BoundingBox)) { return false; } BoundingBox boundingBox = (BoundingBox) boundingVolume; Vector3 otherMin = boundingBox.getTransformedMin(); Vector3 otherMax = boundingBox.getTransformedMax(); Vector3 min = mTransformedMin; Vector3 max = mTransformedMax; return (min.x < otherMax.x) && (max.x > otherMin.x) && (min.y < otherMax.y) && (max.y > otherMin.y) && (min.z < otherMax.z) && (max.z > otherMin.z); }