From 1f297402b5cf6d0be8d2d852ee6704680984c35b Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * Implementation of the world-frustum planes follows the following paper:
+ * Extracting the world-frustum planes from the P*Mv:
*
* Use one of the
* Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
* Gil Gribb
+ * Classifying Point, Sphere and AABBox:
+ *
+ * Efficient View Frustum Culling
+ * Daniel Sýkora
+ *
+ * Lighthouse3d.com
+ * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
+ *
+ *
* Fundamentals about Planes, Half-Spaces and Frustum-Culling:
*
* Planes and Half-Spaces, Max Wagner
update(..)
methods to set the {@link #getPlanes() planes}.
* src
planes into this this instance's planes.
* @param src the 6 source planes
*/
- public final void update(Plane[] src) {
+ public final void updateByPlanes(Plane[] src) {
for (int i = 0; i < 6; ++i) {
final Plane p0 = planes[i];
final float[] p0_n = p0.n;
@@ -170,7 +185,7 @@ public class Frustum {
* as required by this class.
*
* Note: If method returns false, the box may only be partially inside. *
*/ - public final boolean isOutside(AABBox box) { + public final boolean isAABBoxOutside(AABBox box) { for (int i = 0; i < 6; ++i) { if ( isOutsideImpl(planes[i], box) ) { // fully outside @@ -285,18 +300,36 @@ public class Frustum { } + public static enum Location { OUTSIDE, INSIDE, INTERSECT }; + /** - * Check to see if a point is outside of the frustum. + * Check to see if a point is outside, inside or on a plane of the frustum. + * + * @param p the point + * @return {@link Location} of point related to frustum planes */ - public final boolean isOutside(float[] p) { + public final Location classifyPoint(float[] p) { + Location res = Location.INSIDE; + for (int i = 0; i < 6; ++i) { - if ( planes[i].distanceTo(p) < 0.0f ) { - // outside - return true; + final float d = planes[i].distanceTo(p); + if ( d < 0.0f ) { + return Location.OUTSIDE; + } else if ( d == 0.0f ) { + res = Location.INTERSECT; } } - // inside - return false; + return res; + } + + /** + * Check to see if a point is outside of the frustum. + * + * @param p the point + * @return true if outside of the frustum, otherwise inside or on a plane + */ + public final boolean isPointOutside(float[] p) { + return Location.OUTSIDE == classifyPoint(p); } /** @@ -304,21 +337,33 @@ public class Frustum { * * @param p center of the sphere * @param radius radius of the sphere - * @return 1 if outside, -1 if intersects, 0 if inside + * @return {@link Location} of point related to frustum planes */ - public final int isOutside(float[] p, float radius) { + public final Location classifySphere(float[] p, float radius) { + Location res = Location.INSIDE; // fully inside + for (int i = 0; i < 6; ++i) { final float d = planes[i].distanceTo(p); - if ( d > radius ) { + if ( d < -radius ) { // fully outside - return 1; + return Location.OUTSIDE; } else if (d < radius ) { // intersecting - return -1; + res = Location.INTERSECT; } - } - // fully inside - return 0; + } + return res; + } + + /** + * Check to see if a sphere is outside of the frustum. + * + * @param p center of the sphere + * @param radius radius of the sphere + * @return true if outside of the frustum, otherwise inside or intersecting + */ + public final boolean isSphereOutside(float[] p, float radius) { + return Location.OUTSIDE == classifySphere(p, radius); } public StringBuilder toString(StringBuilder sb) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java index 18129ba09..0d76151be 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -1043,7 +1043,7 @@ public class PMVMatrix implements GLMatrixFunc { mulPMV = new float[16]; } FloatUtil.multMatrixf(matrixP, matrixMv, mulPMV, 0); - frustum.update(mulPMV, 0); + frustum.updateByPMV(mulPMV, 0); dirtyBits &= ~DIRTY_FRUSTUM; mod = true; } -- cgit v1.2.3