Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Frustum.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_FRUSTUM_H_
34#define DVD_FRUSTUM_H_
35
36namespace Divide {
37
38class Camera;
39class BoundingBox;
40class BoundingSphere;
41
42class Frustum {
43 public:
44
45 void set(const Frustum& other) noexcept;
46
47 [[nodiscard]] FrustumCollision ContainsPoint(const vec3<F32>& point, I8& lastPlaneCache) const noexcept;
48 [[nodiscard]] FrustumCollision ContainsBoundingBox(const BoundingBox& bbox, I8& lastPlaneCache) const noexcept;
49 [[nodiscard]] FrustumCollision ContainsSphere(const BoundingSphere& bSphere, I8& lastPlaneCache) const noexcept;
50 [[nodiscard]] FrustumCollision ContainsSphere(const vec3<F32>& center, F32 radius, I8& lastPlaneCache) const noexcept;
51
52 [[nodiscard]] FrustumCollision ContainsPoint(const vec3<F32>& point) const noexcept {
53 I8 lastPlaneCache = -1;
54 return ContainsPoint(point, lastPlaneCache);
55 }
56
57 [[nodiscard]] FrustumCollision ContainsBoundingBox(const BoundingBox& bbox) const noexcept {
58 I8 lastPlaneCache = -1;
59 return ContainsBoundingBox(bbox, lastPlaneCache);
60 }
61
62 [[nodiscard]] FrustumCollision ContainsSphere(const vec3<F32>& center, const F32 radius) const noexcept {
63 I8 lastPlaneCache = -1;
64 return ContainsSphere(center, radius, lastPlaneCache);
65 }
66
67 // Get the frustum corners in WorldSpace. cornerWS must be a vector with at least 8 allocated slots
68 void getCornersWorldSpace(std::array<vec3<F32>, to_base(FrustumPoints::COUNT)>& cornersWS) const noexcept;
69
70 const std::array<Plane<F32>, to_base(FrustumPlane::COUNT)>& computePlanes(const mat4<F32>& viewProjMatrix);
71
72
73 [[nodiscard]] FrustumCollision PlaneBoundingBoxIntersect(FrustumPlane frustumPlane, const BoundingBox& bbox) const noexcept;
74 [[nodiscard]] FrustumCollision PlaneBoundingSphereIntersect(FrustumPlane frustumPlane, const BoundingSphere& bsphere) const noexcept;
75 [[nodiscard]] FrustumCollision PlanePointIntersect(FrustumPlane frustumPlane, const vec3<F32>& point) const noexcept;
76 [[nodiscard]] FrustumCollision PlaneSphereIntersect(FrustumPlane frustumPlane, const vec3<F32>& center, F32 radius) const noexcept;
77 [[nodiscard]] FrustumCollision PlaneBoundingBoxIntersect(const FrustumPlane* frustumPlanes, U8 count, const BoundingBox& bbox) const noexcept;
78 [[nodiscard]] FrustumCollision PlaneBoundingSphereIntersect(const FrustumPlane* frustumPlanes, U8 count, const BoundingSphere& bsphere) const noexcept;
79 [[nodiscard]] FrustumCollision PlanePointIntersect(const FrustumPlane* frustumPlanes, U8 count, const vec3<F32>& point) const noexcept;
80 [[nodiscard]] FrustumCollision PlaneSphereIntersect(const FrustumPlane* frustumPlanes, U8 count, const vec3<F32>& center, F32 radius) const noexcept;
81
82 [[nodiscard]] const std::array<Plane<F32>, to_base(FrustumPlane::COUNT)>& planes() const noexcept { return _frustumPlanes; }
83
84 bool operator==(const Frustum& other) const = default;
85
86 private:
87 std::array<Plane<F32>, to_base(FrustumPlane::COUNT)> _frustumPlanes = create_array<to_base(FrustumPlane::COUNT)>(Plane<F32>{ WORLD_Y_AXIS, 0.0f });
88};
89
90[[nodiscard]] FrustumCollision PlaneBoundingBoxIntersect(const Plane<F32>& plane, const BoundingBox& bbox) noexcept;
91[[nodiscard]] FrustumCollision PlaneBoundingSphereIntersect(const Plane<F32>& plane, const BoundingSphere& bsphere) noexcept;
92[[nodiscard]] FrustumCollision PlanePointIntersect(const Plane<F32>& plane, const vec3<F32>& point) noexcept;
93[[nodiscard]] FrustumCollision PlaneSphereIntersect(const Plane<F32>& plane, const vec3<F32>& center, F32 radius) noexcept;
94
95}; // namespace Divide
96
97#endif //DVD_FRUSTUM_H_
bool operator==(const Frustum &other) const =default
FrustumCollision ContainsBoundingBox(const BoundingBox &bbox) const noexcept
Definition: Frustum.h:57
FrustumCollision PlaneBoundingBoxIntersect(FrustumPlane frustumPlane, const BoundingBox &bbox) const noexcept
Definition: Frustum.cpp:94
FrustumCollision ContainsPoint(const vec3< F32 > &point, I8 &lastPlaneCache) const noexcept
Definition: Frustum.cpp:21
FrustumCollision ContainsSphere(const BoundingSphere &bSphere, I8 &lastPlaneCache) const noexcept
Definition: Frustum.cpp:170
const std::array< Plane< F32 >, to_base(FrustumPlane::COUNT)> & computePlanes(const mat4< F32 > &viewProjMatrix)
Definition: Frustum.cpp:226
FrustumCollision PlanePointIntersect(FrustumPlane frustumPlane, const vec3< F32 > &point) const noexcept
Definition: Frustum.cpp:102
const std::array< Plane< F32 >, to_base(FrustumPlane::COUNT)> & planes() const noexcept
Definition: Frustum.h:82
FrustumCollision ContainsBoundingBox(const BoundingBox &bbox, I8 &lastPlaneCache) const noexcept
Definition: Frustum.cpp:174
FrustumCollision ContainsSphere(const vec3< F32 > &center, const F32 radius) const noexcept
Definition: Frustum.h:62
void set(const Frustum &other) noexcept
Definition: Frustum.cpp:202
FrustumCollision PlaneBoundingSphereIntersect(FrustumPlane frustumPlane, const BoundingSphere &bsphere) const noexcept
Definition: Frustum.cpp:98
void getCornersWorldSpace(std::array< vec3< F32 >, to_base(FrustumPoints::COUNT)> &cornersWS) const noexcept
Definition: Frustum.cpp:208
FrustumCollision PlaneSphereIntersect(FrustumPlane frustumPlane, const vec3< F32 > &center, F32 radius) const noexcept
Definition: Frustum.cpp:106
std::array< Plane< F32 >, to_base(FrustumPlane::COUNT)> _frustumPlanes
Definition: Frustum.h:87
FrustumCollision ContainsPoint(const vec3< F32 > &point) const noexcept
Definition: Frustum.h:52
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FrustumCollision PlaneBoundingSphereIntersect(const Plane< F32 > &plane, const BoundingSphere &bsphere) noexcept
Definition: Frustum.cpp:49
uint8_t U8
FrustumCollision PlaneSphereIntersect(const Plane< F32 > &plane, const vec3< F32 > &center, const F32 radius) noexcept
Definition: Frustum.cpp:53
FrustumCollision PlaneBoundingBoxIntersect(const Plane< F32 > &plane, const BoundingBox &bbox) noexcept
Definition: Frustum.cpp:159
FrustumCollision PlanePointIntersect(const Plane< F32 > &plane, const vec3< F32 > &point) noexcept
Definition: Frustum.cpp:11
static const vec3< F32 > WORLD_Y_AXIS
Definition: MathVectors.h:1440
constexpr auto to_base(const Type value) -> Type