Panda3D
boundingHexahedron.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file boundingHexahedron.h
10  * @author drose
11  * @date 1999-10-03
12  */
13 
14 #ifndef BOUNDINGHEXAHEDRON_H
15 #define BOUNDINGHEXAHEDRON_H
16 
17 #include "pandabase.h"
18 
19 #include "finiteBoundingVolume.h"
20 #include "frustum.h"
21 #include "plane.h"
22 
23 #include "coordinateSystem.h"
24 
25 
26 /**
27  * This defines a bounding convex hexahedron. It is typically used to
28  * represent a frustum, but may represent any enclosing convex hexahedron,
29  * including simple boxes. However, if all you want is an axis-aligned
30  * bounding box, you may be better off with the simpler BoundingBox class.
31  */
32 class EXPCL_PANDA_MATHUTIL BoundingHexahedron : public FiniteBoundingVolume {
33 public:
34  INLINE_MATHUTIL BoundingHexahedron();
35 
36 PUBLISHED:
37  BoundingHexahedron(const LFrustum &frustum, bool is_ortho,
38  CoordinateSystem cs = CS_default);
39  BoundingHexahedron(const LPoint3 &fll, const LPoint3 &flr,
40  const LPoint3 &fur, const LPoint3 &ful,
41  const LPoint3 &nll, const LPoint3 &nlr,
42  const LPoint3 &nur, const LPoint3 &nul);
43 
44 public:
45  ALLOC_DELETED_CHAIN(BoundingHexahedron);
46  virtual BoundingVolume *make_copy() const;
47 
48  virtual LPoint3 get_min() const;
49  virtual LPoint3 get_max() const;
50 
51  virtual LPoint3 get_approx_center() const;
52  virtual void xform(const LMatrix4 &mat);
53 
54  virtual void output(std::ostream &out) const;
55  virtual void write(std::ostream &out, int indent_level = 0) const;
56 
57 PUBLISHED:
58  INLINE_MATHUTIL int get_num_points() const;
59  INLINE_MATHUTIL LPoint3 get_point(int n) const;
60  MAKE_SEQ(get_points, get_num_points, get_point);
61  INLINE_MATHUTIL int get_num_planes() const;
62  INLINE_MATHUTIL LPlane get_plane(int n) const;
63  MAKE_SEQ(get_planes, get_num_planes, get_plane);
64 
65  MAKE_SEQ_PROPERTY(points, get_num_points, get_point);
66  MAKE_SEQ_PROPERTY(planes, get_num_planes, get_plane);
67 
68 public:
69  virtual const BoundingHexahedron *as_bounding_hexahedron() const;
70 
71 protected:
72  virtual bool extend_other(BoundingVolume *other) const;
73  virtual bool around_other(BoundingVolume *other,
74  const BoundingVolume **first,
75  const BoundingVolume **last) const;
76  virtual int contains_other(const BoundingVolume *other) const;
77 
78  virtual int contains_point(const LPoint3 &point) const;
79  virtual int contains_lineseg(const LPoint3 &a, const LPoint3 &b) const;
80  virtual int contains_sphere(const BoundingSphere *sphere) const;
81  virtual int contains_box(const BoundingBox *box) const;
82  virtual int contains_plane(const BoundingPlane *plane) const;
83  virtual int contains_hexahedron(const BoundingHexahedron *hexahedron) const;
84 
85 private:
86  void set_planes();
87  void set_centroid();
88 
89 private:
90  enum {
91  num_points = 8,
92  num_planes = 6
93  };
94  LPoint3 _points[num_points];
95  LPlane _planes[num_planes];
96  LPoint3 _centroid;
97 
98 
99 public:
100  static TypeHandle get_class_type() {
101  return _type_handle;
102  }
103  static void init_type() {
104  FiniteBoundingVolume::init_type();
105  register_type(_type_handle, "BoundingHexahedron",
106  FiniteBoundingVolume::get_class_type());
107  }
108  virtual TypeHandle get_type() const {
109  return get_class_type();
110  }
111  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
112 
113 private:
114  static TypeHandle _type_handle;
115 
116  friend class BoundingSphere;
117  friend class BoundingBox;
118 };
119 
120 #include "boundingHexahedron.I"
121 
122 #endif
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
Definition: boundingBox.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a bounding sphere, consisting of a center and a radius.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual const BoundingHexahedron * as_bounding_hexahedron() const
Virtual downcast method.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This funny bounding volume is an infinite plane that divides space into two regions: the part behind ...
Definition: boundingPlane.h:28
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A special kind of GeometricBoundingVolume that is known to be finite.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This defines a bounding convex hexahedron.