JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
Frustum.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.math.geom;
29
30import com.jogamp.math.FovHVHalves;
31import com.jogamp.math.Matrix4f;
32import com.jogamp.math.Vec3f;
33import com.jogamp.math.Vec4f;
34
35/**
36 * Providing frustum {@link #getPlanes() planes} derived by different inputs
37 * ({@link #updateFrustumPlanes(float[], int) P*MV}, ..) used to classify objects
38 * <ul>
39 * <li> {@link #classifyPoint(Vec3f) point} </li>
40 * <li> {@link #classifySphere(Vec3f, float) sphere} </li>
41 * </ul>
42 * and to test whether they are outside
43 * <ul>
44 * <li> {@link #isOutside(Vec3f) point} </li>
45 * <li> {@link #isSphereOutside(Vec3f, float) sphere} </li>
46 * <li> {@link #isOutside(AABBox) bounding-box} </li>
47 * <li> {@link #isOutside(Cube) cube} </li>
48 * </ul>
49 *
50 * <p>
51 * Extracting the world-frustum planes from the P*Mv:
52 * <pre>
53 * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
54 * Gil Gribb <ggribb@ravensoft.com>
55 * Klaus Hartmann <k_hartmann@osnabrueck.netsurf.de>
56 * http://graphics.cs.ucf.edu/cap4720/fall2008/plane_extraction.pdf
57 * </pre>
58 * Classifying Point, Sphere and AABBox:
59 * <pre>
60 * Efficient View Frustum Culling
61 * Daniel Sýkora <sykorad@fel.cvut.cz>
62 * Josef Jelínek <jelinej1@fel.cvut.cz>
63 * http://www.cg.tuwien.ac.at/hostings/cescg/CESCG-2002/DSykoraJJelinek/index.html
64 * </pre>
65 * <pre>
66 * Lighthouse3d.com
67 * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
68 * </pre>
69 *
70 * Fundamentals about Planes, Half-Spaces and Frustum-Culling:<br/>
71 * <pre>
72 * Planes and Half-Spaces, Max Wagner <mwagner@digipen.edu>
73 * http://www.emeyex.com/site/tuts/PlanesHalfSpaces.pdf
74 * </pre>
75 * <pre>
76 * Frustum Culling, Max Wagner <mwagner@digipen.edu>
77 * http://www.emeyex.com/site/tuts/FrustumCulling.pdf
78 * </pre>
79 * </p>
80 */
81public final class Frustum {
82 /**
83 * {@link Frustum} description by {@link #fovhv} and {@link #zNear}, {@link #zFar}.
84 */
85 public static class FovDesc {
86 /** Field of view in both directions, may not be centered, either {@link FovHVHalves#inTangents} or radians. */
87 public final FovHVHalves fovhv;
88 /** Near Z */
89 public final float zNear;
90 /** Far Z */
91 public final float zFar;
92 /**
93 * @param fovhv field of view in both directions, may not be centered, either {@link FovHVHalves#inTangents} or radians
94 * @param zNear
95 * @param zFar
96 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}.
97 */
98 public FovDesc(final FovHVHalves fovhv, final float zNear, final float zFar) throws IllegalArgumentException {
99 if( zNear <= 0.0f || zFar <= zNear ) {
100 throw new IllegalArgumentException("Requirements zNear > 0 and zFar > zNear, but zNear "+zNear+", zFar "+zFar);
101 }
102 this.fovhv = fovhv;
103 this.zNear = zNear;
104 this.zFar = zFar;
105 }
106 @Override
107 public final String toString() {
108 return "FrustumFovDesc["+fovhv.toStringInDegrees()+", Z["+zNear+" - "+zFar+"]]";
109 }
110 }
111
112 /** Normalized planes[l, r, b, t, n, f] */
113 protected final Plane[] planes = new Plane[6];
114
115 /**
116 * Creates an undefined instance w/o calculating the frustum.
117 * <p>
118 * Use one of the <code>update(..)</code> methods to set the {@link #getPlanes() planes}.
119 * </p>
120 * @see #updateByPlanes(Plane[])
121 * @see #updateFrustumPlanes(float[], int)
122 */
123 public Frustum() {
124 planes[LEFT ] = new Plane();
125 planes[RIGHT ] = new Plane();
126 planes[BOTTOM] = new Plane();
127 planes[TOP ] = new Plane();
128 planes[NEAR ] = new Plane();
129 planes[FAR ] = new Plane();
130 }
131
132 public Frustum(final Frustum o) {
133 planes[LEFT ] = new Plane(o.planes[LEFT]);
134 planes[RIGHT ] = new Plane(o.planes[RIGHT]);
135 planes[BOTTOM] = new Plane(o.planes[BOTTOM]);
136 planes[TOP ] = new Plane(o.planes[TOP]);
137 planes[NEAR ] = new Plane(o.planes[NEAR]);
138 planes[FAR ] = new Plane(o.planes[FAR]);
139 }
140
141 public Frustum set(final Frustum o) {
142 planes[LEFT ].set(o.planes[LEFT]);
143 planes[RIGHT ].set(o.planes[RIGHT]);
144 planes[BOTTOM].set(o.planes[BOTTOM]);
145 planes[TOP ].set(o.planes[TOP]);
146 planes[NEAR ].set(o.planes[NEAR]);
147 planes[FAR ].set(o.planes[FAR]);
148 return this;
149 }
150
151 /**
152 * Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0
153 * <p>
154 * In order to work w/ {@link Frustum#isOutside(AABBox) isOutside(..)} methods,
155 * the normals have to point to the inside of the frustum.
156 * </p>
157 */
158 public static class Plane {
159 /** Normal of the plane */
160 public final Vec3f n;
161
162 /** Distance to origin */
163 public float d;
164
165 public Plane() {
166 n = new Vec3f();
167 d = 0f;
168 }
169
170 public Plane(final Plane o) {
171 n = new Vec3f(o.n);
172 d = o.d;
173 }
174
175 public Plane set(final Plane o) {
176 n.set(o.n);
177 d = o.d;
178 return this;
179 }
180
181 /**
182 * Setup of plane using 3 points. None of the three points are mutated.
183 * <p>
184 * Since this method may not properly define whether the normal points inside the frustum,
185 * consider using {@link #set(Vec3f, Vec3f)}.
186 * </p>
187 * @param p0 point on plane, used as the shared start-point for vec(p0->p1) and vec(p0->p2)
188 * @param p1 point on plane
189 * @param p2 point on plane
190 * @return this plane for chaining
191 */
192 public Plane set(final Vec3f p0, final Vec3f p1, final Vec3f p2) {
193 final Vec3f v = p1.minus(p0);
194 final Vec3f u = p2.minus(p0);
195 n.cross(v, u).normalize();
196 d = n.copy().scale(-1).dot(p0);
197 return this;
198 }
199
200 /**
201 * Setup of plane using given normal and one point on plane. The given normal is mutated, the point not mutated.
202 * @param n normal to plane pointing to the inside of this frustum
203 * @param p0 point on plane, consider choosing the closest point to origin
204 * @return this plane for chaining
205 */
206 public Plane set(final Vec3f n, final Vec3f p0) {
207 this.n.set(n);
208 d = n.scale(-1).dot(p0);
209 return this;
210 }
211
212 /** Sets the given {@link Vec4f} {@code out} to {@code ( n, d )}. Returns {@code out} for chaining. */
213 public Vec4f toVec4f(final Vec4f out) {
214 out.set(n, d);
215 return out;
216 }
217
218 /**
219 * Sets the given {@code [float[off]..float[off+4])} {@code out} to {@code ( n, d )}.
220 * @param out the {@code float[off+4]} output array
221 */
222 public void toFloats(final float[/* off+4] */] out, final int off) {
223 out[off+0] = n.x();
224 out[off+1] = n.y();
225 out[off+2] = n.z();
226 out[off+3] = d;
227 }
228
229 /**
230 * Return signed distance of plane to given point.
231 * <ul>
232 * <li>If dist &lt; 0 , then the point p lies in the negative halfspace.</li>
233 * <li>If dist = 0 , then the point p lies in the plane.</li>
234 * <li>If dist &gt; 0 , then the point p lies in the positive halfspace.</li>
235 * </ul>
236 * A plane cuts 3D space into 2 half spaces.
237 * <p>
238 * Positive halfspace is where the plane’s normals vector points into.
239 * </p>
240 * <p>
241 * Negative halfspace is the <i>other side</i> of the plane, i.e. *-1
242 * </p>
243 **/
244 public final float distanceTo(final float x, final float y, final float z) {
245 return n.x() * x + n.y() * y + n.z() * z + d;
246 }
247
248 /** Return distance of plane to given point, see {@link #distanceTo(float, float, float)}. */
249 public final float distanceTo(final Vec3f p) {
250 return n.dot(p) + d;
251 }
252
253 @Override
254 public String toString() {
255 return "Plane[ [ " + n + " ], " + d + "]";
256 }
257 }
258
259 /** Index for left plane: {@value} */
260 public static final int LEFT = 0;
261 /** Index for right plane: {@value} */
262 public static final int RIGHT = 1;
263 /** Index for bottom plane: {@value} */
264 public static final int BOTTOM = 2;
265 /** Index for top plane: {@value} */
266 public static final int TOP = 3;
267 /** Index for near plane: {@value} */
268 public static final int NEAR = 4;
269 /** Index for far plane: {@value} */
270 public static final int FAR = 5;
271
272 /**
273 * {@link Plane}s are ordered in the returned array as follows:
274 * <ul>
275 * <li>{@link #LEFT}</li>
276 * <li>{@link #RIGHT}</li>
277 * <li>{@link #BOTTOM}</li>
278 * <li>{@link #TOP}</li>
279 * <li>{@link #NEAR}</li>
280 * <li>{@link #FAR}</li>
281 * </ul>
282 * <p>
283 * {@link Plane}'s normals are pointing to the inside of the frustum
284 * in order to work w/ {@link #isOutside(AABBox) isOutside(..)} methods.
285 * </p>
286 *
287 * @return array of normalized {@link Plane}s, order see above.
288 */
289 public final Plane[] getPlanes() { return planes; }
290
291 /**
292 * Sets each of the given {@link Vec4f}[6] {@code out} to {@link Plane#toVec4f(Vec4f)}
293 * in the order {@link #LEFT}, {@link #RIGHT}, {@link #BOTTOM}, {@link #TOP}, {@link #NEAR}, {@link #FAR}.
294 * @param out the {@link Vec4f}[6] output array
295 * @return {@code out} for chaining
296 */
297 public Vec4f[] getPlanes(final Vec4f[] out) {
298 planes[LEFT ].toVec4f(out[0]);
299 planes[RIGHT ].toVec4f(out[1]);
300 planes[BOTTOM].toVec4f(out[2]);
301 planes[TOP ].toVec4f(out[3]);
302 planes[NEAR ].toVec4f(out[4]);
303 planes[FAR ].toVec4f(out[5]);
304 return out;
305 }
306
307 /** Sets the given {@code [float[off]..float[off+4*6])} {@code out} to {@code ( n, d )}. */
308 /**
309 * Sets each of the given {@code [float[off]..float[off+4*6])} {@code out} to {@link Plane#toFloats(float[], int)},
310 * i.e. [n.x, n.y, n.z, d, ...].
311 * <p>
312 * Plane order is as follows: {@link #LEFT}, {@link #RIGHT}, {@link #BOTTOM}, {@link #TOP}, {@link #NEAR}, {@link #FAR}.
313 * </p>
314 * @param out the {@code float[off+4*6]} output array
315 * @return {@code out} for chaining
316 */
317 public void getPlanes(final float[/* off+4*6] */] out, final int off) {
318 planes[LEFT ].toFloats(out, off+4*0);
319 planes[RIGHT ].toFloats(out, off+4*1);
320 planes[BOTTOM].toFloats(out, off+4*2);
321 planes[TOP ].toFloats(out, off+4*3);
322 planes[NEAR ].toFloats(out, off+4*4);
323 planes[FAR ].toFloats(out, off+4*5);
324 }
325
326 /**
327 * Copy the given <code>src</code> planes into this this instance's planes.
328 * @param src the 6 source planes
329 */
330 public final void updateByPlanes(final Plane[] src) {
331 for (int i = 0; i < 6; ++i) {
332 final Plane pD = planes[i];
333 final Plane pS = src[i];
334 pD.d = pS.d;
335 System.arraycopy(pS.n, 0, pD.n, 0, 3);
336 }
337 }
338
339 /**
340 * Calculate the frustum planes in world coordinates
341 * using the passed {@link FovDesc}.
342 * <p>
343 * Operation Details:
344 * <ul>
345 * <li>The given {@link FovDesc} will be transformed
346 * into the given perspective matrix (column major order) first,
347 * see {@link Matrix4f#setToPerspective(FovHVHalves, float, float)}.</li>
348 * <li>Then the perspective matrix is used to {@link Matrix4f#getFrustum(Frustum)} this instance.</li>
349 * </ul>
350 * </p>
351 * <p>
352 * Frustum plane's normals will point to the inside of the viewing frustum,
353 * as required by this class.
354 * </p>
355 *
356 * @param m 4x4 matrix in column-major order (also result)
357 * @param fovDesc {@link Frustum} {@link FovDesc}
358 * @return given matrix for chaining
359 * @see Matrix4f#setToPerspective(FovHVHalves, float, float)
360 * @see Matrix4f#getFrustum(Frustum)
361 * @see Matrix4f#getFrustum(Frustum, FovDesc)
362 */
363 public Matrix4f updateByFovDesc(final Matrix4f m, final FovDesc fovDesc) {
364 m.setToPerspective(fovDesc.fovhv, fovDesc.zNear, fovDesc.zFar);
365 setFromMat(m);
366 return m;
367 }
368
369 /**
370 * Calculate the frustum planes in world coordinates
371 * using the passed column major order matrix, usually a projection (P) or premultiplied P*MV matrix.
372 * <p>
373 * Frustum plane's normals will point to the inside of the viewing frustum,
374 * as required by this class.
375 * </p>
376 * @see Matrix4f#getFrustum(Frustum)
377 */
378 public Frustum setFromMat(final Matrix4f pmv) {
379 return pmv.getFrustum(this);
380 }
381
382 /**
383 * Calculate the frustum planes using the given {@link Cube}.
384 * <p>
385 * One useful application is to {@link Cube#transform(Matrix4f) transform}
386 * an {@link AABBox}, see {@link Cube#Cube(AABBox)} from its object-space
387 * into model-view (Mv) and produce the {@link Frustum} planes using this method
388 * for CPU side object culling and GPU shader side fragment clipping.
389 * </p>
390 * <p>
391 * Frustum plane's normals will point to the inside of the viewing frustum,
392 * as required by this class.
393 * </p>
394 * @param c the {@link Cube} source
395 * @return this frustum for chaining
396 * @see Cube#updateFrustumPlanes(Frustum)
397 * @see Cube#Cube(AABBox)
398 * @see Cube#transform(Matrix4f)
399 */
401 return c.updateFrustumPlanes(this);
402 }
403
404 private static final boolean intersects(final Plane p, final AABBox box) {
405 final Vec3f lo = box.getLow();
406 final Vec3f hi = box.getHigh();
407
408 return p.distanceTo(lo.x(), lo.y(), lo.z()) > 0.0f ||
409 p.distanceTo(hi.x(), lo.y(), lo.z()) > 0.0f ||
410 p.distanceTo(lo.x(), hi.y(), lo.z()) > 0.0f ||
411 p.distanceTo(hi.x(), hi.y(), lo.z()) > 0.0f ||
412 p.distanceTo(lo.x(), lo.y(), hi.z()) > 0.0f ||
413 p.distanceTo(hi.x(), lo.y(), hi.z()) > 0.0f ||
414 p.distanceTo(lo.x(), hi.y(), hi.z()) > 0.0f ||
415 p.distanceTo(hi.x(), hi.y(), hi.z()) > 0.0f;
416 }
417
418 /**
419 * Returns whether the given {@link AABBox} is completely outside of this frustum.
420 * <p>
421 * Note: If method returns false, the box may only be partially inside, i.e. intersects with this frustum
422 * </p>
423 */
424 public final boolean isOutside(final AABBox box) {
425 return !intersects(planes[0], box) ||
426 !intersects(planes[1], box) ||
427 !intersects(planes[2], box) ||
428 !intersects(planes[3], box) ||
429 !intersects(planes[4], box) ||
430 !intersects(planes[5], box);
431 }
432
433 private static final boolean intersects(final Plane p, final Cube c) {
434 return p.distanceTo(c.lbf) > 0.0f ||
435 p.distanceTo(c.rbf) > 0.0f ||
436 p.distanceTo(c.rtf) > 0.0f ||
437 p.distanceTo(c.ltf) > 0.0f ||
438 p.distanceTo(c.lbn) > 0.0f ||
439 p.distanceTo(c.rbn) > 0.0f ||
440 p.distanceTo(c.rtn) > 0.0f ||
441 p.distanceTo(c.ltn) > 0.0f;
442 }
443
444 /**
445 * Returns whether the given {@link Cube} is completely outside of this frustum.
446 * <p>
447 * Note: If method returns false, the box may only be partially inside, i.e. intersects with this frustum
448 * </p>
449 */
450 public final boolean isOutside(final Cube c) {
451 return !intersects(planes[0], c) ||
452 !intersects(planes[1], c) ||
453 !intersects(planes[2], c) ||
454 !intersects(planes[3], c) ||
455 !intersects(planes[4], c) ||
456 !intersects(planes[5], c);
457 }
458
459
460 public static enum Location { OUTSIDE, INSIDE, INTERSECT };
461
462 /**
463 * Classifies the given {@link Vec3f} point whether it is outside, inside or on a plane of this frustum.
464 *
465 * @param p the point
466 * @return {@link Location} of point related to frustum planes
467 */
468 public final Location classifyPoint(final Vec3f p) {
470
471 for (int i = 0; i < 6; ++i) {
472 final float d = planes[i].distanceTo(p);
473 if ( d < 0.0f ) {
474 return Location.OUTSIDE;
475 } else if ( d == 0.0f ) {
476 res = Location.INTERSECT;
477 }
478 }
479 return res;
480 }
481
482 /**
483 * Returns whether the given {@link Vec3f} point is completely outside of this frustum.
484 *
485 * @param p the point
486 * @return true if outside of the frustum, otherwise inside or on a plane
487 */
488 public final boolean isOutside(final Vec3f p) {
489 return planes[0].distanceTo(p) < 0.0f ||
490 planes[1].distanceTo(p) < 0.0f ||
491 planes[2].distanceTo(p) < 0.0f ||
492 planes[3].distanceTo(p) < 0.0f ||
493 planes[4].distanceTo(p) < 0.0f ||
494 planes[5].distanceTo(p) < 0.0f;
495 }
496
497 /**
498 * Classifies the given sphere whether it is is outside, intersecting or inside of this frustum.
499 *
500 * @param p center of the sphere
501 * @param radius radius of the sphere
502 * @return {@link Location} of point related to frustum planes
503 */
504 public final Location classifySphere(final Vec3f p, final float radius) {
505 Location res = Location.INSIDE; // fully inside
506
507 for (int i = 0; i < 6; ++i) {
508 final float d = planes[i].distanceTo(p);
509 if ( d < -radius ) {
510 // fully outside
511 return Location.OUTSIDE;
512 } else if (d < radius ) {
513 // intersecting
514 res = Location.INTERSECT;
515 }
516 }
517 return res;
518 }
519
520 /**
521 * Returns whether the given sphere is completely outside of this frustum.
522 *
523 * @param p center of the sphere
524 * @param radius radius of the sphere
525 * @return true if outside of the frustum, otherwise inside or intersecting
526 */
527 public final boolean isSphereOutside(final Vec3f p, final float radius) {
528 return Location.OUTSIDE == classifySphere(p, radius);
529 }
530
531 public StringBuilder toString(StringBuilder sb) {
532 if( null == sb ) {
533 sb = new StringBuilder();
534 }
535 sb.append("Frustum[Planes[").append(System.lineSeparator())
536 .append(" L: ").append(planes[0]).append(", ").append(System.lineSeparator())
537 .append(" R: ").append(planes[1]).append(", ").append(System.lineSeparator())
538 .append(" B: ").append(planes[2]).append(", ").append(System.lineSeparator())
539 .append(" T: ").append(planes[3]).append(", ").append(System.lineSeparator())
540 .append(" N: ").append(planes[4]).append(", ").append(System.lineSeparator())
541 .append(" F: ").append(planes[5]).append("], ").append(System.lineSeparator())
542 .append("]");
543 return sb;
544 }
545
546 @Override
547 public String toString() {
548 return toString(null).toString();
549 }
550}
Horizontal and vertical field of view (FOV) halves, allowing a non-centered projection.
final String toStringInDegrees()
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
Definition: Matrix4f.java:89
Frustum getFrustum(final Frustum frustum)
Calculate the frustum planes in world coordinates using this column major order matrix,...
Definition: Matrix4f.java:1340
Matrix4f setToPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Set this matrix to perspective frustum projection.
Definition: Matrix4f.java:1303
3D Vector based upon three float components.
Definition: Vec3f.java:37
Vec3f scale(final float s)
this = this * s, returns this.
Definition: Vec3f.java:218
Vec3f normalize()
Normalize this vector in place.
Definition: Vec3f.java:297
float dot(final Vec3f o)
Return the dot product of this vector and the given one.
Definition: Vec3f.java:338
Vec3f minus(final Vec3f arg)
Returns this - arg; creates new vector.
Definition: Vec3f.java:255
Vec3f cross(final Vec3f arg)
Returns this cross arg; creates new vector.
Definition: Vec3f.java:343
Vec3f set(final Vec3f o)
this = o, returns this.
Definition: Vec3f.java:79
4D Vector based upon four float components.
Definition: Vec4f.java:37
Vec4f set(final Vec4f o)
this = o, returns this.
Definition: Vec4f.java:67
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final Vec3f getHigh()
Returns the maximum right-top-near (xyz) coordinate.
Definition: AABBox.java:131
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
Definition: AABBox.java:140
Simple 8-point Vec3f cube compound having z-far <= z-near @endiliteral.
Definition: Cube.java:48
Frustum updateFrustumPlanes(final Frustum frustum)
Calculate the frustum planes using this Cube.
Definition: Cube.java:194
final Vec3f ltf
left -top -far (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:56
final Vec3f ltn
left -top -near (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:65
final Vec3f rtn
right-top -near (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:63
final Vec3f lbn
left -bottom-near (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:59
final Vec3f rbn
right-bottom-near (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:61
final Vec3f rtf
right-top -far (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:54
final Vec3f rbf
right-bottom-far (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:52
final Vec3f lbf
left -bottom-far (xyz) in AABB case, otherwise arbitrary
Definition: Cube.java:50
Frustum description by fovhv and zNear, zFar.
Definition: Frustum.java:85
final FovHVHalves fovhv
Field of view in both directions, may not be centered, either FovHVHalves#inTangents or radians.
Definition: Frustum.java:87
FovDesc(final FovHVHalves fovhv, final float zNear, final float zFar)
Definition: Frustum.java:98
Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0.
Definition: Frustum.java:158
final float distanceTo(final float x, final float y, final float z)
Return signed distance of plane to given point.
Definition: Frustum.java:244
final Vec3f n
Normal of the plane.
Definition: Frustum.java:160
Vec4f toVec4f(final Vec4f out)
Sets the given Vec4f out to ( n, d ).
Definition: Frustum.java:213
void toFloats(final float[] out, final int off)
Sets the given [float[off]..float[off+4]) out to ( n, d ).
Definition: Frustum.java:222
Plane set(final Plane o)
Definition: Frustum.java:175
float d
Distance to origin.
Definition: Frustum.java:163
final float distanceTo(final Vec3f p)
Return distance of plane to given point, see distanceTo(float, float, float).
Definition: Frustum.java:249
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
Definition: Frustum.java:81
static final int NEAR
Index for near plane: {@value}.
Definition: Frustum.java:268
final Location classifyPoint(final Vec3f p)
Classifies the given Vec3f point whether it is outside, inside or on a plane of this frustum.
Definition: Frustum.java:468
Frustum setFromMat(final Matrix4f pmv)
Calculate the frustum planes in world coordinates using the passed column major order matrix,...
Definition: Frustum.java:378
Matrix4f updateByFovDesc(final Matrix4f m, final FovDesc fovDesc)
Calculate the frustum planes in world coordinates using the passed FovDesc.
Definition: Frustum.java:363
Frustum updateFrustumPlanes(final Cube c)
Calculate the frustum planes using the given Cube.
Definition: Frustum.java:400
final Location classifySphere(final Vec3f p, final float radius)
Classifies the given sphere whether it is is outside, intersecting or inside of this frustum.
Definition: Frustum.java:504
static final int BOTTOM
Index for bottom plane: {@value}.
Definition: Frustum.java:264
final Plane[] getPlanes()
Planes are ordered in the returned array as follows:
Definition: Frustum.java:289
void getPlanes(final float[] out, final int off)
Sets the given [float[off]..float[off+4*6]) out to ( n, d ).
Definition: Frustum.java:317
final boolean isOutside(final AABBox box)
Returns whether the given AABBox is completely outside of this frustum.
Definition: Frustum.java:424
final void updateByPlanes(final Plane[] src)
Copy the given src planes into this this instance's planes.
Definition: Frustum.java:330
final boolean isOutside(final Vec3f p)
Returns whether the given Vec3f point is completely outside of this frustum.
Definition: Frustum.java:488
static final int RIGHT
Index for right plane: {@value}.
Definition: Frustum.java:262
Frustum()
Creates an undefined instance w/o calculating the frustum.
Definition: Frustum.java:123
Frustum(final Frustum o)
Definition: Frustum.java:132
final boolean isOutside(final Cube c)
Returns whether the given Cube is completely outside of this frustum.
Definition: Frustum.java:450
Vec4f[] getPlanes(final Vec4f[] out)
Sets each of the given Vec4f[6] out to Plane#toVec4f(Vec4f) in the order LEFT, RIGHT,...
Definition: Frustum.java:297
StringBuilder toString(StringBuilder sb)
Definition: Frustum.java:531
static final int TOP
Index for top plane: {@value}.
Definition: Frustum.java:266
static final int LEFT
Index for left plane: {@value}.
Definition: Frustum.java:260
final Plane[] planes
Normalized planes[l, r, b, t, n, f].
Definition: Frustum.java:113
static final int FAR
Index for far plane: {@value}.
Definition: Frustum.java:270
final boolean isSphereOutside(final Vec3f p, final float radius)
Returns whether the given sphere is completely outside of this frustum.
Definition: Frustum.java:527