AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
BoundingAABB.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXCOLLIDE_BOUNDINGAABB_H
18#define AGXCOLLIDE_BOUNDINGAABB_H
19
21
22#include <agx/agx.h>
23#include <agx/Vec3.h>
24#include <agx/AffineMatrix4x4.h>
25#include <agx/Bound.h>
26#include <agxData/Type.h>
27
28#include <iosfwd>
29
30
31namespace agxCollide
32{
33
38 {
39 public:
42
50 BoundingAABB(const agx::Vec3& min, const agx::Vec3& max);
51
58 BoundingAABB(const agx::Bound3& other, const agx::AffineMatrix4x4& transform);
59
63 void reset();
64
71 void set(const agx::Bound3& other, const agx::AffineMatrix4x4& transform);
72
77 void expand(const agx::Bound3& other);
78
83 void expand(const agx::Vec3& point);
84
93 void expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax);
94
102 void expand(const agx::Bound3& other, const agx::AffineMatrix4x4& transform);
103
112 void expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax, const agx::AffineMatrix4x4& transform);
113
119 bool hasOverlap(const BoundingAABB* other) const;
120
128 bool testSphereOverlap(const agx::Vec3& pos, agx::Real radius) const;
129
133 bool isCleared() const;
134
135 using agx::Bound3::set;
137 };
138
139#ifndef SWIG
140 static_assert(sizeof(agx::Bound3) == sizeof(BoundingAABB), "Size mismatch");
141#endif
142
143
144
145 /* Implementation */
147 {
148 reset();
149 }
150
151
152 AGX_FORCE_INLINE BoundingAABB::BoundingAABB(const agx::Vec3& min, const agx::Vec3& max) : agx::Bound3(min, max)
153 {
154 }
155
156
158 {
159 this->reset();
160 this->expand(other, transform);
161 }
162
163
165 {
166 this->reset();
167 this->expand(other, transform);
168 }
169
170
172 {
174 max().set(-agx::RealMax);
175 }
176
177
179 {
180 return min()[0] > max()[0];
181 }
182
183
185 {
186 expand(other.min(), other.max());
187 }
188
189
191 {
192 expand(point, point);
193 }
194
195
196 AGX_FORCE_INLINE void BoundingAABB::expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax)
197 {
198 min() = agx::Vec3::componentMin(min(), otherMin);
199 max() = agx::Vec3::componentMax(max(), otherMax);
200 }
201
202
204 {
205 expand( other.min(), other.max(), transform );
206 }
207
208
210 {
211 return agx::Bound3::hasOverlap(*other);
212 }
213
214
216 {
217 const bool retval =
218 pos[0] > (min()[0] - radius) && pos[1] > (min()[1] - radius) && pos[2] > (min()[2] - radius) &&
219 pos[0] < (max()[0] + radius) && pos[1] < (max()[1] + radius) && pos[2] < (max()[2] + radius);
220 return retval;
221 }
222
223
224 inline std::ostream& operator << ( std::ostream& output, const BoundingAABB& bound )
225 {
226 output << "min(): " << bound.min() << ", max(): " << bound.max();
227 return output;
228 }
229
230}
231
233
234#endif
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGXPHYSICS_EXPORT
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
void expand(const agx::Bound3 &other)
Expands a bounding volume to contain both itself and another bound.
Definition: BoundingAABB.h:184
void reset()
Removes any extent of the bound.
Definition: BoundingAABB.h:171
void set(const agx::Bound3 &other, const agx::AffineMatrix4x4 &transform)
Sets a bounding volume given a bounding volume given in another coordinate-system.
Definition: BoundingAABB.h:164
BoundingAABB()
Creates an empty bounding volume. isCleared() will return 'true'.
Definition: BoundingAABB.h:146
bool testSphereOverlap(const agx::Vec3 &pos, agx::Real radius) const
Test if a sphere overlaps the bound.
Definition: BoundingAABB.h:215
bool hasOverlap(const BoundingAABB *other) const
Tests if the bound intersects with another bounding volume.
Definition: BoundingAABB.h:209
bool isCleared() const
Is the bounding volume cleared? Will be true e.g.
Definition: BoundingAABB.h:178
void expand(const agx::Vec3 &otherMin, const agx::Vec3 &otherMax, const agx::AffineMatrix4x4 &transform)
Expands a bounding volume given a bounding volume given in another coordinate-system.
bool hasOverlap(const BoundT &other) const
Definition: Bound.h:312
void set(const Vec3 &min, const Vec3 &max)
Relocate the bound to the new location.
Definition: Bound.h:264
const Vec3 & min() const
Definition: Bound.h:252
const Vec3 & max() const
Definition: Bound.h:255
void set(T x, T y, T z)
Definition: Vec3Template.h:459
static Vec3T componentMax(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the maximum of this and the other vector.
Definition: Vec3Template.h:385
static Vec3T componentMin(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the minimum of this and the other vector.
Definition: Vec3Template.h:379
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
Definition: BoundingAABB.h:224
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
AGXCORE_EXPORT const Real RealMax
double Real
Definition: Real.h:42
BoundT< Vec3 > Bound3
Definition: Bound.h:147