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; }
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; } }
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; }