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