00001 // Filename: boundingSphere.h 00002 // Created by: drose (01Oct99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef BOUNDINGSPHERE_H 00016 #define BOUNDINGSPHERE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "finiteBoundingVolume.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : BoundingSphere 00024 // Description : This defines a bounding sphere, consisting of a 00025 // center and a radius. It is always a sphere, and 00026 // never an ellipsoid or other quadric. 00027 //////////////////////////////////////////////////////////////////// 00028 class EXPCL_PANDA_MATHUTIL BoundingSphere : public FiniteBoundingVolume { 00029 PUBLISHED: 00030 INLINE_MATHUTIL BoundingSphere(); 00031 INLINE_MATHUTIL BoundingSphere(const LPoint3 ¢er, PN_stdfloat radius); 00032 ALLOC_DELETED_CHAIN(BoundingSphere); 00033 00034 public: 00035 virtual BoundingVolume *make_copy() const; 00036 00037 virtual LPoint3 get_min() const; 00038 virtual LPoint3 get_max() const; 00039 virtual PN_stdfloat get_volume() const; 00040 00041 virtual LPoint3 get_approx_center() const; 00042 virtual void xform(const LMatrix4 &mat); 00043 00044 virtual void output(ostream &out) const; 00045 00046 PUBLISHED: 00047 INLINE_MATHUTIL LPoint3 get_center() const; 00048 INLINE_MATHUTIL PN_stdfloat get_radius() const; 00049 00050 public: 00051 virtual const BoundingSphere *as_bounding_sphere() const; 00052 00053 protected: 00054 virtual bool extend_other(BoundingVolume *other) const; 00055 virtual bool around_other(BoundingVolume *other, 00056 const BoundingVolume **first, 00057 const BoundingVolume **last) const; 00058 virtual int contains_other(const BoundingVolume *other) const; 00059 00060 00061 virtual bool extend_by_point(const LPoint3 &point); 00062 virtual bool extend_by_sphere(const BoundingSphere *sphere); 00063 virtual bool extend_by_box(const BoundingBox *box); 00064 virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron); 00065 virtual bool extend_by_finite(const FiniteBoundingVolume *volume); 00066 00067 virtual bool around_points(const LPoint3 *first, 00068 const LPoint3 *last); 00069 virtual bool around_finite(const BoundingVolume **first, 00070 const BoundingVolume **last); 00071 00072 virtual int contains_point(const LPoint3 &point) const; 00073 virtual int contains_lineseg(const LPoint3 &a, const LPoint3 &b) const; 00074 virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; 00075 virtual int contains_sphere(const BoundingSphere *sphere) const; 00076 virtual int contains_box(const BoundingBox *box) const; 00077 virtual int contains_line(const BoundingLine *line) const; 00078 virtual int contains_plane(const BoundingPlane *plane) const; 00079 00080 private: 00081 LPoint3 _center; 00082 PN_stdfloat _radius; 00083 00084 00085 public: 00086 static TypeHandle get_class_type() { 00087 return _type_handle; 00088 } 00089 static void init_type() { 00090 FiniteBoundingVolume::init_type(); 00091 register_type(_type_handle, "BoundingSphere", 00092 FiniteBoundingVolume::get_class_type()); 00093 } 00094 virtual TypeHandle get_type() const { 00095 return get_class_type(); 00096 } 00097 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00098 00099 private: 00100 static TypeHandle _type_handle; 00101 00102 friend class BoundingHexahedron; 00103 }; 00104 00105 #include "boundingSphere.I" 00106 00107 #endif