00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BOUNDINGHEXAHEDRON_H
00020 #define BOUNDINGHEXAHEDRON_H
00021
00022 #include <pandabase.h>
00023
00024 #include "finiteBoundingVolume.h"
00025 #include "frustum.h"
00026 #include "plane.h"
00027
00028 #include <coordinateSystem.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class EXPCL_PANDA BoundingHexahedron : public FiniteBoundingVolume {
00042 public:
00043 INLINE_MATHUTIL BoundingHexahedron();
00044 BoundingHexahedron(const Frustumf &frustum, bool is_ortho,
00045 CoordinateSystem cs = CS_default);
00046 BoundingHexahedron(const LPoint3f &fll, const LPoint3f &flr,
00047 const LPoint3f &fur, const LPoint3f &ful,
00048 const LPoint3f &nll, const LPoint3f &nlr,
00049 const LPoint3f &nur, const LPoint3f &nul);
00050 virtual BoundingVolume *make_copy() const;
00051
00052 virtual LPoint3f get_min() const;
00053 virtual LPoint3f get_max() const;
00054
00055 virtual LPoint3f get_approx_center() const;
00056 virtual void xform(const LMatrix4f &mat);
00057
00058 virtual void output(ostream &out) const;
00059 virtual void write(ostream &out, int indent_level = 0) const;
00060
00061 INLINE_MATHUTIL int get_num_points() const;
00062 INLINE_MATHUTIL LPoint3f get_point(int n) const;
00063 INLINE_MATHUTIL int get_num_planes() const;
00064 INLINE_MATHUTIL Planef get_plane(int n) const;
00065
00066 protected:
00067 virtual bool extend_other(BoundingVolume *other) const;
00068 virtual bool around_other(BoundingVolume *other,
00069 const BoundingVolume **first,
00070 const BoundingVolume **last) const;
00071 virtual int contains_other(const BoundingVolume *other) const;
00072
00073
00074 virtual bool extend_by_point(const LPoint3f &point);
00075 virtual bool extend_by_sphere(const BoundingSphere *sphere);
00076 virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron);
00077
00078 virtual bool around_points(const LPoint3f *first,
00079 const LPoint3f *last);
00080 virtual bool around_spheres(const BoundingVolume **first,
00081 const BoundingVolume **last);
00082 virtual bool around_hexahedrons(const BoundingVolume **first,
00083 const BoundingVolume **last);
00084
00085 virtual int contains_point(const LPoint3f &point) const;
00086 virtual int contains_lineseg(const LPoint3f &a, const LPoint3f &b) const;
00087 virtual int contains_sphere(const BoundingSphere *sphere) const;
00088 virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00089
00090 private:
00091 void set_planes();
00092 void set_centroid();
00093
00094 private:
00095 enum {
00096 num_points = 8,
00097 num_planes = 6
00098 };
00099 LPoint3f _points[num_points];
00100 Planef _planes[num_planes];
00101 LPoint3f _centroid;
00102
00103
00104 public:
00105 static TypeHandle get_class_type() {
00106 return _type_handle;
00107 }
00108 static void init_type() {
00109 FiniteBoundingVolume::init_type();
00110 register_type(_type_handle, "BoundingHexahedron",
00111 FiniteBoundingVolume::get_class_type());
00112 }
00113 virtual TypeHandle get_type() const {
00114 return get_class_type();
00115 }
00116 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00117
00118 private:
00119 static TypeHandle _type_handle;
00120
00121 friend class BoundingSphere;
00122 };
00123
00124 #include "boundingHexahedron.I"
00125
00126 #endif