Panda3D
collisionSolid.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 collisionSolid.I
10  * @author drose
11  * @date 2000-06-27
12  */
13 
14 /**
15  * Sets the current state of the 'tangible' flag. Set this true to make the
16  * solid tangible, so that a CollisionHandlerPusher will not allow another
17  * object to intersect it, or false to make it intangible, so that a
18  * CollisionHandlerPusher will ignore it except to throw an event.
19  */
20 INLINE void CollisionSolid::
21 set_tangible(bool tangible) {
22  LightMutexHolder holder(_lock);
23  if (tangible) {
24  _flags |= F_tangible;
25  } else {
26  _flags &= ~F_tangible;
27  }
28  _flags |= F_viz_geom_stale;
29 }
30 
31 /**
32  * Returns whether the solid is considered 'tangible' or not. An intangible
33  * solid has no effect in a CollisionHandlerPusher (except to throw an event);
34  * it's useful for defining 'trigger' planes and spheres, that cause an effect
35  * when passed through.
36  */
37 INLINE bool CollisionSolid::
38 is_tangible() const {
39  LightMutexHolder holder(_lock);
40  return do_is_tangible();
41 }
42 
43 /**
44  * Records a false normal for this CollisionSolid that will be reported by the
45  * collision system with all collisions into it, instead of its actual normal.
46  * This is useful as a workaround for the problem of an avatar wanting to
47  * stand on a sloping ground; by storing a false normal, the ground appears to
48  * be perfectly level, and the avatar does not tend to slide down it.
49  */
50 INLINE void CollisionSolid::
51 set_effective_normal(const LVector3 &effective_normal) {
52  LightMutexHolder holder(_lock);
53  _effective_normal = effective_normal;
54  _flags |= F_effective_normal;
55 }
56 
57 /**
58  * Removes the normal previously set by set_effective_normal().
59  */
60 INLINE void CollisionSolid::
62  LightMutexHolder holder(_lock);
63  _flags &= ~F_effective_normal;
64 }
65 
66 /**
67  * Returns true if a special normal was set by set_effective_normal(), false
68  * otherwise.
69  */
70 INLINE bool CollisionSolid::
72  LightMutexHolder holder(_lock);
73  return do_has_effective_normal();
74 }
75 
76 /**
77  * Returns the normal that was set by set_effective_normal(). It is an error
78  * to call this unless has_effective_normal() returns true.
79  */
80 INLINE const LVector3 &CollisionSolid::
82  LightMutexHolder holder(_lock);
83  nassertr(do_has_effective_normal(), LVector3::zero());
84  return _effective_normal;
85 }
86 
87 /**
88  * This is only meaningful for CollisionSolids that will be added to a
89  * traverser as colliders. It is normally true, but if set false, it means
90  * that this particular solid does not care about the "effective" normal of
91  * other solids it meets, but rather always uses the true normal.
92  */
93 INLINE void CollisionSolid::
94 set_respect_effective_normal(bool respect_effective_normal) {
95  LightMutexHolder holder(_lock);
96  // For historical reasons, the bit we store is the opposite of the bool flag
97  // we present.
98  if (respect_effective_normal) {
99  _flags &= ~F_ignore_effective_normal;
100  } else {
101  _flags |= F_ignore_effective_normal;
102  }
103 }
104 
105 /**
106  * See set_respect_effective_normal().
107  */
108 INLINE bool CollisionSolid::
109 get_respect_effective_normal() const {
110  LightMutexHolder holder(_lock);
111  return (_flags & F_ignore_effective_normal) == 0;
112 }
113 
114 /**
115  * Returns whether the solid is considered 'tangible' or not. Assumes the
116  * lock is already held.
117  */
118 INLINE bool CollisionSolid::
119 do_is_tangible() const {
120  return (_flags & F_tangible) != 0;
121 }
122 
123 /**
124  * Returns true if a special normal was set by set_effective_normal(), false
125  * otherwise. Assumes the lock is already held.
126  */
127 INLINE bool CollisionSolid::
128 do_has_effective_normal() const {
129  return respect_effective_normal && (_flags & F_effective_normal) != 0;
130 }
131 
132 /**
133  * Should be called by a derived class to mark the internal bounding volume
134  * stale, so that recompute_internal_bounds() will be called when the bounding
135  * volume is next requested.
136  */
137 INLINE void CollisionSolid::
138 mark_internal_bounds_stale() {
139  LightMutexHolder holder(_lock);
140  _flags |= F_internal_bounds_stale;
141 }
142 
143 /**
144  * Called internally when the visualization may have been compromised by some
145  * change to internal state and will need to be recomputed the next time it is
146  * rendered.
147  */
148 INLINE void CollisionSolid::
149 mark_viz_stale() {
150  LightMutexHolder holder(_lock);
151  _flags |= F_viz_geom_stale;
152 }
const LVector3 & get_effective_normal() const
Returns the normal that was set by set_effective_normal().
void set_effective_normal(const LVector3 &effective_normal)
Records a false normal for this CollisionSolid that will be reported by the collision system with all...
void clear_effective_normal()
Removes the normal previously set by set_effective_normal().
set_respect_effective_normal
This is only meaningful for CollisionSolids that will be added to a traverser as colliders.
Similar to MutexHolder, but for a light mutex.
bool has_effective_normal() const
Returns true if a special normal was set by set_effective_normal(), false otherwise.
set_tangible
Sets the current state of the 'tangible' flag.