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 93 bool operator==(
const AABB< T >& other )
const;
96 bool operator!=(
const AABB< T >& other )
const;
117 template<
class U >
friend void lunchbox::byteswap( U& );
120 template<
typename T >
inline 121 std::ostream& operator << ( std::ostream& os, const AABB< T >& aabb )
123 return os << aabb.getMin() <<
" - " << aabb.getMax();
127 : _min(
std::numeric_limits< T >::max( ))
128 , _max(
std::numeric_limits< T >::min( ))
132 : _min( std::numeric_limits< float >::max( ))
133 , _max( -std::numeric_limits< float >::max( ))
137 : _min( std::numeric_limits< double >::max( ))
138 , _max( -std::numeric_limits< double >::max( ))
141 template<
typename T >
143 : _min(
vector< 3, T >(
std::min( pMin[0], pMax[0] ),
144 std::min( pMin[1], pMax[1] ),
145 std::min( pMin[2], pMax[2] )))
146 , _max(
vector< 3, T >(
std::max( pMin[0], pMax[0] ),
147 std::max( pMin[1], pMax[1] ),
148 std::max( pMin[2], pMax[2] )))
153 _max = _min = sphere.getCenter();
154 _max += sphere.getRadius();
155 _min -= sphere.getRadius();
160 if ( pos.x() > _max.x() || pos.y() > _max.y() || pos.z() > _max.z() ||
161 pos.x() < _min.x() || pos.y() < _min.y() || pos.z() < _min.z( ))
168 template<
typename T >
inline 172 sv += sphere.getRadius();
173 if ( sv.x() > _max.x() || sv.y() > _max.y() || sv.z() > _max.z() )
175 sv -= sphere.getRadius() * 2.0f;
176 if ( sv.x() < _min.x() || sv.y() < _min.y() || sv.z() < _min.z() )
181 template<
typename T >
inline 184 const auto& extent =
getSize() * 0.5f;
185 const float d = plane.dot(
getCenter() );
186 const float n = extent.x() * std::abs( plane.x( )) +
187 extent.y() * std::abs( plane.y( )) +
188 extent.z() * std::abs( plane.z( ));
190 return !( d - n >= 0 || d + n > 0 );
203 template<
typename T >
inline 206 return _min == other._min && _max == other._max;
209 template<
typename T >
inline 212 return _min != other._min || _max != other._max;
217 return ( _min + _max ) * 0.5f;
225 template<
typename T >
231 if ( min.x() < _min.x() )
233 if ( min.y() < _min.y() )
235 if ( min.z() < _min.z() )
238 if ( max.x() > _max.x() )
240 if ( max.y() > _max.y() )
242 if ( max.z() > _max.z() )
246 template<
typename T >
249 if ( point.x() < _min.x() )
250 _min.x() = point.x();
251 if ( point.y() < _min.y() )
252 _min.y() = point.y();
253 if ( point.z() < _min.z() )
254 _min.z() = point.z();
256 if ( point.x() > _max.x() )
257 _max.x() = point.x();
258 if ( point.y() > _max.y() )
259 _max.y() = point.y();
260 if ( point.z() > _max.z() )
261 _max.z() = point.z();
266 _min = std::numeric_limits< T >::max();
267 _max = -std::numeric_limits< T >::max();
272 return _min.x() >= _max.x() || _min.y() >= _max.y() || _min.z() >= _max.x();
275 template<
typename T >
inline void 280 for(
size_t i = 0; i < 3; ++i )
282 if( plane[ i ] >= 0.0 )
284 nearPoint[ i ] = _min[ i ];
285 farPoint[ i ] = _max[ i ];
289 nearPoint[ i ] = _max[ i ];
290 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
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.