32 #ifndef __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
33 #define __VMML__AXIS_ALIGNED_BOUNDING_BOX__HPP__
35 #include <vmmlib/vector.hpp>
38 namespace lunchbox {
template<
class T >
void byteswap( T& ); }
50 template<
typename T >
class AABB
111 template<
class U >
friend void lunchbox::byteswap( U& );
114 template<
typename T >
inline
115 std::ostream& operator << ( std::ostream& os, const AABB< T >& aabb )
117 return os << aabb.getMin() <<
" - " << aabb.getMax();
121 : _min(
std::numeric_limits< T >::max( ))
122 , _max(
std::numeric_limits< T >::min( ))
126 : _min(
std::numeric_limits< float >::max( ))
127 , _max( -
std::numeric_limits< float >::max( ))
131 : _min(
std::numeric_limits< double >::max( ))
132 , _max( -
std::numeric_limits< double >::max( ))
135 template<
typename T >
137 : _min(
vector< 3, T >(
std::min( pMin[0], pMax[0] ),
138 std::min( pMin[1], pMax[1] ),
139 std::min( pMin[2], pMax[2] )))
140 , _max(
vector< 3, T >(
std::max( pMin[0], pMax[0] ),
141 std::max( pMin[1], pMax[1] ),
142 std::max( pMin[2], pMax[2] )))
147 _max = _min = sphere.getCenter();
148 _max += sphere.getRadius();
149 _min -= sphere.getRadius();
154 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.z() > _max.z() ||
155 pos.x() < _min.x() || pos.y() < _min.y() || pos.z() < _min.z( ))
162 template<
typename T >
inline
166 sv += sphere.getRadius();
167 if ( sv.x() > _max.x() || sv.y() > _max.y() || sv.z() > _max.z() )
169 sv -= sphere.getRadius() * 2.0f;
170 if ( sv.x() < _min.x() || sv.y() < _min.y() || sv.z() < _min.z() )
185 template<
typename T >
inline
188 return _min == other._min && _max == other._max;
191 template<
typename T >
inline
194 return _min != other._min || _max != other._max;
199 return ( _min + _max ) * 0.5f;
207 template<
typename T >
213 if ( min.x() < _min.x() )
215 if ( min.y() < _min.y() )
217 if ( min.z() < _min.z() )
220 if ( max.x() > _max.x() )
222 if ( max.y() > _max.y() )
224 if ( max.z() > _max.z() )
228 template<
typename T >
231 if ( point.x() < _min.x() )
232 _min.x() = point.x();
233 if ( point.y() < _min.y() )
234 _min.y() = point.y();
235 if ( point.z() < _min.z() )
236 _min.z() = point.z();
238 if ( point.x() > _max.x() )
239 _max.x() = point.x();
240 if ( point.y() > _max.y() )
241 _max.y() = point.y();
242 if ( point.z() > _max.z() )
243 _max.z() = point.z();
248 _min = std::numeric_limits< T >::max();
249 _max = -std::numeric_limits< T >::max();
254 return _min.x() >= _max.x() || _min.y() >= _max.y() || _min.z() >= _max.x();
257 template<
typename T >
inline void
261 for(
size_t i = 0; i < 3; ++i )
263 if( plane[ i ] >= 0.0 )
265 nearPoint[ i ] = _min[ i ];
266 farPoint[ i ] = _max[ i ];
270 nearPoint[ i ] = _max[ i ];
271 farPoint[ i ] = _min[ i ];
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
heavily inspired by boost::enable_if http://www.boost.org, file: boost/utility/enable_if.hpp, Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine
AABB()
Create an empty bounding box.
An axis-aligned bounding box.
const vector< 3, T > & getMin() const
bool operator==(const AABB< T > &other) 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.