00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef BOUNDINGVOLUME_H
00016 #define BOUNDINGVOLUME_H
00017
00018 #include "pandabase.h"
00019
00020 #include "typedObject.h"
00021 #include "typedReferenceCount.h"
00022 #include "deletedChain.h"
00023
00024 class GeometricBoundingVolume;
00025 class FiniteBoundingVolume;
00026 class BoundingSphere;
00027 class BoundingBox;
00028 class BoundingHexahedron;
00029 class BoundingLine;
00030 class BoundingPlane;
00031 class UnionBoundingVolume;
00032 class IntersectionBoundingVolume;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class EXPCL_PANDA_MATHUTIL BoundingVolume : public TypedReferenceCount {
00046 public:
00047 INLINE_MATHUTIL BoundingVolume();
00048
00049 PUBLISHED:
00050 virtual BoundingVolume *make_copy() const=0;
00051
00052 INLINE_MATHUTIL bool is_empty() const;
00053 INLINE_MATHUTIL bool is_infinite() const;
00054
00055 INLINE_MATHUTIL void set_infinite();
00056
00057 INLINE_MATHUTIL bool extend_by(const BoundingVolume *vol);
00058
00059
00060
00061
00062 bool around(const BoundingVolume **first,
00063 const BoundingVolume **last);
00064
00065
00066
00067 enum IntersectionFlags {
00068
00069 IF_no_intersection = 0,
00070
00071
00072 IF_possible = 0x01,
00073
00074
00075
00076 IF_some = 0x02,
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 IF_all = 0x04,
00091
00092
00093
00094 IF_dont_understand = 0x08
00095 };
00096
00097 INLINE_MATHUTIL int contains(const BoundingVolume *vol) const;
00098
00099 virtual void output(ostream &out) const=0;
00100 virtual void write(ostream &out, int indent_level = 0) const;
00101
00102
00103
00104 enum BoundsType {
00105 BT_default,
00106 BT_best,
00107 BT_sphere,
00108 BT_box,
00109 };
00110
00111 public:
00112 virtual const GeometricBoundingVolume *as_geometric_bounding_volume() const;
00113 virtual const FiniteBoundingVolume *as_finite_bounding_volume() const;
00114 virtual const BoundingSphere *as_bounding_sphere() const;
00115 virtual const BoundingBox *as_bounding_box() const;
00116 virtual const BoundingHexahedron *as_bounding_hexahedron() const;
00117 virtual const BoundingLine *as_bounding_line() const;
00118 virtual const BoundingPlane *as_bounding_plane() const;
00119
00120 static BoundsType string_bounds_type(const string &str);
00121
00122 protected:
00123 enum Flags {
00124 F_empty = 0x01,
00125 F_infinite = 0x02
00126 };
00127 int _flags;
00128
00129 protected:
00130
00131
00132
00133
00134
00135 virtual bool extend_other(BoundingVolume *other) const=0;
00136 virtual bool around_other(BoundingVolume *other,
00137 const BoundingVolume **first,
00138 const BoundingVolume **last) const=0;
00139 virtual int contains_other(const BoundingVolume *other) const=0;
00140
00141
00142
00143 virtual bool extend_by_sphere(const BoundingSphere *sphere);
00144 virtual bool extend_by_box(const BoundingBox *box);
00145 virtual bool extend_by_hexahedron(const BoundingHexahedron *hexahedron);
00146 virtual bool extend_by_line(const BoundingLine *line);
00147 virtual bool extend_by_plane(const BoundingPlane *plane);
00148 virtual bool extend_by_union(const UnionBoundingVolume *unionv);
00149 virtual bool extend_by_intersection(const IntersectionBoundingVolume *intersection);
00150 virtual bool extend_by_finite(const FiniteBoundingVolume *volume);
00151 virtual bool extend_by_geometric(const GeometricBoundingVolume *volume);
00152
00153 virtual bool around_spheres(const BoundingVolume **first,
00154 const BoundingVolume **last);
00155 virtual bool around_boxes(const BoundingVolume **first,
00156 const BoundingVolume **last);
00157 virtual bool around_hexahedrons(const BoundingVolume **first,
00158 const BoundingVolume **last);
00159 virtual bool around_lines(const BoundingVolume **first,
00160 const BoundingVolume **last);
00161 virtual bool around_planes(const BoundingVolume **first,
00162 const BoundingVolume **last);
00163 virtual bool around_unions(const BoundingVolume **first,
00164 const BoundingVolume **last);
00165 virtual bool around_intersections(const BoundingVolume **first,
00166 const BoundingVolume **last);
00167 virtual bool around_finite(const BoundingVolume **first,
00168 const BoundingVolume **last);
00169 virtual bool around_geometric(const BoundingVolume **first,
00170 const BoundingVolume **last);
00171
00172 virtual int contains_sphere(const BoundingSphere *sphere) const;
00173 virtual int contains_box(const BoundingBox *box) const;
00174 virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
00175 virtual int contains_line(const BoundingLine *line) const;
00176 virtual int contains_plane(const BoundingPlane *plane) const;
00177 virtual int contains_union(const UnionBoundingVolume *unionv) const;
00178 virtual int contains_intersection(const IntersectionBoundingVolume *intersection) const;
00179 virtual int contains_finite(const FiniteBoundingVolume *volume) const;
00180 virtual int contains_geometric(const GeometricBoundingVolume *volume) const;
00181
00182
00183 public:
00184 static TypeHandle get_class_type() {
00185 return _type_handle;
00186 }
00187 static void init_type() {
00188 TypedReferenceCount::init_type();
00189 register_type(_type_handle, "BoundingVolume",
00190 TypedReferenceCount::get_class_type());
00191 }
00192 virtual TypeHandle get_type() const {
00193 return get_class_type();
00194 }
00195 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00196
00197 private:
00198 static TypeHandle _type_handle;
00199
00200 friend class BoundingSphere;
00201 friend class BoundingBox;
00202 friend class BoundingHexahedron;
00203 friend class BoundingLine;
00204 friend class BoundingPlane;
00205 friend class UnionBoundingVolume;
00206 friend class IntersectionBoundingVolume;
00207 };
00208
00209 INLINE_MATHUTIL ostream &operator << (ostream &out, const BoundingVolume &bound);
00210
00211 #include "boundingVolume.I"
00212
00213 EXPCL_PANDA_MATHUTIL ostream &operator << (ostream &out, BoundingVolume::BoundsType type);
00214 EXPCL_PANDA_MATHUTIL istream &operator >> (istream &in, BoundingVolume::BoundsType &type);
00215
00216 #endif