24#ifndef JAU_FRUSTUM_HPP_
25#define JAU_FRUSTUM_HPP_
97 constexpr static const int LEFT = 0;
99 constexpr static const int RIGHT = 1;
103 constexpr static const int TOP = 3;
105 constexpr static const int NEAR = 4;
107 constexpr static const int FAR = 5;
194 d = (
n * -1.0f).dot(p0);
208 constexpr void toFloats(
float out[])
const noexcept {
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;
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]);
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);
374 p.
n.
set( m.m30 + m.m00,
384 p.
n.
set( m.m30 - m.m00,
394 p.
n.
set( m.m30 + m.m10,
404 p.
n.
set( m.m30 - m.m10,
414 p.
n.
set( m.m30 + m.m20,
424 p.
n.
set( m.m30 - m.m20,
431 for (
int i = 0; i < 6; ++i) {
433 const float invLen = 1.0f / p.
n.
length();
441 static bool intersects(
const Plane& p,
const AABBox3f& box)
noexcept {
442 const Vec3f& lo = box.low();
443 const Vec3f& hi = box.high();
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;
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);
483 for (
int i = 0; i < 6; ++i) {
484 const float d = planes[i].distanceTo(p);
487 }
else if ( d == 0.0f ) {
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;
519 for (
int i = 0; i < 6; ++i) {
520 const float d = planes[i].distanceTo(p);
524 }
else if (d < radius ) {
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")
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).
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.
constexpr Vector3F & set(const Vec2f &o, const value_type z_) noexcept
TODO constexpr bool operator<=>(const vec3f_t& rhs ) const noexcept { return ... }.
constexpr Vector3F & normalize() noexcept
Normalize this vector in place.
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
constexpr value_type dot(const Vector3F &o) const noexcept
Return the dot product of this vector and the given one.
constexpr Vector3F cross(const Vector3F &b) const noexcept
cross product this x b
std::string toString() const noexcept
4D vector using four value_type components.
constexpr Vector4F & set(const Vec3f &o, const value_type w_) noexcept
TODO constexpr bool operator<=>(const vec4f_t& rhs ) const noexcept { return ... }.
Axis Aligned Bounding Box.
Frustum description by fovhv and zNear, zFar.
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.
FovDesc(const FovHVHalves &fovhv_, const float zNear_, const float zFar_)
constexpr FovDesc(const FovDesc &o) noexcept=default
FovDesc & operator=(FovDesc &&) noexcept=default
std::string toString() noexcept
Plane equation := dot(n, x - p) = 0 -> Ax + By + Cz + d == 0.
float d
Distance to origin.
constexpr void toFloats(float out[]) const noexcept
Sets the given [float[off]..float[off+4]) out to ( n, d ).
constexpr jau::math::Vec4f & toVec4f(jau::math::Vec4f &out) const noexcept
Sets the given vec4f out to ( n, d ).
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.
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.
jau::math::Vec3f n
Normal of the plane.
constexpr Plane(Plane &&o) noexcept=default
constexpr Plane & operator=(const Plane &) noexcept=default
std::string toString() const noexcept
constexpr Plane() noexcept
constexpr float distanceTo(const jau::math::Vec3f &p) const noexcept
Return distance of plane to given point, see distanceTo(float, float, float).
constexpr float distanceTo(const float x, const float y, const float z) const noexcept
Return signed distance of plane to given point.
constexpr Plane(const Plane &o) noexcept=default
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
static constexpr const int LEFT
Index for left plane: {@value}.
Mat4f & updateByFovDesc(jau::math::Mat4f &m, const FovDesc &fovDesc) noexcept
Calculate the frustum planes in world coordinates using the passed FovDesc.
Frustum & setFromMat(const jau::math::Mat4f &m) noexcept
Calculate the frustum planes in world coordinates using the given column major order matrix,...
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.
constexpr void getPlanes(float out[]) const noexcept
Sets the given [float[off]..float[off+4*6]) out to ( n, d ).
constexpr void updateByPlanes(const Plane src[]) noexcept
Copy the given src planes into this this instance's planes.
bool isOutside(const Vec3f &p) const noexcept
Returns whether the given Vec3f point is completely outside of this frustum.
constexpr Frustum() noexcept=default
Creates an undefined instance w/o calculating the frustum.
static constexpr const int FAR
Index for far plane: {@value}.
static constexpr const int TOP
Index for top plane: {@value}.
static constexpr const int NEAR
Index for near plane: {@value}.
static constexpr const int BOTTOM
Index for bottom plane: {@value}.
bool isSphereOutside(const Vec3f &p, const float radius) const noexcept
Returns whether the given sphere is completely outside of this frustum.
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.
static constexpr const int RIGHT
Index for right plane: {@value}.
constexpr Plane * getPlanes() noexcept
Planes are ordered in the returned array as follows:
bool isOutside(const AABBox3f &&box) const noexcept
Returns whether the given AABBox is completely outside of this frustum.
std::string to_string(const alphabet &v) noexcept
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.