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