Panda3D
 All Classes Functions Variables Enumerations
collisionSolid.h
1 // Filename: collisionSolid.h
2 // Created by: drose (24Apr00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONSOLID_H
16 #define COLLISIONSOLID_H
17 
18 #include "pandabase.h"
19 
20 #include "config_collide.h"
21 #include "copyOnWriteObject.h"
22 #include "luse.h"
23 #include "pointerTo.h"
24 #include "renderState.h"
25 #include "geomNode.h"
26 #include "lightMutex.h"
27 #include "lightMutexHolder.h"
28 #include "pStatCollector.h"
29 
30 class CollisionHandler;
31 class CollisionEntry;
32 class CollisionSphere;
33 class GeomNode;
34 class CollisionNode;
35 class CullTraverserData;
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : CollisionSolid
39 // Description : The abstract base class for all things that can
40 // collide with other things in the world, and all the
41 // things they can collide with (except geometry).
42 //
43 // This class and its derivatives really work very
44 // similarly to the way BoundingVolume and all of its
45 // derivatives work. There's a different subclass for
46 // each basic shape of solid, and double-dispatch
47 // function calls handle the subset of the N*N
48 // intersection tests that we care about.
49 ////////////////////////////////////////////////////////////////////
50 class EXPCL_PANDA_COLLIDE CollisionSolid : public CopyOnWriteObject {
51 public:
53  CollisionSolid(const CollisionSolid &copy);
54  virtual ~CollisionSolid();
55 
56  virtual CollisionSolid *make_copy()=0;
57 protected:
58  virtual PT(CopyOnWriteObject) make_cow_copy();
59 
60 PUBLISHED:
61  virtual LPoint3 get_collision_origin() const=0;
62 
63  INLINE void set_tangible(bool tangible);
64  INLINE bool is_tangible() const;
65 
66  INLINE void set_effective_normal(const LVector3 &effective_normal);
67  INLINE void clear_effective_normal();
68  INLINE bool has_effective_normal() const;
69  INLINE const LVector3 &get_effective_normal() const;
70 
71  INLINE void set_respect_effective_normal(bool respect_effective_normal);
72  INLINE bool get_respect_effective_normal() const;
73 
74  CPT(BoundingVolume) get_bounds() const;
75  void set_bounds(const BoundingVolume &bounding_volume);
76 
77 public:
78  virtual PT(CollisionEntry)
79  test_intersection(const CollisionEntry &entry) const;
80 
81  virtual void xform(const LMatrix4 &mat);
82 
83  virtual PT(PandaNode) get_viz(const CullTraverser *trav,
84  const CullTraverserData &data,
85  bool bounds_only) const;
86 
87  virtual PStatCollector &get_volume_pcollector();
88  virtual PStatCollector &get_test_pcollector();
89 
90 PUBLISHED:
91  virtual void output(ostream &out) const;
92  virtual void write(ostream &out, int indent_level = 0) const;
93 
94 protected:
95  INLINE bool do_is_tangible() const;
96  INLINE bool do_has_effective_normal() const;
97 
98  INLINE void mark_internal_bounds_stale();
99  virtual PT(BoundingVolume) compute_internal_bounds() const;
100 
101  virtual PT(CollisionEntry)
102  test_intersection_from_sphere(const CollisionEntry &entry) const;
103  virtual PT(CollisionEntry)
104  test_intersection_from_line(const CollisionEntry &entry) const;
105  virtual PT(CollisionEntry)
106  test_intersection_from_ray(const CollisionEntry &entry) const;
107  virtual PT(CollisionEntry)
108  test_intersection_from_segment(const CollisionEntry &entry) const;
109  virtual PT(CollisionEntry)
110  test_intersection_from_parabola(const CollisionEntry &entry) const;
111  virtual PT(CollisionEntry)
112  test_intersection_from_box(const CollisionEntry &entry) const;
113 
114  static void report_undefined_intersection_test(TypeHandle from_type,
115  TypeHandle into_type);
116  static void report_undefined_from_intersection(TypeHandle from_type);
117 
118  INLINE void mark_viz_stale();
119  virtual void fill_viz_geom();
120 
121  CPT(RenderState) get_solid_viz_state();
122  CPT(RenderState) get_wireframe_viz_state();
123  CPT(RenderState) get_other_viz_state();
124  CPT(RenderState) get_solid_bounds_viz_state();
125  CPT(RenderState) get_wireframe_bounds_viz_state();
126  CPT(RenderState) get_other_bounds_viz_state();
127 
128  PT(GeomNode) _viz_geom;
129  PT(GeomNode) _bounds_viz_geom;
130 
131 private:
132  LVector3 _effective_normal;
133  PT(BoundingVolume) _internal_bounds;
134 
135  // Be careful reordering these bits, since they are written to a bam
136  // file.
137  enum Flags {
138  F_tangible = 0x01,
139  F_effective_normal = 0x02,
140  F_viz_geom_stale = 0x04,
141  F_ignore_effective_normal = 0x08,
142  F_internal_bounds_stale = 0x10,
143  };
144  int _flags;
145 
146  LightMutex _lock;
147 
148  static PStatCollector _volume_pcollector;
149  static PStatCollector _test_pcollector;
150 
151 public:
152  virtual void write_datagram(BamWriter* manager, Datagram &me);
153 
154 protected:
155  void fillin(DatagramIterator& scan, BamReader* manager);
156 
157 public:
158  static TypeHandle get_class_type() {
159  return _type_handle;
160  }
161  static void init_type() {
162  CopyOnWriteObject::init_type();
163  register_type(_type_handle, "CollisionSolid",
164  CopyOnWriteObject::get_class_type());
165  }
166  virtual TypeHandle get_type() const {
167  return get_class_type();
168  }
169  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
170 
171 private:
172  static TypeHandle _type_handle;
173 
174  friend class CollisionSphere;
175  friend class CollisionLine;
176  friend class CollisionRay;
177  friend class CollisionSegment;
178  friend class CollisionParabola;
179  friend class CollisionHandlerFluidPusher;
180  friend class CollisionBox;
181 };
182 
183 INLINE ostream &operator << (ostream &out, const CollisionSolid &cs) {
184  cs.output(out);
185  return out;
186 }
187 
188 #include "collisionSolid.I"
189 
190 #endif
191 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
An infinite ray, with a specific origin and direction.
Definition: collisionRay.h:31
The abstract interface to a number of classes that decide what to do when a collision is detected...
A CollisionHandlerPusher that makes use of timing and spatial information from fluid collisions to im...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
A cuboid collision volume or object.
Definition: collisionBox.h:30
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
A spherical collision volume or object.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A lightweight class that represents a single element that may be timed and/or counted via stats...
A finite line segment, with two specific endpoints but no thickness.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
Defines a single collision event.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
An infinite line, similar to a CollisionRay, except that it extends in both directions.
Definition: collisionLine.h:28
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
This defines a parabolic arc, or subset of an arc, similar to the path of a projectile or falling obj...
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:33
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37