Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Bounds.hpp
1#pragma once
2#include "Common.hpp"
3#include <array>
4
10public:
12 BoundingSphere() = default;
13
18 BoundingSphere(const glm::vec3 & aCenter, float aRadius);
19
20 glm::vec3 center = glm::vec3(0.0f);
21 float radius = 0.0f;
22};
23
29public:
31 BoundingBox() = default;
32
37 BoundingBox(const glm::vec3 & v0, const glm::vec3 & v1);
38
44 BoundingBox(const glm::vec3 & v0, const glm::vec3 & v1, const glm::vec3 & v2);
45
49 void merge(const BoundingBox & box);
50
54 void merge(const glm::vec3 & point);
55
60
64 glm::vec3 getSize() const;
65
70 std::vector<glm::vec3> getCorners() const;
71
76 std::vector<glm::vec4> getHomogeneousCorners() const;
77
81 glm::vec3 getCentroid() const;
82
87 BoundingBox transformed(const glm::mat4 & trans) const;
88
93 bool contains(const glm::vec3 & point) const;
94
96 bool empty() const;
97
98 glm::vec3 minis = glm::vec3(std::numeric_limits<float>::max());
99 glm::vec3 maxis = glm::vec3(std::numeric_limits<float>::lowest());
100};
101
102
106class Frustum {
107public:
108
112 Frustum(const glm::mat4 & vp);
113
118 bool intersects(const BoundingBox & box) const;
119
127 static glm::mat4 perspective(float fov, float ratio, float near, float far);
128
138 static glm::mat4 ortho(float left, float right, float bottom, float top, float near, float far);
139
140private:
141
143 enum FrustumPlane : uint {
144 LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3, NEAR = 4, FAR = 5, COUNT = 6
145 };
146
147 std::array<glm::vec4, FrustumPlane::COUNT> _planes;
148 std::array<glm::vec3, 8> _corners;
149};
Represent the smallest axis-aligne box containing a given object or region of space.
Definition: Bounds.hpp:28
void merge(const BoundingBox &box)
Definition: Bounds.cpp:17
bool empty() const
Definition: Bounds.cpp:83
BoundingBox()=default
BoundingSphere getSphere() const
Definition: Bounds.cpp:27
std::vector< glm::vec3 > getCorners() const
Definition: Bounds.cpp:37
bool contains(const glm::vec3 &point) const
Definition: Bounds.cpp:79
glm::vec3 getCentroid() const
Definition: Bounds.cpp:61
std::vector< glm::vec4 > getHomogeneousCorners() const
Definition: Bounds.cpp:49
glm::vec3 minis
Lower-back-left corner of the box.
Definition: Bounds.hpp:98
BoundingBox transformed(const glm::mat4 &trans) const
Definition: Bounds.cpp:65
glm::vec3 maxis
Higher-top-right corner of the box.
Definition: Bounds.hpp:99
glm::vec3 getSize() const
Definition: Bounds.cpp:33
Represent the sphere of smallest radius containing a given object or region of space.
Definition: Bounds.hpp:9
BoundingSphere()=default
glm::vec3 center
The sphere center.
Definition: Bounds.hpp:20
float radius
The sphere radius.
Definition: Bounds.hpp:21
Represent a 3D frustum, volume defined by the intersection of six planes.
Definition: Bounds.hpp:106
std::array< glm::vec4, FrustumPlane::COUNT > _planes
Frustum hyperplane coefficients.
Definition: Bounds.hpp:147
std::array< glm::vec3, 8 > _corners
Frustum corners.
Definition: Bounds.hpp:148
FrustumPlane
Definition: Bounds.hpp:143
static glm::mat4 ortho(float left, float right, float bottom, float top, float near, float far)
Definition: Bounds.cpp:146
static glm::mat4 perspective(float fov, float ratio, float near, float far)
Definition: Bounds.cpp:137
bool intersects(const BoundingBox &box) const
Definition: Bounds.cpp:118