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