Panda3D

boundingSphere.h

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 LPoint3f &center, float radius);
00032   ALLOC_DELETED_CHAIN(BoundingSphere);
00033 
00034 public:
00035   virtual BoundingVolume *make_copy() const;
00036 
00037   virtual LPoint3f get_min() const;
00038   virtual LPoint3f get_max() const;
00039   virtual float get_volume() const;
00040 
00041   virtual LPoint3f get_approx_center() const;
00042   virtual void xform(const LMatrix4f &mat);
00043 
00044   virtual void output(ostream &out) const;
00045 
00046 PUBLISHED:
00047   INLINE_MATHUTIL LPoint3f get_center() const;
00048   INLINE_MATHUTIL float 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 LPoint3f &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   bool extend_by_finite(const FiniteBoundingVolume *volume);
00066 
00067   virtual bool around_points(const LPoint3f *first,
00068                              const LPoint3f *last);
00069   virtual bool around_spheres(const BoundingVolume **first,
00070                               const BoundingVolume **last);
00071   virtual bool around_boxes(const BoundingVolume **first,
00072                             const BoundingVolume **last);
00073   virtual bool around_hexahedrons(const BoundingVolume **first,
00074                                   const BoundingVolume **last);
00075   bool around_finite(const BoundingVolume **first,
00076                      const BoundingVolume **last);
00077 
00078   virtual int contains_point(const LPoint3f &point) const;
00079   virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const;
00080   virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00081   virtual int contains_sphere(const BoundingSphere *sphere) const;
00082   virtual int contains_box(const BoundingBox *box) const;
00083   virtual int contains_line(const BoundingLine *line) const;
00084   virtual int contains_plane(const BoundingPlane *plane) const;
00085 
00086 private:
00087   LPoint3f _center;
00088   float _radius;
00089 
00090 
00091 public:
00092   static TypeHandle get_class_type() {
00093     return _type_handle;
00094   }
00095   static void init_type() {
00096     FiniteBoundingVolume::init_type();
00097     register_type(_type_handle, "BoundingSphere",
00098                   FiniteBoundingVolume::get_class_type());
00099   }
00100   virtual TypeHandle get_type() const {
00101     return get_class_type();
00102   }
00103   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00104 
00105 private:
00106   static TypeHandle _type_handle;
00107 
00108   friend class BoundingHexahedron;
00109 };
00110 
00111 #include "boundingSphere.I"
00112 
00113 #endif
 All Classes Functions Variables Enumerations