Panda3D

boundingBox.h

00001 // Filename: boundingBox.h
00002 // Created by:  drose (31May07)
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 BOUNDINGBOX_H
00016 #define BOUNDINGBOX_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "finiteBoundingVolume.h"
00021 #include "plane.h"
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //       Class : BoundingBox
00025 // Description : An axis-aligned bounding box; that is, a minimum and
00026 //               maximum coordinate triple.
00027 //
00028 //               This box is always axis-aligned.  If you need a more
00029 //               general bounding box, try BoundingHexahedron.
00030 ////////////////////////////////////////////////////////////////////
00031 class EXPCL_PANDA_MATHUTIL BoundingBox : public FiniteBoundingVolume {
00032 PUBLISHED:
00033   INLINE_MATHUTIL BoundingBox();
00034   INLINE_MATHUTIL BoundingBox(const LPoint3f &min, const LPoint3f &max);
00035   ALLOC_DELETED_CHAIN(BoundingBox);
00036 
00037 public:
00038   virtual BoundingVolume *make_copy() const;
00039 
00040   virtual LPoint3f get_min() const;
00041   virtual LPoint3f get_max() const;
00042   virtual float get_volume() const;
00043 
00044   virtual LPoint3f get_approx_center() const;
00045   virtual void xform(const LMatrix4f &mat);
00046 
00047   virtual void output(ostream &out) const;
00048 
00049 PUBLISHED:
00050   INLINE_MATHUTIL int get_num_points() const;
00051   INLINE_MATHUTIL LPoint3f get_point(int n) const;
00052   MAKE_SEQ(get_points, get_num_points, get_point);
00053   INLINE_MATHUTIL int get_num_planes() const;
00054   INLINE_MATHUTIL Planef get_plane(int n) const;
00055   MAKE_SEQ(get_planes, get_num_planes, get_plane);
00056 
00057 public:
00058   // Inline accessors for speed.
00059   INLINE_MATHUTIL const LPoint3f &get_minq() const;
00060   INLINE_MATHUTIL const LPoint3f &get_maxq() const;
00061 
00062 public:
00063   virtual const BoundingBox *as_bounding_box() const;
00064 
00065 protected:
00066   virtual bool extend_other(BoundingVolume *other) const;
00067   virtual bool around_other(BoundingVolume *other,
00068                             const BoundingVolume **first,
00069                             const BoundingVolume **last) const;
00070   virtual int contains_other(const BoundingVolume *other) const;
00071 
00072 
00073   virtual bool extend_by_point(const LPoint3f &point);
00074   virtual bool extend_by_sphere(const BoundingSphere *sphere);
00075   virtual bool extend_by_box(const BoundingBox *box);
00076   virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron);
00077   bool extend_by_finite(const FiniteBoundingVolume *volume);
00078 
00079   virtual bool around_points(const LPoint3f *first,
00080                              const LPoint3f *last);
00081   virtual bool around_spheres(const BoundingVolume **first,
00082                               const BoundingVolume **last);
00083   virtual bool around_boxes(const BoundingVolume **first,
00084                             const BoundingVolume **last);
00085   virtual bool around_hexahedrons(const BoundingVolume **first,
00086                                   const BoundingVolume **last);
00087   bool around_finite(const BoundingVolume **first,
00088                      const BoundingVolume **last);
00089 
00090   virtual int contains_point(const LPoint3f &point) const;
00091   virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const;
00092   virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00093   virtual int contains_sphere(const BoundingSphere *sphere) const;
00094   virtual int contains_box(const BoundingBox *box) const;
00095   virtual int contains_line(const BoundingLine *line) const;
00096   virtual int contains_plane(const BoundingPlane *plane) const;
00097   int contains_finite(const FiniteBoundingVolume *volume) const;
00098 
00099 private:
00100   LPoint3f _min;
00101   LPoint3f _max;
00102 
00103   static const int plane_def[6][3];
00104 
00105 public:
00106   static TypeHandle get_class_type() {
00107     return _type_handle;
00108   }
00109   static void init_type() {
00110     FiniteBoundingVolume::init_type();
00111     register_type(_type_handle, "BoundingBox",
00112                   FiniteBoundingVolume::get_class_type());
00113   }
00114   virtual TypeHandle get_type() const {
00115     return get_class_type();
00116   }
00117   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00118 
00119 private:
00120   static TypeHandle _type_handle;
00121 
00122   friend class BoundingSphere;
00123 };
00124 
00125 #include "boundingBox.I"
00126 
00127 #endif
 All Classes Functions Variables Enumerations