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