diff options
author | Sven Gothel <[email protected]> | 2012-11-12 06:40:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-11-12 06:40:22 +0100 |
commit | 3859f4577524bd3302631272579183adbc92f5c2 (patch) | |
tree | 4dfbc4f4327de7d459442f84b20618e21316e264 /src/jogl/classes/com/jogamp | |
parent | 5f0aa6b2d1a2af6a0c7c23ac0c00bfde06fafe4c (diff) |
Frustum: Clarify isOutside(AABBox) impl, add isOutside for point and sphere
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java b/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java index 1b732e51b..fd370dfba 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java @@ -225,7 +225,7 @@ public class Frustum { } } - private static final boolean quickClassify(Plane p, AABBox box) { + private static final boolean isOutsideImpl(Plane p, AABBox box) { final float[] low = box.getLow(); final float[] high = box.getHigh(); @@ -237,20 +237,20 @@ public class Frustum { p.distanceTo(high[0], low[1], high[2]) > 0.0f || p.distanceTo(low[0], high[1], high[2]) > 0.0f || p.distanceTo(high[0], high[1], high[2]) > 0.0f ) { - return true; + return false; } - return false; + return true; } /** - * Quick check to see if an orthogonal bounding box is completly outside of the frustum. + * Check to see if an orthogonal bounding box is completly outside of the frustum. * <p> - * Note: If method returns false, the box may be only partially inside. + * Note: If method returns false, the box may only be partially inside. * </p> */ public final boolean isOutside(AABBox box) { for (int i = 0; i < 6; ++i) { - if (!quickClassify(planes[i], box)) { + if ( isOutsideImpl(planes[i], box) ) { // fully outside return true; } @@ -259,6 +259,43 @@ public class Frustum { return false; } + + /** + * Check to see if a point is outside of the frustum. + */ + public final boolean isOutside(float[] p) { + for (int i = 0; i < 6; ++i) { + if ( planes[i].distanceTo(p) < 0.0f ) { + // outside + return true; + } + } + // inside + return false; + } + + /** + * Check to see if a sphere is outside, intersecting or inside of the frustum. + * + * @param p center of the sphere + * @param radius radius of the sphere + * @return 1 if outside, -1 if intersects, 0 if inside + */ + public final int isOutside(float[] p, float radius) { + for (int i = 0; i < 6; ++i) { + final float d = planes[i].distanceTo(p); + if ( d > radius ) { + // fully outside + return 1; + } else if (d < radius ) { + // intersecting + return -1; + } + } + // fully inside + return 0; + } + public StringBuilder toString(StringBuilder sb) { if( null == sb ) { sb = new StringBuilder(); |