Changeset 8038 for OpenSceneGraph/trunk/include/osg/BoundingSphere
- Timestamp:
- 04/03/08 20:36:50 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/BoundingSphere (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/BoundingSphere
r5328 r8038 16 16 17 17 #include <osg/Export> 18 #include <osg/Vec3> 18 #include <osg/Vec3f> 19 #include <osg/Vec3d> 19 20 20 21 namespace osg { … … 31 32 { 32 33 public: 34 35 #ifdef OSG_USE_DOUBLE_BOUNDINGSPHERE 36 typedef Vec3d vec_type; 37 typedef double value_type; 38 #else 39 typedef Vec3f vec_type; 40 typedef float value_type; 41 #endif 33 42 34 Vec3_center;35 float_radius;43 vec_type _center; 44 value_type _radius; 36 45 37 46 /** Construct a default bounding sphere with radius to -1.0f, representing an invalid/unset bounding sphere.*/ 38 BoundingSphere() : _center(0.0 f,0.0f,0.0f),_radius(-1.0f) {}47 BoundingSphere() : _center(0.0,0.0,0.0),_radius(-1.0) {} 39 48 40 49 /** Creates a bounding sphere initialized to the given extents. */ 41 BoundingSphere(const Vec3& center,floatradius) : _center(center),_radius(radius) {}50 BoundingSphere(const vec_type& center,value_type radius) : _center(center),_radius(radius) {} 42 51 43 52 /** Creates a bounding sphere initialized to the given extents. */ … … 45 54 46 55 /** Creates a bounding sphere initialized to the given extents. */ 47 BoundingSphere(const BoundingBox& bb) : _center(0.0 f,0.0f,0.0f),_radius(-1.0f) { expandBy(bb); }56 BoundingSphere(const BoundingBox& bb) : _center(0.0,0.0,0.0),_radius(-1.0) { expandBy(bb); } 48 57 49 58 /** Clear the bounding sphere. Reset to default values. */ 50 59 inline void init() 51 60 { 52 _center.set(0.0 f,0.0f,0.0f);53 _radius = -1.0 f;61 _center.set(0.0,0.0,0.0); 62 _radius = -1.0; 54 63 } 55 64 56 65 /** Returns true of the bounding sphere extents are valid, false 57 66 * otherwise. */ 58 inline bool valid() const { return _radius>=0.0 f; }67 inline bool valid() const { return _radius>=0.0; } 59 68 60 /** Set the bounding sphere to the given center/radius . */61 inline void set(const Vec3& center,floatradius)69 /** Set the bounding sphere to the given center/radius using floats. */ 70 inline void set(const vec_type& center,value_type radius) 62 71 { 63 72 _center = center; … … 66 75 67 76 /** Returns the center of the bounding sphere. */ 68 inline Vec3& center() { return _center; } 77 inline vec_type& center() { return _center; } 78 69 79 /** Returns the const center of the bounding sphere. */ 70 inline const Vec3& center() const { return _center; }80 inline const vec_type& center() const { return _center; } 71 81 72 82 /** Returns the radius of the bounding sphere. */ 73 inline float& radius() { return _radius; }83 inline value_type& radius() { return _radius; } 74 84 /** Returns the const radius of the bounding sphere. */ 75 inline floatradius() const { return _radius; }85 inline value_type radius() const { return _radius; } 76 86 77 87 /** Returns the squared length of the radius. Note, For performance 78 88 * reasons, the calling method is responsible for checking to make 79 89 * sure the sphere is valid. */ 80 inline floatradius2() const { return _radius*_radius; }90 inline value_type radius2() const { return _radius*_radius; } 81 91 82 92 /** Expands the sphere to encompass the given point. Repositions the 83 93 * sphere center to minimize the radius increase. If the sphere is 84 94 * uninitialized, set its center to v and radius to zero. */ 85 void expandBy(const Vec3 & v);95 void expandBy(const Vec3f& v); 86 96 87 97 /** Expands the sphere to encompass the given point. Does not 88 98 * reposition the sphere center. If the sphere is 89 99 * uninitialized, set its center to v and radius to zero. */ 90 void expandRadiusBy(const Vec3& v); 100 void expandRadiusBy(const Vec3f& v); 101 102 /** Expands the sphere to encompass the given point. Repositions the 103 * sphere center to minimize the radius increase. If the sphere is 104 * uninitialized, set its center to v and radius to zero. */ 105 void expandBy(const Vec3d& v); 106 107 /** Expands the sphere to encompass the given point. Does not 108 * reposition the sphere center. If the sphere is 109 * uninitialized, set its center to v and radius to zero. */ 110 void expandRadiusBy(const Vec3d& v); 91 111 92 112 /** Expands the sphere to encompass the given sphere. Repositions the … … 109 129 110 130 /** Returns true if v is within the sphere. */ 111 inline bool contains(const Vec3& v) const131 inline bool contains(const vec_type& v) const 112 132 { 113 133 return valid() && ((v-_center).length2()<=radius2()); 114 134 } 135 115 136 116 137 /** Returns true if there is a non-empty intersection with the given
