Panda3D
collisionEntry.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 collisionEntry.h
10  * @author drose
11  * @date 2002-03-16
12  */
13 
14 #ifndef COLLISIONENTRY_H
15 #define COLLISIONENTRY_H
16 
17 #include "pandabase.h"
18 
19 #include "collisionTraverser.h"
20 #include "collisionSolid.h"
21 #include "collisionNode.h"
22 #include "collisionRecorder.h"
23 
24 #include "transformState.h"
26 #include "luse.h"
27 #include "pointerTo.h"
28 #include "pandaNode.h"
29 #include "nodePath.h"
30 #include "clipPlaneAttrib.h"
31 
32 /**
33  * Defines a single collision event. One of these is created for each
34  * collision detected by a CollisionTraverser, to be dealt with by the
35  * CollisionHandler.
36  *
37  * A CollisionEntry provides slots for a number of data values (such as
38  * intersection point and normal) that might or might not be known for each
39  * collision. It is up to the handler to determine what information is known
40  * and to do the right thing with it.
41  */
42 class EXPCL_PANDA_COLLIDE CollisionEntry : public TypedWritableReferenceCount {
43 public:
44  INLINE CollisionEntry();
45  CollisionEntry(const CollisionEntry &copy);
46  void operator = (const CollisionEntry &copy);
47 
48 PUBLISHED:
49  INLINE const CollisionSolid *get_from() const;
50  INLINE bool has_into() const;
51  INLINE const CollisionSolid *get_into() const;
52 
53  INLINE CollisionNode *get_from_node() const;
54  INLINE PandaNode *get_into_node() const;
55  INLINE NodePath get_from_node_path() const;
56  INLINE NodePath get_into_node_path() const;
57 
58  INLINE void set_t(PN_stdfloat t);
59  INLINE PN_stdfloat get_t() const;
60  INLINE bool collided() const;
61  INLINE void reset_collided();
62 
63  INLINE bool get_respect_prev_transform() const;
64 
65  INLINE void set_surface_point(const LPoint3 &point);
66  INLINE void set_surface_normal(const LVector3 &normal);
67  INLINE void set_interior_point(const LPoint3 &point);
68 
69  INLINE bool has_surface_point() const;
70  INLINE bool has_surface_normal() const;
71  INLINE bool has_interior_point() const;
72 
73  INLINE void set_contact_pos(const LPoint3 &pos);
74  INLINE void set_contact_normal(const LVector3 &normal);
75 
76  INLINE bool has_contact_pos() const;
77  INLINE bool has_contact_normal() const;
78 
79  LPoint3 get_surface_point(const NodePath &space) const;
80  LVector3 get_surface_normal(const NodePath &space) const;
81  LPoint3 get_interior_point(const NodePath &space) const;
82  bool get_all(const NodePath &space,
83  LPoint3 &surface_point,
84  LVector3 &surface_normal,
85  LPoint3 &interior_point) const;
86 
87  LPoint3 get_contact_pos(const NodePath &space) const;
88  LVector3 get_contact_normal(const NodePath &space) const;
89  bool get_all_contact_info(const NodePath &space,
90  LPoint3 &contact_pos,
91  LVector3 &contact_normal) const;
92 
93  void output(std::ostream &out) const;
94  void write(std::ostream &out, int indent_level = 0) const;
95 
96 PUBLISHED:
97  MAKE_PROPERTY(from_solid, get_from);
98  MAKE_PROPERTY(into_solid, get_into);
99  MAKE_PROPERTY(from_node, get_from_node);
100  MAKE_PROPERTY(into_node, get_into_node);
101  MAKE_PROPERTY(from_node_path, get_from_node_path);
102  MAKE_PROPERTY(into_node_path, get_into_node_path);
103 
104  MAKE_PROPERTY(t, get_t, set_t);
105  MAKE_PROPERTY(respect_prev_transform, get_respect_prev_transform);
106 
107 public:
108  INLINE CPT(TransformState) get_wrt_space() const;
109  INLINE CPT(TransformState) get_inv_wrt_space() const;
110  INLINE CPT(TransformState) get_wrt_prev_space() const;
111 
112  INLINE const LMatrix4 &get_wrt_mat() const;
113  INLINE const LMatrix4 &get_inv_wrt_mat() const;
114  INLINE const LMatrix4 &get_wrt_prev_mat() const;
115 
116  INLINE const ClipPlaneAttrib *get_into_clip_planes() const;
117 
118 private:
119  INLINE void test_intersection(CollisionHandler *record,
120  const CollisionTraverser *trav) const;
121  void check_clip_planes();
122 
123  CPT(CollisionSolid) _from;
124  CPT(CollisionSolid) _into;
125 
126  PT(CollisionNode) _from_node;
127  PT(PandaNode) _into_node;
128  NodePath _from_node_path;
129  NodePath _into_node_path;
130  CPT(ClipPlaneAttrib) _into_clip_planes;
131  PN_stdfloat _t;
132 
133  enum Flags {
134  F_has_surface_point = 0x0001,
135  F_has_surface_normal = 0x0002,
136  F_has_interior_point = 0x0004,
137  F_respect_prev_transform = 0x0008,
138  F_checked_clip_planes = 0x0010,
139  F_has_contact_pos = 0x0020,
140  F_has_contact_normal = 0x0040,
141  };
142 
143  int _flags;
144 
145  LPoint3 _surface_point;
146  LVector3 _surface_normal;
147  LPoint3 _interior_point;
148 
149  LPoint3 _contact_pos;
150  LVector3 _contact_normal;
151 
152 public:
153  static TypeHandle get_class_type() {
154  return _type_handle;
155  }
156  static void init_type() {
157  TypedWritableReferenceCount::init_type();
158  register_type(_type_handle, "CollisionEntry",
159  TypedWritableReferenceCount::get_class_type());
160  }
161  virtual TypeHandle get_type() const {
162  return get_class_type();
163  }
164  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
165 
166 private:
167  static TypeHandle _type_handle;
168 
169  friend class CollisionTraverser;
170  friend class CollisionHandlerFluidPusher;
171 };
172 
173 INLINE std::ostream &operator << (std::ostream &out, const CollisionEntry &entry);
174 
175 #include "collisionEntry.I"
176 
177 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
The abstract interface to a number of classes that decide what to do when a collision is detected.
Indicates a coordinate-system transform on vertices.
A CollisionHandlerPusher that makes use of timing and spatial information from fluid collisions to im...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for all things that can collide with other things in the world,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 functions similarly to a LightAttrib.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a single collision event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:30
This class manages the traversal through the scene graph to detect collisions.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.