From 3859f4577524bd3302631272579183adbc92f5c2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 12 Nov 2012 06:40:22 +0100 Subject: Frustum: Clarify isOutside(AABBox) impl, add isOutside for point and sphere --- .../com/jogamp/opengl/math/geom/Frustum.java | 49 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl') 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. *

- * Note: If method returns false, the box may be only partially inside. + * Note: If method returns false, the box may only be partially inside. *

*/ 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(); -- cgit v1.2.3