Panda3D
Loading...
Searching...
No Matches
collisionEntry.I
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.I
10 * @author drose
11 * @date 2002-03-16
12 */
13
14/**
15 *
16 */
17INLINE CollisionEntry::
18CollisionEntry() {
19 _flags = 0;
20 // > 1. means collision didn't happen
21 _t = 2.f;
22}
23
24/**
25 * Returns the CollisionSolid pointer for the particular solid that triggered
26 * this collision.
27 */
29get_from() const {
30 return _from;
31}
32
33/**
34 * Returns true if the "into" solid is, in fact, a CollisionSolid, and its
35 * pointer is known (in which case get_into() may be called to retrieve it).
36 * If this returns false, the collision was detected into a GeomNode, and
37 * there is no CollisionSolid pointer to be retrieved.
38 */
40has_into() const {
41 return (_into != nullptr);
42}
43
44/**
45 * Returns the CollisionSolid pointer for the particular solid was collided
46 * into. This pointer might be NULL if the collision was into a piece of
47 * visible geometry, instead of a normal CollisionSolid collision; see
48 * has_into().
49 */
51get_into() const {
52 return _into;
53}
54
55/**
56 * Returns the node that contains the CollisionSolid that triggered this
57 * collision. This will be a node that has been added to a CollisionTraverser
58 * via add_collider().
59 */
61get_from_node() const {
62 return _from_node;
63}
64
65/**
66 * Returns the node that contains the CollisionSolid that was collided into.
67 * This returns a PandaNode pointer instead of something more specific,
68 * because it might be either a CollisionNode or a GeomNode.
69 *
70 * Also see get_into_node_path().
71 */
73get_into_node() const {
74 return _into_node;
75}
76
77/**
78 * Returns the NodePath that represents the CollisionNode that contains the
79 * CollisionSolid that triggered this collision. This will be a NodePath that
80 * has been added to a CollisionTraverser via add_collider().
81 */
83get_from_node_path() const {
84 return _from_node_path;
85}
86
87/**
88 * Returns the NodePath that represents the specific CollisionNode or GeomNode
89 * instance that was collided into. This is the same node returned by
90 * get_into_node(), represented as a NodePath; however, it may be more useful
91 * because the NodePath can resolve the particular instance of the node, if
92 * there is more than one.
93 */
95get_into_node_path() const {
96 return _into_node_path;
97}
98
99/**
100 * Sets a time value for this collision relative to other CollisionEntries
101 */
102INLINE void CollisionEntry::
103set_t(PN_stdfloat t) {
104 nassertv(!cnan(t));
105 _t = t;
106}
107
108/**
109 * returns time value for this collision relative to other CollisionEntries
110 */
111INLINE PN_stdfloat CollisionEntry::
112get_t() const {
113 return _t;
114}
115
116/**
117 * returns true if this represents an actual collision as opposed to a
118 * potential collision, needed for iterative collision resolution where path
119 * of collider changes mid-frame
120 */
122collided() const {
123 return ((0.f <= _t) && (_t <= 1.f));
124}
125
126/**
127 * prepare for another collision test
128 */
131 _t = 2.f;
132}
133
134/**
135 * Returns true if the collision was detected by a CollisionTraverser whose
136 * respect_prev_transform flag was set true, meaning we should consider motion
137 * significant in evaluating collisions.
138 */
139INLINE bool CollisionEntry::
141 return (_flags & F_respect_prev_transform) != 0;
142}
143
144
145/**
146 * Stores the point, on the surface of the "into" object, at which a collision
147 * is detected.
148 *
149 * This point is specified in the coordinate space of the "into" object.
150 */
152set_surface_point(const LPoint3 &point) {
153 nassertv(!point.is_nan());
154 _surface_point = point;
155 _flags |= F_has_surface_point;
156}
157
158/**
159 * Stores the surface normal of the "into" object at the point of the
160 * intersection.
161 *
162 * This normal is specified in the coordinate space of the "into" object.
163 */
165set_surface_normal(const LVector3 &normal) {
166 nassertv(!normal.is_nan());
167 _surface_normal = normal;
168 _flags |= F_has_surface_normal;
169}
170
171/**
172 * Stores the point, within the interior of the "into" object, which
173 * represents the depth to which the "from" object has penetrated. This can
174 * also be described as the intersection point on the surface of the "from"
175 * object (which is inside the "into" object).
176 *
177 * This point is specified in the coordinate space of the "into" object.
178 */
180set_interior_point(const LPoint3 &point) {
181 nassertv(!point.is_nan());
182 _interior_point = point;
183 _flags |= F_has_interior_point;
184}
185
186/**
187 * Returns true if the surface point has been specified, false otherwise. See
188 * get_surface_point(). Some types of collisions may not compute the surface
189 * point.
190 */
192has_surface_point() const {
193 return (_flags & F_has_surface_point) != 0;
194}
195
196/**
197 * Returns true if the surface normal has been specified, false otherwise.
198 * See get_surface_normal(). Some types of collisions may not compute the
199 * surface normal.
200 */
202has_surface_normal() const {
203 return (_flags & F_has_surface_normal) != 0;
204}
205
206/**
207 * Returns true if the interior point has been specified, false otherwise.
208 * See get_interior_point(). Some types of collisions may not compute the
209 * interior point.
210 */
212has_interior_point() const {
213 return (_flags & F_has_interior_point) != 0;
214}
215
216/**
217 * Stores the position of the "from" object at the instant at which the
218 * collision is first detected.
219 *
220 * This position is specified in the coordinate space of the "into" object.
221 */
223set_contact_pos(const LPoint3 &pos) {
224 nassertv(!pos.is_nan());
225 _contact_pos = pos;
226 _flags |= F_has_contact_pos;
227}
228
229/**
230 * Stores the surface normal of the "into" object at the contact pos.
231 *
232 * This normal is specified in the coordinate space of the "into" object.
233 */
235set_contact_normal(const LVector3 &normal) {
236 nassertv(!normal.is_nan());
237 _contact_normal = normal;
238 _flags |= F_has_contact_normal;
239}
240
241/**
242 * Returns true if the contact position has been specified, false otherwise.
243 * See get_contact_pos(). Some types of collisions may not compute the
244 * contact pos.
245 */
247has_contact_pos() const {
248 return (_flags & F_has_contact_pos) != 0;
249}
250
251/**
252 * Returns true if the contact normal has been specified, false otherwise.
253 * See get_contact_normal(). Some types of collisions may not compute the
254 * contact normal.
255 */
257has_contact_normal() const {
258 return (_flags & F_has_contact_normal) != 0;
259}
260
261/**
262 * Returns the relative transform of the from node as seen from the into node.
263 */
264INLINE CPT(TransformState) CollisionEntry::
265get_wrt_space() const {
266 return _from_node_path.get_transform(_into_node_path);
267}
268
269/**
270 * Returns the relative transform of the into node as seen from the from node.
271 */
272INLINE CPT(TransformState) CollisionEntry::
273get_inv_wrt_space() const {
274 return _into_node_path.get_transform(_from_node_path);
275}
276
277/**
278 * Returns the relative transform of the from node as seen from the into node,
279 * as of the previous frame (according to set_prev_transform(),
280 * set_fluid_pos(), etc.)
281 */
282INLINE CPT(TransformState) CollisionEntry::
283get_wrt_prev_space() const {
285 return _from_node_path.get_prev_transform(_into_node_path);
286 } else {
287 return get_wrt_space();
288 }
289}
290
291/**
292 * Returns the relative transform of the from node as seen from the into node.
293 */
294INLINE const LMatrix4 &CollisionEntry::
295get_wrt_mat() const {
296 return get_wrt_space()->get_mat();
297}
298
299/**
300 * Returns the relative transform of the into node as seen from the from node.
301 */
302INLINE const LMatrix4 &CollisionEntry::
303get_inv_wrt_mat() const {
304 return get_inv_wrt_space()->get_mat();
305}
306
307/**
308 * Returns the relative transform of the from node as seen from the into node,
309 * as of the previous frame (according to set_prev_transform(),
310 * set_fluid_pos(), etc.)
311 */
312INLINE const LMatrix4 &CollisionEntry::
313get_wrt_prev_mat() const {
314 return get_wrt_prev_space()->get_mat();
315}
316
317/**
318 * Returns the ClipPlaneAttrib, if any, that is applied to the into_node_path,
319 * or NULL if there is no clip plane in effect.
320 */
321INLINE const ClipPlaneAttrib *CollisionEntry::
322get_into_clip_planes() const {
323 if ((_flags & F_checked_clip_planes) == 0) {
324 ((CollisionEntry *)this)->check_clip_planes();
325 }
326 return _into_clip_planes;
327}
328
329/**
330 * This is intended to be called only by the CollisionTraverser. It requests
331 * the CollisionEntry to start the intersection test between the from and into
332 * solids stored within it, passing the result (if positive) to the indicated
333 * CollisionHandler.
334 */
335INLINE void CollisionEntry::
336test_intersection(CollisionHandler *record,
337 const CollisionTraverser *trav) const {
338 PT(CollisionEntry) result = get_from()->test_intersection(*this);
339#ifdef DO_COLLISION_RECORDING
340 if (trav->has_recorder()) {
341 if (result != nullptr) {
342 trav->get_recorder()->collision_tested(*result, true);
343 } else {
344 trav->get_recorder()->collision_tested(*this, false);
345 }
346 }
347#endif // DO_COLLISION_RECORDING
348#ifdef DO_PSTATS
349 ((CollisionSolid *)get_into())->get_test_pcollector().add_level(1);
350#endif // DO_PSTATS
351 // if there was no collision detected but the handler wants to know about
352 // all potential collisions, create a "didn't collide" collision entry for
353 // it
354 if (record->wants_all_potential_collidees() && result == nullptr) {
355 result = new CollisionEntry(*this);
356 result->reset_collided();
357 }
358 if (result != nullptr) {
359 record->add_entry(result);
360 }
361}
362
363INLINE std::ostream &
364operator << (std::ostream &out, const CollisionEntry &entry) {
365 entry.output(out);
366 return out;
367}
This functions similarly to a LightAttrib.
Defines a single collision event.
get_from_node
Returns the node that contains the CollisionSolid that triggered this collision.
get_respect_prev_transform
Returns true if the collision was detected by a CollisionTraverser whose respect_prev_transform flag ...
get_t
returns time value for this collision relative to other CollisionEntries
void reset_collided()
prepare for another collision test
bool has_contact_normal() const
Returns true if the contact normal has been specified, false otherwise.
get_into
Returns the CollisionSolid pointer for the particular solid was collided into.
bool has_surface_normal() const
Returns true if the surface normal has been specified, false otherwise.
void set_contact_pos(const LPoint3 &pos)
Stores the position of the "from" object at the instant at which the collision is first detected.
bool has_into() const
Returns true if the "into" solid is, in fact, a CollisionSolid, and its pointer is known (in which ca...
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
bool collided() const
returns true if this represents an actual collision as opposed to a potential collision,...
bool has_surface_point() const
Returns true if the surface point has been specified, false otherwise.
get_into_node_path
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
void set_surface_normal(const LVector3 &normal)
Stores the surface normal of the "into" object at the point of the intersection.
get_into_node
Returns the node that contains the CollisionSolid that was collided into.
bool has_interior_point() const
Returns true if the interior point has been specified, false otherwise.
void set_interior_point(const LPoint3 &point)
Stores the point, within the interior of the "into" object, which represents the depth to which the "...
set_t
Sets a time value for this collision relative to other CollisionEntries.
bool has_contact_pos() const
Returns true if the contact position has been specified, false otherwise.
void set_contact_normal(const LVector3 &normal)
Stores the surface normal of the "into" object at the contact pos.
get_from
Returns the CollisionSolid pointer for the particular solid that triggered this collision.
void set_surface_point(const LPoint3 &point)
Stores the point, on the surface of the "into" object, at which a collision is detected.
The abstract interface to a number of classes that decide what to do when a collision is detected.
A node in the scene graph that can hold any number of CollisionSolids.
The abstract base class for all things that can collide with other things in the world,...
This class manages the traversal through the scene graph to detect collisions.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
const TransformState * get_prev_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the transform that has been set as this node's "previous" position.
Definition nodePath.cxx:882
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition nodePath.cxx:794
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
Indicates a coordinate-system transform on vertices.