jaulib v1.3.8
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
frustum.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11#ifndef JAU_MATH_GEOM_FRUSTUM_HPP_
12#define JAU_MATH_GEOM_FRUSTUM_HPP_
13
14#include <cmath>
15#include <cstdarg>
16#include <string>
17
18#include <jau/float_math.hpp>
19#include <jau/math/vec3f.hpp>
20#include <jau/math/vec4f.hpp>
21#include <jau/math/mat4f.hpp>
24
25namespace jau::math::geom {
26
27 /** \addtogroup Math
28 *
29 * @{
30 */
31
32/**
33 * Providing frustum {@link #getPlanes() planes} derived by different inputs
34 * ({@link #updateFrustumPlanes(float[], int) P*MV}, ..) used to classify objects
35 * <ul>
36 * <li> {@link #classifyPoint(Vec3f) point} </li>
37 * <li> {@link #classifySphere(Vec3f, float) sphere} </li>
38 * </ul>
39 * and to test whether they are outside
40 * <ul>
41 * <li> {@link #isOutside(Vec3f) point} </li>
42 * <li> {@link #isSphereOutside(Vec3f, float) sphere} </li>
43 * <li> {@link #isOutside(AABBox) bounding-box} </li>
44 * <li> {@link #isOutside(Cube) cube} </li>
45 * </ul>
46 *
47 * <p>
48 * Extracting the world-frustum planes from the P*Mv:
49 * <pre>
50 * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
51 * Gil Gribb <ggribb@ravensoft.com>
52 * Klaus Hartmann <k_hartmann@osnabrueck.netsurf.de>
53 * http://graphics.cs.ucf.edu/cap4720/fall2008/plane_extraction.pdf
54 * </pre>
55 * Classifying Point, Sphere and AABBox:
56 * <pre>
57 * Efficient View Frustum Culling
58 * Daniel Sýkora <sykorad@fel.cvut.cz>
59 * Josef Jelínek <jelinej1@fel.cvut.cz>
60 * http://www.cg.tuwien.ac.at/hostings/cescg/CESCG-2002/DSykoraJJelinek/index.html
61 * </pre>
62 * <pre>
63 * Lighthouse3d.com
64 * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
65 * </pre>
66 *
67 * Fundamentals about Planes, Half-Spaces and Frustum-Culling:<br/>
68 * <pre>
69 * Planes and Half-Spaces, Max Wagner <mwagner@digipen.edu>
70 * http://www.emeyex.com/site/tuts/PlanesHalfSpaces.pdf
71 * </pre>
72 * <pre>
73 * Frustum Culling, Max Wagner <mwagner@digipen.edu>
74 * http://www.emeyex.com/site/tuts/FrustumCulling.pdf
75 * </pre>
76 * </p>
77 */
78class Frustum {
79 public:
80 /** Index for left plane: {@value} */
81 constexpr static const int LEFT = 0;
82 /** Index for right plane: {@value} */
83 constexpr static const int RIGHT = 1;
84 /** Index for bottom plane: {@value} */
85 constexpr static const int BOTTOM = 2;
86 /** Index for top plane: {@value} */
87 constexpr static const int TOP = 3;
88 /** Index for near plane: {@value} */
89 constexpr static const int NEAR = 4;
90 /** Index for far plane: {@value} */
91 constexpr static const int FAR = 5;
92
93 /**
94 * {@link Frustum} description by {@link #fovhv} and {@link #zNear}, {@link #zFar}.
95 */
96 class FovDesc {
97 public:
98 /** Field of view in both directions, may not be centered, either {@link FovHVHalves#inTangents} or radians. */
100 /** Near Z */
101 float zNear;
102 /** Far Z */
103 float zFar;
104 /**
105 * @param fovhv field of view in both directions, may not be centered, either {@link FovHVHalves#inTangents} or radians
106 * @param zNear
107 * @param zFar
108 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}.
109 */
110 FovDesc(const FovHVHalves& fovhv_, const float zNear_, const float zFar_)
111 : fovhv(fovhv_), zNear(zNear_), zFar(zFar_)
112 {
113 if( zNear <= 0.0f || zFar <= zNear ) {
114 throw IllegalArgumentError("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE);
115 }
116 }
117
118 constexpr FovDesc(const FovDesc& o) noexcept = default;
119 constexpr FovDesc(FovDesc&& o) noexcept = default;
120 FovDesc& operator=(const FovDesc&) noexcept = default;
121 FovDesc& operator=(FovDesc&&) noexcept = default;
122
123 std::string toString() noexcept {
124 return "FrustumFovDesc["+fovhv.toStringInDegrees()+", Z["+std::to_string(zNear)+" - "+std::to_string(zFar)+"]]";
125 }
126 };
127
128 /**
129 * Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0
130 * <p>
131 * In order to work w/ {@link Frustum#isOutside(AABBox) isOutside(..)} methods,
132 * the normals have to point to the inside of the frustum.
133 * </p>
134 */
135 class Plane {
136 public:
137 /** Normal of the plane */
139
140 /** Distance to origin */
141 float d;
142
143 constexpr Plane() noexcept
144 : n(), d(0) {}
145
146 constexpr Plane(const Plane& o) noexcept = default;
147 constexpr Plane(Plane&& o) noexcept = default;
148 constexpr Plane& operator=(const Plane&) noexcept = default;
149 constexpr Plane& operator=(Plane&&) noexcept = default;
150
151 /**
152 * Setup of plane using 3 points. None of the three points are mutated.
153 * <p>
154 * Since this method may not properly define whether the normal points inside the frustum,
155 * consider using {@link #set(Vec3f, Vec3f)}.
156 * </p>
157 * @param p0 point on plane, used as the shared start-point for vec(p0->p1) and vec(p0->p2)
158 * @param p1 point on plane
159 * @param p2 point on plane
160 * @return this plane for chaining
161 */
162 constexpr Plane& set(const jau::math::Vec3f& p0, const jau::math::Vec3f& p1, const jau::math::Vec3f& p2) noexcept {
163 const jau::math::Vec3f v = p1 - p0;
164 const jau::math::Vec3f u = p2 - p0;
165 n.cross(v, u).normalize();
166 d = (jau::math::Vec3f(n) * -1.0f).dot(p0);
167 return *this;
168 }
169
170 /**
171 * Setup of plane using given normal and one point on plane. The given normal is mutated, the point not mutated.
172 * @param n_ normal to plane pointing to the inside of this frustum
173 * @param p0 point on plane, consider choosing the closest point to origin
174 * @return this plane for chaining
175 */
176 constexpr Plane& set(const jau::math::Vec3f& n_, const jau::math::Vec3f& p0) noexcept {
177 n = n_;
178 d = (n * -1.0f).dot(p0);
179 return *this;
180 }
181
182 /** Sets the given vec4f {@code out} to {@code ( n, d )}. Returns {@code out} for chaining. */
183 constexpr jau::math::Vec4f& toVec4f(jau::math::Vec4f& out) const noexcept {
184 out.set(n, d);
185 return out;
186 }
187
188 /**
189 * Sets the given {@code [float[off]..float[off+4])} {@code out} to {@code ( n, d )}.
190 * @param out the {@code float[off+4]} output array
191 */
192 constexpr void toFloats(float out[/* off+4] */]) const noexcept {
193 out[0] = n.x;
194 out[1] = n.y;
195 out[2] = n.z;
196 out[3] = d;
197 }
198
199 /**
200 * Return signed distance of plane to given point.
201 * <ul>
202 * <li>If dist &lt; 0 , then the point p lies in the negative halfspace.</li>
203 * <li>If dist = 0 , then the point p lies in the plane.</li>
204 * <li>If dist &gt; 0 , then the point p lies in the positive halfspace.</li>
205 * </ul>
206 * A plane cuts 3D space into 2 half spaces.
207 * <p>
208 * Positive halfspace is where the plane’s normals vector points into.
209 * </p>
210 * <p>
211 * Negative halfspace is the <i>other side</i> of the plane, i.e. *-1
212 * </p>
213 **/
214 constexpr float distanceTo(const float x, const float y, const float z) const noexcept {
215 return n.x * x + n.y * y + n.z * z + d;
216 }
217
218 /** Return distance of plane to given point, see {@link #distanceTo(float, float, float)}. */
219 constexpr float distanceTo(const jau::math::Vec3f& p) const noexcept {
220 return n.dot(p) + d;
221 }
222
223 std::string toString() const noexcept {
224 return "Plane[ [ " + n.toString() + " ], " + std::to_string(d) + "]";
225 }
226 };
227
228 private:
229 /** Normalized planes[l, r, b, t, n, f] */
230 Plane planes[6];
231
232 public:
233 /**
234 * Creates an undefined instance w/o calculating the frustum.
235 * <p>
236 * Use one of the <code>update(..)</code> methods to set the {@link #getPlanes() planes}.
237 * </p>
238 * @see #updateByPlanes(Plane[])
239 * @see #updateFrustumPlanes(float[], int)
240 */
241 constexpr Frustum() noexcept = default;
242
243 constexpr Frustum(const Frustum& o) noexcept = default;
244 constexpr Frustum(Frustum&& o) noexcept = default;
245 constexpr Frustum& operator=(const Frustum&) noexcept = default;
246 constexpr Frustum& operator=(Frustum&&) noexcept = default;
247
248 /**
249 * Sets each of the given {@link Vec4f}[6] {@code out} to {@link Plane#toVec4f(Vec4f)}
250 * in the order {@link #LEFT}, {@link #RIGHT}, {@link #BOTTOM}, {@link #TOP}, {@link #NEAR}, {@link #FAR}.
251 * @param out the jau::math::vec4f[6] output array
252 * @return {@code out} for chaining
253 */
254 constexpr jau::math::Vec4f* getPlanes(jau::math::Vec4f out[/*6*/]) const noexcept {
255 planes[LEFT ].toVec4f(out[0]);
256 planes[RIGHT ].toVec4f(out[1]);
257 planes[BOTTOM].toVec4f(out[2]);
258 planes[TOP ].toVec4f(out[3]);
259 planes[NEAR ].toVec4f(out[4]);
260 planes[FAR ].toVec4f(out[5]);
261 return out;
262 }
263
264 /** Sets the given {@code [float[off]..float[off+4*6])} {@code out} to {@code ( n, d )}. */
265 /**
266 * Sets each of the given {@code [float[off]..float[off+4*6])} {@code out} to {@link Plane#toFloats(float[], int)},
267 * i.e. [n.x, n.y, n.z, d, ...].
268 * <p>
269 * Plane order is as follows: {@link #LEFT}, {@link #RIGHT}, {@link #BOTTOM}, {@link #TOP}, {@link #NEAR}, {@link #FAR}.
270 * </p>
271 * @param out the {@code float[off+4*6]} output array
272 * @return {@code out} for chaining
273 */
274 constexpr void getPlanes(float out[/* off+4*6] */]) const noexcept {
275 planes[LEFT ].toFloats( out + static_cast<ptrdiff_t>(4*0) );
276 planes[RIGHT ].toFloats( out + static_cast<ptrdiff_t>(4*1) );
277 planes[BOTTOM].toFloats( out + static_cast<ptrdiff_t>(4*2) );
278 planes[TOP ].toFloats( out + static_cast<ptrdiff_t>(4*3) );
279 planes[NEAR ].toFloats( out + static_cast<ptrdiff_t>(4*4) );
280 planes[FAR ].toFloats( out + static_cast<ptrdiff_t>(4*5) );
281 }
282
283 /**
284 * Copy the given <code>src</code> planes into this this instance's planes.
285 * @param src the 6 source planes
286 */
287 constexpr void updateByPlanes(const Plane src[/*6*/]) noexcept {
288 planes[0] = src[0];
289 planes[1] = src[1];
290 planes[2] = src[2];
291 planes[3] = src[3];
292 planes[4] = src[4];
293 planes[5] = src[5];
294 }
295
296 /**
297 * {@link Plane}s are ordered in the returned array as follows:
298 * <ul>
299 * <li>{@link #LEFT}</li>
300 * <li>{@link #RIGHT}</li>
301 * <li>{@link #BOTTOM}</li>
302 * <li>{@link #TOP}</li>
303 * <li>{@link #NEAR}</li>
304 * <li>{@link #FAR}</li>
305 * </ul>
306 * <p>
307 * {@link Plane}'s normals are pointing to the inside of the frustum
308 * in order to work w/ {@link #isOutside(AABBox) isOutside(..)} methods.
309 * </p>
310 *
311 * @return array of normalized {@link Plane}s, order see above.
312 */
313 constexpr Plane* getPlanes() noexcept { return planes; }
314
315 /**
316 * Calculate the frustum planes in world coordinates
317 * using the passed {@link FovDesc}.
318 * <p>
319 * Operation Details:
320 * <ul>
321 * <li>The given {@link FovDesc} will be transformed
322 * into the given perspective matrix (column major order) first,
323 * see {@link Matrix4f#setToPerspective(FovHVHalves, float, float)}.</li>
324 * <li>Then the perspective matrix is used to {@link Matrix4f#updateFrustumPlanes(Frustum)} this instance.</li>
325 * </ul>
326 * </p>
327 * <p>
328 * Frustum plane's normals will point to the inside of the viewing frustum,
329 * as required by this class.
330 * </p>
331 *
332 * @param m 4x4 matrix in column-major order (also result)
333 * @param fovDesc {@link Frustum} {@link FovDesc}
334 * @return given matrix for chaining
335 * @see Matrix4f#setToPerspective(FovHVHalves, float, float)
336 * @see Matrix4f#updateFrustumPlanes(Frustum)
337 * @see Matrix4f#getFrustum(Frustum, FovDesc)
338 */
340 m.setToPerspective(fovDesc.fovhv, fovDesc.zNear, fovDesc.zFar);
341 setFromMat(m);
342 return m;
343 }
344
345 /**
346 * Calculate the frustum planes in world coordinates
347 * using the given column major order matrix, usually a projection (P) or premultiplied P*MV matrix.
348 * <p>
349 * Frustum plane's normals will point to the inside of the viewing frustum,
350 * as required by this class.
351 * </p>
352 */
353 Frustum& setFromMat(const jau::math::Mat4f& m) noexcept {
354 // Left: a = m41 + m11, b = m42 + m12, c = m43 + m13, d = m44 + m14 - [1..4] column-major
355 // Left: a = m30 + m00, b = m31 + m01, c = m32 + m02, d = m33 + m03 - [0..3] column-major
356 {
358 p.n.set( m.m30 + m.m00,
359 m.m31 + m.m01,
360 m.m32 + m.m02 );
361 p.d = m.m33 + m.m03;
362 }
363
364 // Right: a = m41 - m11, b = m42 - m12, c = m43 - m13, d = m44 - m14 - [1..4] column-major
365 // Right: a = m30 - m00, b = m31 - m01, c = m32 - m02, d = m33 - m03 - [0..3] column-major
366 {
368 p.n.set( m.m30 - m.m00,
369 m.m31 - m.m01,
370 m.m32 - m.m02 );
371 p.d = m.m33 - m.m03;
372 }
373
374 // Bottom: a = m41 + m21, b = m42 + m22, c = m43 + m23, d = m44 + m24 - [1..4] column-major
375 // Bottom: a = m30 + m10, b = m31 + m11, c = m32 + m12, d = m33 + m13 - [0..3] column-major
376 {
378 p.n.set( m.m30 + m.m10,
379 m.m31 + m.m11,
380 m.m32 + m.m12 );
381 p.d = m.m33 + m.m13;
382 }
383
384 // Top: a = m41 - m21, b = m42 - m22, c = m43 - m23, d = m44 - m24 - [1..4] column-major
385 // Top: a = m30 - m10, b = m31 - m11, c = m32 - m12, d = m33 - m13 - [0..3] column-major
386 {
388 p.n.set( m.m30 - m.m10,
389 m.m31 - m.m11,
390 m.m32 - m.m12 );
391 p.d = m.m33 - m.m13;
392 }
393
394 // Near: a = m41m31, b = m42m32, c = m43m33, d = m44m34 - [1..4] column-major
395 // Near: a = m30m20, b = m31m21, c = m32m22, d = m33m23 - [0..3] column-major
396 {
398 p.n.set( m.m30 + m.m20,
399 m.m31 + m.m21,
400 m.m32 + m.m22 );
401 p.d = m.m33 + m.m23;
402 }
403
404 // Far: a = m41 - m31, b = m42 - m32, c = m43 - m33, d = m44 - m34 - [1..4] column-major
405 // Far: a = m30 - m20, b = m31 - m21, c = m32m22, d = m33m23 - [0..3] column-major
406 {
408 p.n.set( m.m30 - m.m20,
409 m.m31 - m.m21,
410 m.m32 - m.m22 );
411 p.d = m.m33 - m.m23;
412 }
413
414 // Normalize all planes
415 for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
416 geom::Frustum::Plane& p = planes[i];
417 const float invLen = 1.0f / p.n.length();
418 p.n *= invLen;
419 p.d *= invLen;
420 }
421 return *this;
422 }
423
424 private:
425 static bool intersects(const Plane& p, const AABBox3f& box) noexcept {
426 const Vec3f& lo = box.low();
427 const Vec3f& hi = box.high();
428
429 return p.distanceTo(lo.x, lo.y, lo.z) > 0.0f ||
430 p.distanceTo(hi.x, lo.y, lo.z) > 0.0f ||
431 p.distanceTo(lo.x, hi.y, lo.z) > 0.0f ||
432 p.distanceTo(hi.x, hi.y, lo.z) > 0.0f ||
433 p.distanceTo(lo.x, lo.y, hi.z) > 0.0f ||
434 p.distanceTo(hi.x, lo.y, hi.z) > 0.0f ||
435 p.distanceTo(lo.x, hi.y, hi.z) > 0.0f ||
436 p.distanceTo(hi.x, hi.y, hi.z) > 0.0f;
437 }
438
439 public:
440
441 /**
442 * Returns whether the given {@link AABBox} is completely outside of this frustum.
443 * <p>
444 * Note: If method returns false, the box may only be partially inside, i.e. intersects with this frustum
445 * </p>
446 */
447 bool isOutside(const AABBox3f&& box) const noexcept {
448 return !intersects(planes[0], box) ||
449 !intersects(planes[1], box) ||
450 !intersects(planes[2], box) ||
451 !intersects(planes[3], box) ||
452 !intersects(planes[4], box) ||
453 !intersects(planes[5], box);
454 }
455
457
458 /**
459 * Classifies the given {@link Vec3f} point whether it is outside, inside or on a plane of this frustum.
460 *
461 * @param p the point
462 * @return {@link Location} of point related to frustum planes
463 */
464 location_t classifyPoint(const Vec3f& p) const noexcept {
466
467 for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
468 const float d = planes[i].distanceTo(p);
469 if ( d < 0.0f ) {
470 return location_t::OUTSIDE;
471 } else if ( d == 0.0f ) {
473 }
474 }
475 return res;
476 }
477
478 /**
479 * Returns whether the given {@link Vec3f} point is completely outside of this frustum.
480 *
481 * @param p the point
482 * @return true if outside of the frustum, otherwise inside or on a plane
483 */
484 bool isOutside(const Vec3f& p) const noexcept {
485 return planes[0].distanceTo(p) < 0.0f ||
486 planes[1].distanceTo(p) < 0.0f ||
487 planes[2].distanceTo(p) < 0.0f ||
488 planes[3].distanceTo(p) < 0.0f ||
489 planes[4].distanceTo(p) < 0.0f ||
490 planes[5].distanceTo(p) < 0.0f;
491 }
492
493 /**
494 * Classifies the given sphere whether it is is outside, intersecting or inside of this frustum.
495 *
496 * @param p center of the sphere
497 * @param radius radius of the sphere
498 * @return {@link Location} of point related to frustum planes
499 */
500 location_t classifySphere(const Vec3f& p, const float radius) const noexcept {
501 location_t res = location_t::INSIDE; // fully inside
502
503 for (int i = 0; i < 6; ++i) { // NOLINT(modernize-loop-convert)
504 const float d = planes[i].distanceTo(p);
505 if ( d < -radius ) {
506 // fully outside
507 return location_t::OUTSIDE;
508 } else if (d < radius ) {
509 // intersecting
511 }
512 }
513 return res;
514 }
515
516 /**
517 * Returns whether the given sphere is completely outside of this frustum.
518 *
519 * @param p center of the sphere
520 * @param radius radius of the sphere
521 * @return true if outside of the frustum, otherwise inside or intersecting
522 */
523 bool isSphereOutside(const Vec3f& p, const float radius) const noexcept {
524 return location_t::OUTSIDE == classifySphere(p, radius);
525 }
526
527 std::string toString() {
528 std::string s;
529 s.append("Frustum[Planes[").append("\n")
530 .append(" L: ").append(planes[0].toString()).append(",\n")
531 .append(" R: ").append(planes[1].toString()).append(",\n")
532 .append(" B: ").append(planes[2].toString()).append(",\n")
533 .append(" T: ").append(planes[3].toString()).append(",\n")
534 .append(" N: ").append(planes[4].toString()).append(",\n")
535 .append(" F: ").append(planes[5].toString()).append("],\n")
536 .append("]");
537 return s;
538 }
539
540};
541
542/**@}*/
543
544} // namespace jau::math::geom
545
546#endif // JAU_MATH_GEOM_FRUSTUM_HPP_
547
#define E_FILE_LINE
Horizontal and vertical field of view (FOV) halves, allowing a non-centered projection.
Matrix4 & setToPerspective(const value_type fovy_rad, const value_type aspect, const value_type zNear, const value_type zFar)
Set this matrix to perspective frustum projection.
Definition mat4f.hpp:1247
constexpr Vector3F & set(const Vec2f &o, const value_type z_) noexcept
TODO constexpr bool operator<=>(const vec3f_t& rhs ) const noexcept { return ... }...
Definition vec3f.hpp:138
value_type x
Definition vec3f.hpp:69
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
Definition vec3f.hpp:252
value_type y
Definition vec3f.hpp:70
value_type z
Definition vec3f.hpp:71
Axis Aligned Bounding Box.
Definition aabbox3f.hpp:43
Frustum description by fovhv and zNear, zFar.
Definition frustum.hpp:96
FovDesc & operator=(const FovDesc &) noexcept=default
constexpr FovDesc(FovDesc &&o) noexcept=default
FovHVHalves fovhv
Field of view in both directions, may not be centered, either FovHVHalves#inTangents or radians.
Definition frustum.hpp:99
FovDesc(const FovHVHalves &fovhv_, const float zNear_, const float zFar_)
Definition frustum.hpp:110
constexpr FovDesc(const FovDesc &o) noexcept=default
FovDesc & operator=(FovDesc &&) noexcept=default
std::string toString() noexcept
Definition frustum.hpp:123
Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0.
Definition frustum.hpp:135
float d
Distance to origin.
Definition frustum.hpp:141
constexpr void toFloats(float out[]) const noexcept
Sets the given [float[off]..float[off+4]) out to ( n, d ).
Definition frustum.hpp:192
constexpr jau::math::Vec4f & toVec4f(jau::math::Vec4f &out) const noexcept
Sets the given vec4f out to ( n, d ).
Definition frustum.hpp:183
constexpr Plane & set(const jau::math::Vec3f &n_, const jau::math::Vec3f &p0) noexcept
Setup of plane using given normal and one point on plane.
Definition frustum.hpp:176
constexpr Plane & operator=(Plane &&) noexcept=default
constexpr Plane & set(const jau::math::Vec3f &p0, const jau::math::Vec3f &p1, const jau::math::Vec3f &p2) noexcept
Setup of plane using 3 points.
Definition frustum.hpp:162
jau::math::Vec3f n
Normal of the plane.
Definition frustum.hpp:138
constexpr Plane(Plane &&o) noexcept=default
constexpr Plane & operator=(const Plane &) noexcept=default
std::string toString() const noexcept
Definition frustum.hpp:223
constexpr Plane() noexcept
Definition frustum.hpp:143
constexpr float distanceTo(const jau::math::Vec3f &p) const noexcept
Return distance of plane to given point, see distanceTo(float, float, float).
Definition frustum.hpp:219
constexpr float distanceTo(const float x, const float y, const float z) const noexcept
Return signed distance of plane to given point.
Definition frustum.hpp:214
constexpr Plane(const Plane &o) noexcept=default
static constexpr const int LEFT
Index for left plane: {@value}.
Definition frustum.hpp:81
Mat4f & updateByFovDesc(jau::math::Mat4f &m, const FovDesc &fovDesc)
Calculate the frustum planes in world coordinates using the passed FovDesc.
Definition frustum.hpp:339
Frustum & setFromMat(const jau::math::Mat4f &m) noexcept
Calculate the frustum planes in world coordinates using the given column major order matrix,...
Definition frustum.hpp:353
location_t classifySphere(const Vec3f &p, const float radius) const noexcept
Classifies the given sphere whether it is is outside, intersecting or inside of this frustum.
Definition frustum.hpp:500
constexpr void getPlanes(float out[]) const noexcept
Sets the given [float[off]..float[off+4*6]) out to ( n, d ).
Definition frustum.hpp:274
constexpr void updateByPlanes(const Plane src[]) noexcept
Copy the given src planes into this this instance's planes.
Definition frustum.hpp:287
bool isOutside(const Vec3f &p) const noexcept
Returns whether the given Vec3f point is completely outside of this frustum.
Definition frustum.hpp:484
constexpr Frustum() noexcept=default
Creates an undefined instance w/o calculating the frustum.
static constexpr const int FAR
Index for far plane: {@value}.
Definition frustum.hpp:91
static constexpr const int TOP
Index for top plane: {@value}.
Definition frustum.hpp:87
static constexpr const int NEAR
Index for near plane: {@value}.
Definition frustum.hpp:89
constexpr jau::math::Vec4f * getPlanes(jau::math::Vec4f out[]) const noexcept
Sets each of the given Vec4f[6] out to Plane#toVec4f(Vec4f) in the order LEFT, RIGHT,...
Definition frustum.hpp:254
static constexpr const int BOTTOM
Index for bottom plane: {@value}.
Definition frustum.hpp:85
std::string toString()
Definition frustum.hpp:527
bool isSphereOutside(const Vec3f &p, const float radius) const noexcept
Returns whether the given sphere is completely outside of this frustum.
Definition frustum.hpp:523
location_t classifyPoint(const Vec3f &p) const noexcept
Classifies the given Vec3f point whether it is outside, inside or on a plane of this frustum.
Definition frustum.hpp:464
static constexpr const int RIGHT
Index for right plane: {@value}.
Definition frustum.hpp:83
constexpr Plane * getPlanes() noexcept
Planes are ordered in the returned array as follows:
Definition frustum.hpp:313
bool isOutside(const AABBox3f &&box) const noexcept
Returns whether the given AABBox is completely outside of this frustum.
Definition frustum.hpp:447
Matrix4< float > Mat4f
Definition mat4f.hpp:1928
Vector4F< float > Vec4f
Definition vec4f.hpp:375
Vector3F< float > Vec3f
Definition vec3f.hpp:433
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition backtrace.hpp:32
STL namespace.