Panda3D
 All Classes Functions Variables Enumerations
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 LPoint3 &min, const LPoint3 &max);
00035   ALLOC_DELETED_CHAIN(BoundingBox);
00036 
00037 public:
00038   virtual BoundingVolume *make_copy() const;
00039 
00040   virtual LPoint3 get_min() const;
00041   virtual LPoint3 get_max() const;
00042   virtual PN_stdfloat get_volume() const;
00043 
00044   virtual LPoint3 get_approx_center() const;
00045   virtual void xform(const LMatrix4 &mat);
00046 
00047   virtual void output(ostream &out) const;
00048 
00049 PUBLISHED:
00050   INLINE_MATHUTIL int get_num_points() const;
00051   INLINE_MATHUTIL LPoint3 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 LPlane 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 LPoint3 &get_minq() const;
00060   INLINE_MATHUTIL const LPoint3 &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 LPoint3 &point);
00074   virtual bool extend_by_box(const BoundingBox *box);
00075   virtual bool extend_by_finite(const FiniteBoundingVolume *volume);
00076 
00077   virtual bool around_points(const LPoint3 *first,
00078                              const LPoint3 *last);
00079   virtual bool around_finite(const BoundingVolume **first,
00080                              const BoundingVolume **last);
00081 
00082   virtual int contains_point(const LPoint3 &point) const;
00083   virtual int contains_lineseg(const LPoint3 &a, const LPoint3 &b) const;
00084   virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00085   virtual int contains_box(const BoundingBox *box) const;
00086   virtual int contains_line(const BoundingLine *line) const;
00087   virtual int contains_plane(const BoundingPlane *plane) const;
00088   virtual int contains_finite(const FiniteBoundingVolume *volume) const;
00089 
00090 private:
00091   LPoint3 _min;
00092   LPoint3 _max;
00093 
00094   static const int plane_def[6][3];
00095 
00096 public:
00097   static TypeHandle get_class_type() {
00098     return _type_handle;
00099   }
00100   static void init_type() {
00101     FiniteBoundingVolume::init_type();
00102     register_type(_type_handle, "BoundingBox",
00103                   FiniteBoundingVolume::get_class_type());
00104   }
00105   virtual TypeHandle get_type() const {
00106     return get_class_type();
00107   }
00108   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00109 
00110 private:
00111   static TypeHandle _type_handle;
00112 
00113   friend class BoundingSphere;
00114 };
00115 
00116 #include "boundingBox.I"
00117 
00118 #endif
 All Classes Functions Variables Enumerations