Panda3D
|
00001 // Filename: boundingHexahedron.h 00002 // Created by: drose (03Oct99) 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 BOUNDINGHEXAHEDRON_H 00016 #define BOUNDINGHEXAHEDRON_H 00017 00018 #include "pandabase.h" 00019 00020 #include "finiteBoundingVolume.h" 00021 #include "frustum.h" 00022 #include "plane.h" 00023 00024 #include "coordinateSystem.h" 00025 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : BoundingHexahedron 00029 // Description : This defines a bounding convex hexahedron. It is 00030 // typically used to represent a frustum, but may 00031 // represent any enclosing convex hexahedron, including 00032 // simple boxes. However, if all you want is an 00033 // axis-aligned bounding box, you may be better off with 00034 // the simpler BoundingBox class. 00035 //////////////////////////////////////////////////////////////////// 00036 class EXPCL_PANDA_MATHUTIL BoundingHexahedron : public FiniteBoundingVolume { 00037 public: 00038 INLINE_MATHUTIL BoundingHexahedron(); 00039 00040 PUBLISHED: 00041 BoundingHexahedron(const LFrustum &frustum, bool is_ortho, 00042 CoordinateSystem cs = CS_default); 00043 BoundingHexahedron(const LPoint3 &fll, const LPoint3 &flr, 00044 const LPoint3 &fur, const LPoint3 &ful, 00045 const LPoint3 &nll, const LPoint3 &nlr, 00046 const LPoint3 &nur, const LPoint3 &nul); 00047 00048 public: 00049 ALLOC_DELETED_CHAIN(BoundingHexahedron); 00050 virtual BoundingVolume *make_copy() const; 00051 00052 virtual LPoint3 get_min() const; 00053 virtual LPoint3 get_max() const; 00054 00055 virtual LPoint3 get_approx_center() const; 00056 virtual void xform(const LMatrix4 &mat); 00057 00058 virtual void output(ostream &out) const; 00059 virtual void write(ostream &out, int indent_level = 0) const; 00060 00061 PUBLISHED: 00062 INLINE_MATHUTIL int get_num_points() const; 00063 INLINE_MATHUTIL LPoint3 get_point(int n) const; 00064 MAKE_SEQ(get_points, get_num_points, get_point); 00065 INLINE_MATHUTIL int get_num_planes() const; 00066 INLINE_MATHUTIL LPlane get_plane(int n) const; 00067 MAKE_SEQ(get_planes, get_num_planes, get_plane); 00068 00069 public: 00070 virtual const BoundingHexahedron *as_bounding_hexahedron() const; 00071 00072 protected: 00073 virtual bool extend_other(BoundingVolume *other) const; 00074 virtual bool around_other(BoundingVolume *other, 00075 const BoundingVolume **first, 00076 const BoundingVolume **last) const; 00077 virtual int contains_other(const BoundingVolume *other) const; 00078 00079 virtual int contains_point(const LPoint3 &point) const; 00080 virtual int contains_lineseg(const LPoint3 &a, const LPoint3 &b) const; 00081 virtual int contains_sphere(const BoundingSphere *sphere) const; 00082 virtual int contains_box(const BoundingBox *box) const; 00083 virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const; 00084 00085 private: 00086 void set_planes(); 00087 void set_centroid(); 00088 00089 private: 00090 enum { 00091 num_points = 8, 00092 num_planes = 6 00093 }; 00094 LPoint3 _points[num_points]; 00095 LPlane _planes[num_planes]; 00096 LPoint3 _centroid; 00097 00098 00099 public: 00100 static TypeHandle get_class_type() { 00101 return _type_handle; 00102 } 00103 static void init_type() { 00104 FiniteBoundingVolume::init_type(); 00105 register_type(_type_handle, "BoundingHexahedron", 00106 FiniteBoundingVolume::get_class_type()); 00107 } 00108 virtual TypeHandle get_type() const { 00109 return get_class_type(); 00110 } 00111 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00112 00113 private: 00114 static TypeHandle _type_handle; 00115 00116 friend class BoundingSphere; 00117 friend class BoundingBox; 00118 }; 00119 00120 #include "boundingHexahedron.I" 00121 00122 #endif