32 #ifndef __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
33 #define __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
35 #include <vmmlib/vector.hpp>
48 template<
typename T >
class AABB
56 AABB( T cx, T cy, T cz, T size );
63 void set( T cx, T cy, T cz, T size );
78 AABB operator*(
const T value )
const;
79 AABB operator/(
const T value )
const;
80 AABB operator+(
const T value )
const;
81 AABB operator-(
const T value )
const;
83 void operator*=(
const T value );
84 void operator/=(
const T value );
85 void operator+=(
const T value );
86 void operator-=(
const T value );
89 bool operator==(
const AABB< U >& other )
const;
91 bool operator!=(
const AABB< U >& other )
const;
103 #ifndef VMMLIB_NO_TYPEDEFS
108 template<
typename T >
109 inline std::ostream& operator << ( std::ostream& os,
112 return os << aabb.getMin() <<
" - " << aabb.getMax();
116 : _min( std::numeric_limits< T >::max( ))
117 , _max( std::numeric_limits< T >::min( ))
121 : _min( std::numeric_limits< float >::max( ))
122 , _max( -std::numeric_limits< float >::max( ))
126 : _min( std::numeric_limits< double >::max( ))
127 , _max( -std::numeric_limits< double >::max( ))
130 template<
typename T >
137 template<
typename T >
140 _max = _min = sphere.getCenter();
141 _max += sphere.getRadius();
142 _min -= sphere.getRadius();
145 template<
typename T >
153 template<
typename T >
157 sv += sphere.getRadius();
158 if ( sv.x() > _max.x() || sv.y() > _max.y() || sv.z() > _max.z() )
160 sv -= sphere.getRadius() * 2.0f;
161 if ( sv.x() < _min.x() || sv.y() < _min.y() || sv.z() < _min.z() )
166 template<
typename T >
169 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.z() > _max.z() ||
170 pos.x() < _min.x() || pos.y() < _min.y() || pos.z() < _min.z( ))
177 template<
typename T >
180 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.x() < _min.x() ||
188 template<
typename T >
196 template<
typename T >
197 inline void AABB< T >::set( T cx, T cy, T cz, T size )
200 _min = center - size;
201 _max = center + size;
204 template<
typename T >
210 template<
typename T >
216 template<
typename T >
222 template<
typename T >
238 template<
typename T > AABB< T >
239 AABB< T >::operator*(
const T value )
const
246 template<
typename T > AABB< T >
247 AABB< T >::operator/(
const T value )
const
254 template<
typename T > AABB< T >
255 AABB< T >::operator+(
const T value )
const
262 template<
typename T > AABB< T >
263 AABB< T >::operator-(
const T value )
const
270 template<
typename T >
271 void AABB< T >::operator*=(
const T value )
277 template<
typename T >
278 void AABB< T >::operator/=(
const T value )
284 template<
typename T >
285 void AABB< T >::operator+=(
const T value )
291 template<
typename T >
292 void AABB< T >::operator-=(
const T value )
298 template<
typename T >
template<
class U >
bool
299 AABB< T >::operator==(
const AABB< U >& other )
302 return _min == other._min && _max == other._max;
305 template<
typename T >
template<
class U >
bool
306 AABB< T >::operator!=(
const AABB< U >& other )
309 return _min != other._min || _max != other._max;
312 template<
typename T >
315 return _min + ( ( _max - _min ) * 0.5f );
318 template<
typename T >
324 template<
typename T >
325 void AABB< T >::merge(
const AABB<T>& aabb )
330 if ( min.x() < _min.x() )
332 if ( min.y() < _min.y() )
334 if ( min.z() < _min.z() )
337 if ( max.x() > _max.x() )
339 if ( max.y() > _max.y() )
341 if ( max.z() > _max.z() )
345 template<
typename T >
348 if ( point.x() < _min.x() )
349 _min.x() = point.x();
350 if ( point.y() < _min.y() )
351 _min.y() = point.y();
352 if ( point.z() < _min.z() )
353 _min.z() = point.z();
355 if ( point.x() > _max.x() )
356 _max.x() = point.x();
357 if ( point.y() > _max.y() )
358 _max.y() = point.y();
359 if ( point.z() > _max.z() )
360 _max.z() = point.z();
363 template<
typename T >
inline
364 void AABB< T >::setEmpty()
366 _min = std::numeric_limits< T >::max();
367 _max = -std::numeric_limits< T >::max();
371 template<
typename T >
inline bool AABB< T >::isEmpty()
const
373 return ( _min.x() >= _max.x() || _min.y() >= _max.y() ||
374 _min.z() >= _max.x( ));
377 template<
typename T >
378 AABB< T > AABB< T >::makeUnitBox()
380 return AABB( vector< 3, T >::ZERO, vector< 3, T >::ONE );
AABB()
Create an empty bounding box.
An axis-aligned bounding box.