Changeset 13041 for OpenSceneGraph/trunk/include/osg/BoundingSphere
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/BoundingSphere (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/BoundingSphere
r10228 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 36 36 public: 37 37 typedef VT vec_type; 38 typedef typename VT::value_type value_type; 38 typedef typename VT::value_type value_type; 39 39 40 40 vec_type _center; 41 41 value_type _radius; 42 42 43 /** Construct a default bounding sphere with radius to -1.0f, representing an invalid/unset bounding sphere.*/ 43 /** Construct a default bounding sphere with radius to -1.0f, representing an invalid/unset bounding sphere.*/ 44 44 BoundingSphereImpl() : _center(0.0,0.0,0.0),_radius(-1.0) {} 45 45 46 46 /** Creates a bounding sphere initialized to the given extents. */ 47 47 BoundingSphereImpl(const vec_type& center, value_type radius) : _center(center),_radius(radius) {} … … 64 64 inline bool valid() const { return _radius>=0.0; } 65 65 66 /** Set the bounding sphere to the given center/radius using floats. */ 66 /** Set the bounding sphere to the given center/radius using floats. */ 67 67 inline void set(const vec_type& center,value_type radius) 68 68 { … … 73 73 /** Returns the center of the bounding sphere. */ 74 74 inline vec_type& center() { return _center; } 75 75 76 76 /** Returns the const center of the bounding sphere. */ 77 77 inline const vec_type& center() const { return _center; } … … 81 81 /** Returns the const radius of the bounding sphere. */ 82 82 inline value_type radius() const { return _radius; } 83 83 84 84 /** Returns the squared length of the radius. Note, For performance 85 85 * reasons, the calling method is responsible for checking to make … … 131 131 ((_center - bs._center).length2() <= (_radius + bs._radius)*(_radius + bs._radius)); 132 132 } 133 133 134 134 }; 135 135 … … 188 188 return; 189 189 } 190 191 192 // Calculate d == The distance between the sphere centers 190 191 192 // Calculate d == The distance between the sphere centers 193 193 double d = ( _center - sh.center() ).length(); 194 194 195 195 // New sphere is already inside this one 196 if ( d + sh.radius() <= _radius ) 196 if ( d + sh.radius() <= _radius ) 197 197 { 198 198 return; 199 199 } 200 200 201 // New sphere completely contains this one 202 if ( d + _radius <= sh.radius() ) 201 // New sphere completely contains this one 202 if ( d + _radius <= sh.radius() ) 203 203 { 204 204 _center = sh._center; … … 207 207 } 208 208 209 209 210 210 // Build a new sphere that completely contains the other two: 211 211 // … … 244 244 } 245 245 246 template<typename VT> 246 template<typename VT> 247 247 void BoundingSphereImpl<VT>::expandBy(const BoundingBoxImpl<VT>& bb) 248 248 { … … 261 261 newbb.expandBy(v); // add it into the new bounding box. 262 262 } 263 263 264 264 _center = newbb.center(); 265 265 _radius = newbb.radius(); 266 266 267 267 } 268 268 else … … 300 300 typedef BoundingSpheref BoundingSphere; 301 301 #else 302 typedef BoundingSphered BoundingSphere; 302 typedef BoundingSphered BoundingSphere; 303 303 #endif 304 304 }
