32 #ifndef __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
33 #define __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
35 #include <vmmlib/vector.hpp>
40 template<
typename T >
54 inline void set( T cx, T cy, T cz, T size );
63 inline void setEmpty(
bool empty =
true );
64 inline bool isEmpty()
const;
65 inline void setDirty(
bool dirty =
true );
66 inline bool isDirty()
const;
79 template<
typename T >
80 inline std::ostream& operator << ( std::ostream& os,
83 return os << aabb.getMin() <<
" - " << aabb.getMax();
86 template<
typename T >
87 AxisAlignedBoundingBox< T >::AxisAlignedBoundingBox()
94 template<
typename T >
95 AxisAlignedBoundingBox< T >::AxisAlignedBoundingBox(
const vector< 3, T >& pMin,
105 template<
typename T >
106 AxisAlignedBoundingBox< T >::AxisAlignedBoundingBox(
const vector< 4, T >& sphere )
110 _max = _min = sphere.getCenter();
111 _max += sphere.getRadius();
112 _min -= sphere.getRadius();
117 template<
typename T >
118 AxisAlignedBoundingBox< T >::AxisAlignedBoundingBox( T cx, T cy, T cz, T size )
129 template<
typename T >
130 inline bool AxisAlignedBoundingBox< T >::isIn(
const vector< 4, T >& sphere )
135 sv += sphere.getRadius();
136 if ( sv.x() > _max.x() || sv.y() > _max.y() || sv.z() > _max.z() )
138 sv -= sphere.getRadius() * 2.0f;
139 if ( sv.x() < _min.x() || sv.y() < _min.y() || sv.z() < _min.z() )
146 template<
typename T >
147 inline bool AxisAlignedBoundingBox< T >::isIn(
const vector< 3, T >& pos )
151 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.z() > _max.z()
152 || pos.x() < _min.x() || pos.y() < _min.y() || pos.z() < _min.z() )
161 template<
typename T >
162 inline bool AxisAlignedBoundingBox< T >::isIn2d(
const vector< 3, T >& pos )
166 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.x() < _min.x()
167 || pos.y() < _min.y() )
176 template<
typename T >
177 inline void AxisAlignedBoundingBox< T >::set(
const vector< 3, T >& pMin,
187 template<
typename T >
188 inline void AxisAlignedBoundingBox< T >::set( T cx, T cy, T cz, T size )
191 _min = center - size;
192 _max = center + size;
198 template<
typename T >
199 inline void AxisAlignedBoundingBox< T >::setMin(
const vector< 3, T >& pMin )
206 template<
typename T >
207 inline void AxisAlignedBoundingBox< T >::setMax(
const vector< 3, T >& pMax )
214 template<
typename T >
215 inline const vector< 3, T >& AxisAlignedBoundingBox< T >::getMin()
const
222 template<
typename T >
223 inline const vector< 3, T >& AxisAlignedBoundingBox< T >::getMax()
const
230 template<
typename T >
232 AxisAlignedBoundingBox< T >::getCenter()
const
234 return _min + ( ( _max - _min ) * 0.5f );
239 template<
typename T >
241 AxisAlignedBoundingBox< T >::getDimension()
const
248 template<
typename T >
249 void AxisAlignedBoundingBox< T >::merge(
const AxisAlignedBoundingBox<T>& aabb )
259 _empty = _dirty =
false;
267 if ( min.x() < _min.x() )
269 if ( min.y() < _min.y() )
271 if ( min.z() < _min.z() )
274 if ( max.x() > _max.x() )
276 if ( max.y() > _max.y() )
278 if ( max.z() > _max.z() )
282 template<
typename T >
283 void AxisAlignedBoundingBox< T >::merge(
const vector< 3, T >& point )
289 _empty = _dirty =
false;
293 if ( point.x() < _min.x() )
294 _min.x() = point.x();
295 if ( point.y() < _min.y() )
296 _min.y() = point.y();
297 if ( point.z() < _min.z() )
298 _min.z() = point.z();
300 if ( point.x() > _max.x() )
301 _max.x() = point.x();
302 if ( point.y() > _max.y() )
303 _max.y() = point.y();
304 if ( point.z() > _max.z() )
305 _max.z() = point.z();
308 template<
typename T >
309 inline void AxisAlignedBoundingBox< T >::setEmpty(
bool empty )
316 template<
typename T >
318 AxisAlignedBoundingBox< T >::isEmpty()
const
325 template<
typename T >
327 AxisAlignedBoundingBox< T >::setDirty(
bool dirty )
334 template<
typename T >
336 AxisAlignedBoundingBox< T >::isDirty()
const
343 typedef AxisAlignedBoundingBox< float > Aabbf;