Saga
Saga Game Engine
Loading...
Searching...
No Matches
boundingBox.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4#include <optional>
5
6namespace Saga {
7
13 struct BoundingBox {
14 static float const oo;
15
16 glm::vec3 bounds[2];
17
18 // TODO: Cache these operations, with a dirty mask that tells you when bounds was altered (for recomputing these values)
23 glm::vec3 centroid();
24
29 glm::vec3 size();
30
31
37 float surfaceArea();
38
45 float volume();
46
52 bool inside(glm::vec3 point);
53
61 bool collidesWithRay(glm::vec4 point, glm::vec4 dir);
62
71 std::optional<float> findCollisionWithRay(glm::vec4 point, glm::vec4 dir);
72
79 bool intersectWith(const BoundingBox &other);
80
86 float lowerBoundSquareDistanceTo(const glm::vec3 point);
87
98 std::optional<float> findCollisionWithBox(glm::vec3 centroid, glm::vec3 dir, glm::vec3 size);
99
106
113 static BoundingBox mergeBox(const BoundingBox &a, const BoundingBox &b);
114
121 static BoundingBox confineBox(const BoundingBox &a, const BoundingBox &b);
122
128 static BoundingBox pointBox(const glm::vec3 &point);
129 };
130
131
132};
Definition: app.cpp:8
Represents a bounding box.
Definition: boundingBox.h:13
static BoundingBox mergeBox(const BoundingBox &a, const BoundingBox &b)
Compute a BoundingBox that is the union of the two input boxes.
Definition: boundingBox.cpp:83
static BoundingBox pointBox(const glm::vec3 &point)
Create a bounding box containing only one point.
Definition: boundingBox.cpp:111
static BoundingBox getExtremeBound()
Get a special invalid BoundingBox used as a starting point for mergeBox and confineBox....
Definition: boundingBox.cpp:117
static float const oo
infinity value. No bounding box's absolute value in any dimension can exceed this.
Definition: boundingBox.h:14
bool intersectWith(const BoundingBox &other)
Determines if a BoundingBox intersects with another.
Definition: boundingBox.cpp:76
float surfaceArea()
Compute the surface area of the BoundinBox.
Definition: boundingBox.cpp:53
bool inside(glm::vec3 point)
Determins if a point is inside of the bounding box.
Definition: boundingBox.cpp:22
glm::vec3 centroid()
Compute the centroid of the BoundingBox.
Definition: boundingBox.cpp:14
glm::vec3 bounds[2]
coordinates of the lower-left and upper-right corners of the bounding box, respectively.
Definition: boundingBox.h:16
float volume()
Compute the volume of the BoundingBox.
Definition: boundingBox.cpp:29
bool collidesWithRay(glm::vec4 point, glm::vec4 dir)
Determine if the BoundingBox collide with a ray.
Definition: boundingBox.cpp:64
glm::vec3 size()
Compute the size of the BoundingBox.
Definition: boundingBox.cpp:18
float lowerBoundSquareDistanceTo(const glm::vec3 point)
Compute the Lower-Bound squared distance from a point to the BoundingBox.
Definition: boundingBox.cpp:42
std::optional< float > findCollisionWithRay(glm::vec4 point, glm::vec4 dir)
Find the point of collision between a ray and the BoundingBox.
Definition: boundingBox.cpp:68
std::optional< float > findCollisionWithBox(glm::vec3 centroid, glm::vec3 dir, glm::vec3 size)
Find the collision between a moving bounding box and this one.
Definition: boundingBox.cpp:72
static BoundingBox confineBox(const BoundingBox &a, const BoundingBox &b)
Confine a BoundingBox within the other, effectively computing their intersection.
Definition: boundingBox.cpp:97