14 #ifndef OSG_BOUNDINGSPHERE
15 #define OSG_BOUNDINGSPHERE 1
25 class BoundingBoxImpl;
34 class BoundingSphereImpl
58 _center.set(0.0,0.0,0.0);
64 inline bool valid()
const {
return _radius>=0.0; }
95 template<
typename vector_type>
101 template<
typename vector_type>
116 template<
typename BBT>
121 template<
typename BBT>
135 return valid() && bs.valid() &&
136 ((_center - bs._center).length2() <= (_radius + bs._radius)*(_radius + bs._radius));
141 template<
typename VT>
142 template<
typename vector_type>
152 _center += dv*(dr/r);
163 template<
typename VT>
164 template<
typename vector_type>
170 if (r>_radius) _radius = r;
180 template<
typename VT>
184 if (!sh.valid())
return;
189 _center = sh._center;
190 _radius = sh._radius;
197 double d = ( _center - sh.center() ).length();
200 if ( d + sh.radius() <= _radius )
206 if ( d + _radius <= sh.radius() )
208 _center = sh._center;
209 _radius = sh._radius;
220 double new_radius = (_radius + d + sh.radius() ) * 0.5;
221 double ratio = ( new_radius - _radius ) / d ;
223 _center[0] += ( sh.center()[0] - _center[0] ) * ratio;
224 _center[1] += ( sh.center()[1] - _center[1] ) * ratio;
225 _center[2] += ( sh.center()[2] - _center[2] ) * ratio;
227 _radius = new_radius;
231 template<
typename VT>
238 value_type r = (sh._center-_center).length()+sh._radius;
239 if (r>_radius) _radius = r;
244 _center = sh._center;
245 _radius = sh._radius;
250 template<
typename VT>
251 template<
typename BBT>
260 for(
unsigned int c=0;c<8;++c)
281 template<
typename VT>
282 template<
typename BBT>
289 for(
unsigned int c=0;c<8;++c)
291 expandRadiusBy(bb.
corner(c));
305 #ifdef OSG_USE_FLOAT_BOUNDINGSPHERE
value_type radius2() const
value_type radius() const
bool contains(const vec_type &v) const
BoundingSphereImpl< Vec3d > BoundingSphered
BoundingSphereImpl< Vec3f > BoundingSpheref
value_type radius() const
void expandRadiusBy(const vector_type &v)
BoundingSphereImpl(const BoundingSphereImpl &bs)
bool operator==(const BoundingSphereImpl &rhs) const
const vec_type & center() const
void expandBy(const vec_type &v)
VT::value_type value_type
void set(const vec_type ¢er, value_type radius)
const vec_type corner(unsigned int pos) const
BoundingSphered BoundingSphere
bool intersects(const BoundingSphereImpl &bs) const
bool operator!=(const BoundingSphereImpl &rhs) const
BoundingSphereImpl(const BoundingBoxImpl< VT > &bb)
const vec_type center() const
void expandBy(const vector_type &v)
BoundingSphereImpl(const vec_type ¢er, value_type radius)