32 #ifndef __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__ 33 #define __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__ 36 #include <vmmlib/vector.hpp> 98 void merge(
const AABB<T>& aabb);
107 bool isEmpty()
const;
110 bool operator==(
const AABB<T>& other)
const;
113 bool operator!=(
const AABB<T>& other)
const;
131 #ifdef __INTEL_COMPILER 144 friend void lunchbox::byteswap(U&);
145 friend void staticjson::init(
AABB<float>*, staticjson::ObjectHandler*);
146 friend void staticjson::init(
AABB<double>*, staticjson::ObjectHandler*);
150 template <
typename T>
151 inline std::ostream& operator<<(std::ostream& os, const AABB<T>& aabb)
153 return os << aabb.getMin() <<
" - " << aabb.getMax();
156 template <
typename T>
158 : _min(
std::numeric_limits<T>::max())
159 , _max(
std::numeric_limits<T>::min())
165 : _min(std::numeric_limits<float>::max())
166 , _max(-std::numeric_limits<float>::max())
172 : _min(std::numeric_limits<double>::max())
173 , _max(-std::numeric_limits<double>::max())
177 template <
typename T>
179 : _min(
vector<3, T>(
std::min(pMin[0], pMax[0]),
std::min(pMin[1], pMax[1]),
180 std::min(pMin[2], pMax[2])))
181 , _max(
vector<3, T>(
std::max(pMin[0], pMax[0]),
std::max(pMin[1], pMax[1]),
182 std::max(pMin[2], pMax[2])))
186 template <
typename T>
189 _max = _min = sphere.getCenter();
190 _max += sphere.getRadius();
191 _min -= sphere.getRadius();
194 template <
typename T>
197 if (pos.x() > _max.x() || pos.y() > _max.y() || pos.z() > _max.z() ||
198 pos.x() < _min.x() || pos.y() < _min.y() || pos.z() < _min.z())
205 template <
typename T>
209 sv += sphere.getRadius();
210 if (sv.x() > _max.x() || sv.y() > _max.y() || sv.z() > _max.z())
212 sv -= sphere.getRadius() * 2.0f;
213 if (sv.x() < _min.x() || sv.y() < _min.y() || sv.z() < _min.z())
218 template <
typename T>
221 const auto& extent =
getSize() * 0.5f;
223 const float n = extent.x() * std::abs(plane.x()) +
224 extent.y() * std::abs(plane.y()) +
225 extent.z() * std::abs(plane.z());
227 return !(d - n >= 0 || d + n > 0);
230 template <
typename T>
236 template <
typename T>
242 template <
typename T>
245 return _min == other._min && _max == other._max;
248 template <
typename T>
251 return _min != other._min || _max != other._max;
254 template <
typename T>
257 return (_min + _max) * 0.5f;
260 template <
typename T>
266 template <
typename T>
272 if (min.x() < _min.x())
274 if (min.y() < _min.y())
276 if (min.z() < _min.z())
279 if (max.x() > _max.x())
281 if (max.y() > _max.y())
283 if (max.z() > _max.z())
287 template <
typename T>
290 if (point.x() < _min.x())
291 _min.x() = point.x();
292 if (point.y() < _min.y())
293 _min.y() = point.y();
294 if (point.z() < _min.z())
295 _min.z() = point.z();
297 if (point.x() > _max.x())
298 _max.x() = point.x();
299 if (point.y() > _max.y())
300 _max.y() = point.y();
301 if (point.z() > _max.z())
302 _max.z() = point.z();
305 template <
typename T>
308 _min = std::numeric_limits<T>::max();
309 _max = -std::numeric_limits<T>::max();
312 template <
typename T>
315 return _min.x() >= _max.x() || _min.y() >= _max.y() || _min.z() >= _max.x();
318 template <
typename T>
323 for (
size_t i = 0; i < 3; ++i)
327 nearPoint[i] = _min[i];
328 farPoint[i] = _max[i];
332 nearPoint[i] = _max[i];
333 farPoint[i] = _min[i];
338 template <
typename T>
bool isIn(const vector< 3, T > &point) const
vector< 3, T > getSize() const
void computeNearFar(const vector< 4, T > &plane, vector< 3, T > &nearPoint, vector< 3, T > &farPoint) const
Compute the nearest and furthest point of this box relative to the given plane.
static AABB< T > makeUnitBox()
bool operator!=(const AABB< T > &other) const
AABB()
Create an empty bounding box.
An axis-aligned bounding box.
const vector< 3, T > & getMin() const
bool operator==(const AABB< T > &other) const
bool isInFront(const vector< 4, T > &plane) const
void reset()
Clear this bounding box.
vector< 3, T > getCenter() const
const vector< 3, T > & getMax() const
void merge(const AABB< T > &aabb)
Create the union of this and the given bounding box.