Panda3D
collisionSolid.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 collisionSolid.h
10  * @author drose
11  * @date 2000-04-24
12  */
13 
14 #ifndef COLLISIONSOLID_H
15 #define COLLISIONSOLID_H
16 
17 #include "pandabase.h"
18 
19 #include "config_collide.h"
20 #include "copyOnWriteObject.h"
21 #include "luse.h"
22 #include "pointerTo.h"
23 #include "renderState.h"
24 #include "geomNode.h"
25 #include "lightMutex.h"
26 #include "lightMutexHolder.h"
27 #include "pStatCollector.h"
28 
29 class CollisionHandler;
30 class CollisionEntry;
31 class CollisionSphere;
32 class GeomNode;
33 class CollisionNode;
34 class CullTraverserData;
35 
36 /**
37  * The abstract base class for all things that can collide with other things
38  * in the world, and all the things they can collide with (except geometry).
39  *
40  * This class and its derivatives really work very similarly to the way
41  * BoundingVolume and all of its derivatives work. There's a different
42  * subclass for each basic shape of solid, and double-dispatch function calls
43  * handle the subset of the N*N intersection tests that we care about.
44  */
45 class EXPCL_PANDA_COLLIDE CollisionSolid : public CopyOnWriteObject {
46 public:
48  CollisionSolid(const CollisionSolid &copy);
49  virtual ~CollisionSolid();
50 
51  virtual CollisionSolid *make_copy()=0;
52 protected:
53  virtual PT(CopyOnWriteObject) make_cow_copy();
54 
55 PUBLISHED:
56  virtual LPoint3 get_collision_origin() const=0;
57  MAKE_PROPERTY(collision_origin, get_collision_origin);
58 
59  INLINE void set_tangible(bool tangible);
60  INLINE bool is_tangible() const;
61  MAKE_PROPERTY(tangible, is_tangible, set_tangible);
62 
63  INLINE void set_effective_normal(const LVector3 &effective_normal);
64  INLINE void clear_effective_normal();
65  INLINE bool has_effective_normal() const;
66  INLINE const LVector3 &get_effective_normal() const;
67 
68  INLINE void set_respect_effective_normal(bool respect_effective_normal);
69  INLINE bool get_respect_effective_normal() const;
70  MAKE_PROPERTY(respect_effective_normal,
71  get_respect_effective_normal,
72  set_respect_effective_normal);
73 
74  CPT(BoundingVolume) get_bounds() const;
75  void set_bounds(const BoundingVolume &bounding_volume);
76  MAKE_PROPERTY(bounds, get_bounds, set_bounds);
77 
78 public:
79  virtual PT(CollisionEntry)
80  test_intersection(const CollisionEntry &entry) const;
81 
82  virtual void xform(const LMatrix4 &mat);
83 
84  virtual PT(PandaNode) get_viz(const CullTraverser *trav,
85  const CullTraverserData &data,
86  bool bounds_only) const;
87 
88  virtual PStatCollector &get_volume_pcollector();
89  virtual PStatCollector &get_test_pcollector();
90 
91 PUBLISHED:
92  virtual void output(std::ostream &out) const;
93  virtual void write(std::ostream &out, int indent_level = 0) const;
94 
95 protected:
96  INLINE bool do_is_tangible() const;
97  INLINE bool do_has_effective_normal() const;
98 
99  INLINE void mark_internal_bounds_stale();
100  virtual PT(BoundingVolume) compute_internal_bounds() const;
101 
102  virtual PT(CollisionEntry)
103  test_intersection_from_sphere(const CollisionEntry &entry) const;
104  virtual PT(CollisionEntry)
105  test_intersection_from_line(const CollisionEntry &entry) const;
106  virtual PT(CollisionEntry)
107  test_intersection_from_ray(const CollisionEntry &entry) const;
108  virtual PT(CollisionEntry)
109  test_intersection_from_segment(const CollisionEntry &entry) const;
110  virtual PT(CollisionEntry)
111  test_intersection_from_capsule(const CollisionEntry &entry) const;
112  virtual PT(CollisionEntry)
113  test_intersection_from_parabola(const CollisionEntry &entry) const;
114  virtual PT(CollisionEntry)
115  test_intersection_from_box(const CollisionEntry &entry) const;
116 
117  static void report_undefined_intersection_test(TypeHandle from_type,
118  TypeHandle into_type);
119  static void report_undefined_from_intersection(TypeHandle from_type);
120 
121  INLINE void mark_viz_stale();
122  virtual void fill_viz_geom();
123 
124  CPT(RenderState) get_solid_viz_state();
125  CPT(RenderState) get_wireframe_viz_state();
126  CPT(RenderState) get_other_viz_state();
127  CPT(RenderState) get_solid_bounds_viz_state();
128  CPT(RenderState) get_wireframe_bounds_viz_state();
129  CPT(RenderState) get_other_bounds_viz_state();
130 
131  PT(GeomNode) _viz_geom;
132  PT(GeomNode) _bounds_viz_geom;
133 
134 private:
135  LVector3 _effective_normal;
136  PT(BoundingVolume) _internal_bounds;
137 
138  // Be careful reordering these bits, since they are written to a bam file.
139  enum Flags {
140  F_tangible = 0x01,
141  F_effective_normal = 0x02,
142  F_viz_geom_stale = 0x04,
143  F_ignore_effective_normal = 0x08,
144  F_internal_bounds_stale = 0x10,
145  };
146  int _flags;
147 
148  LightMutex _lock;
149 
150  static PStatCollector _volume_pcollector;
151  static PStatCollector _test_pcollector;
152 
153 public:
154  virtual void write_datagram(BamWriter* manager, Datagram &me);
155 
156 protected:
157  void fillin(DatagramIterator& scan, BamReader* manager);
158 
159 public:
160  static TypeHandle get_class_type() {
161  return _type_handle;
162  }
163  static void init_type() {
164  CopyOnWriteObject::init_type();
165  register_type(_type_handle, "CollisionSolid",
166  CopyOnWriteObject::get_class_type());
167  }
168  virtual TypeHandle get_type() const {
169  return get_class_type();
170  }
171  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
172 
173 private:
174  static TypeHandle _type_handle;
175 
176  friend class CollisionSphere;
177  friend class CollisionLine;
178  friend class CollisionRay;
179  friend class CollisionSegment;
180  friend class CollisionCapsule;
181  friend class CollisionParabola;
182  friend class CollisionHandlerFluidPusher;
183  friend class CollisionBox;
184 };
185 
186 INLINE std::ostream &operator << (std::ostream &out, const CollisionSolid &cs) {
187  cs.output(out);
188  return out;
189 }
190 
191 #include "collisionSolid.I"
192 
193 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
An infinite ray, with a specific origin and direction.
Definition: collisionRay.h:27
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:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for all things that can collide with other things in the world,...
A cuboid collision volume or object.
Definition: collisionBox.h:27
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A spherical collision volume or object.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class'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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
Defines a single collision event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This implements a solid consisting of a cylinder with hemispherical endcaps, also known as a capsule ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
An infinite line, similar to a CollisionRay, except that it extends in both directions.
Definition: collisionLine.h:25
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:30
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:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.