Panda3D
 All Classes Functions Variables Enumerations
collisionHandlerGravity.I
1 // Filename: CollisionHandlerGravity.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CollisionHandlerGravity::set_offset
18 // Access: Public
19 // Description: Sets the linear offset to add to (or subtract from)
20 // the highest detected collision point to determine the
21 // actual height at which to set the collider.
22 ////////////////////////////////////////////////////////////////////
23 INLINE void CollisionHandlerGravity::
24 set_offset(PN_stdfloat offset) {
25  _offset = offset;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: CollisionHandlerGravity::get_offset
30 // Access: Public
31 // Description: Returns the linear offset to add to (or subtract from)
32 // the highest detected collision point to determine the
33 // actual height at which to set the collider.
34 ////////////////////////////////////////////////////////////////////
35 INLINE PN_stdfloat CollisionHandlerGravity::
36 get_offset() const {
37  return _offset;
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: CollisionHandlerGravity::set_reach
42 // Access: Public
43 // Description: Sets the reach to add to (or subtract from)
44 // the highest collision point
45 ////////////////////////////////////////////////////////////////////
46 INLINE void CollisionHandlerGravity::
47 set_reach(PN_stdfloat reach) {
48  _reach = reach;
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: CollisionHandlerGravity::get_reach
53 // Access: Public
54 // Description: Returns the reach to add to (or subtract from)
55 // the highest collision point
56 ////////////////////////////////////////////////////////////////////
57 INLINE PN_stdfloat CollisionHandlerGravity::
58 get_reach() const {
59  return _reach;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: CollisionHandlerGravity::get_airborne_height
64 // Access: Public
65 // Description: Return the height of the object from the ground.
66 //
67 // The object might not necessarily be at rest. Use
68 // is_on_ground() if you want to know whether the
69 // object is on the ground and at rest.
70 //
71 // See Also: is_in_outer_space()
72 ////////////////////////////////////////////////////////////////////
73 INLINE PN_stdfloat CollisionHandlerGravity::
75  return _airborne_height;
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: CollisionHandlerGravity::is_on_ground
80 // Access: Public
81 // Description: Is the object at rest?
82 ////////////////////////////////////////////////////////////////////
83 INLINE bool CollisionHandlerGravity::
84 is_on_ground() const {
85  // Testing for 0.0f here is not as foolhardy as it may appear. The
86  // handle_entries() function will set these values to 0.0f if they
87  // are within a threshold.
88  return get_airborne_height() == 0.0f && _current_velocity == 0.0f;
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: CollisionHandlerGravity::get_impact_velocity
93 // Access: Public
94 // Description: How hard did the object hit the ground.
95 // This value is set on impact with the ground.
96 // You may want to watch (poll) on is_on_groun() and
97 // when that is true, call get_impact_velocity().
98 // Normally I avoid polling, but we are calling
99 // is_on_ground() frequently anyway.
100 ////////////////////////////////////////////////////////////////////
101 INLINE PN_stdfloat CollisionHandlerGravity::
103  return _impact_velocity;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function : CollisionHandlerGravity::get_contact_normal
108 // Access : Public
109 // Description :
110 ////////////////////////////////////////////////////////////////////
111 INLINE const LVector3 &CollisionHandlerGravity::
112 get_contact_normal() const {
113  return _contact_normal;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: CollisionHandlerGravity::add_velocity
118 // Access: Public
119 // Description: Adds the sepcified amount to the current velocity.
120 // This is mostly here allow this common operation to
121 // be faster for scripting, but it's also more concise
122 // even in cpp.
123 ////////////////////////////////////////////////////////////////////
124 INLINE void CollisionHandlerGravity::
125 add_velocity(PN_stdfloat velocity) {
126  _current_velocity += velocity;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: CollisionHandlerGravity::set_velocity
131 // Access: Public
132 // Description: Sets the current vertical velocity.
133 ////////////////////////////////////////////////////////////////////
134 INLINE void CollisionHandlerGravity::
135 set_velocity(PN_stdfloat velocity) {
136  _current_velocity = velocity;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: CollisionHandlerGravity::get_velocity
141 // Access: Public
142 // Description: Gets the current vertical velocity.
143 //
144 // Generally, negative values mean the object is in
145 // free fall; while postive values mean the object has
146 // vertical thrust.
147 //
148 // A zero value does not necessarily mean the object
149 // on the ground, it may also be weightless and/or at
150 // the apex of its jump.
151 //
152 // See Also: is_on_ground() and get_gravity()
153 ////////////////////////////////////////////////////////////////////
154 INLINE PN_stdfloat CollisionHandlerGravity::
155 get_velocity() const {
156  return _current_velocity;
157 }
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: CollisionHandlerGravity::set_gravity
161 // Access: Public
162 // Description: Sets the linear gravity force (always plumb).
163 ////////////////////////////////////////////////////////////////////
164 INLINE void CollisionHandlerGravity::
165 set_gravity(PN_stdfloat gravity) {
166  _gravity = gravity;
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: CollisionHandlerGravity::get_gravity
171 // Access: Public
172 // Description: Gets the linear gravity force (always plumb).
173 ////////////////////////////////////////////////////////////////////
174 INLINE PN_stdfloat CollisionHandlerGravity::
175 get_gravity() const {
176  return _gravity;
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: CollisionHandlerGravity::set_max_velocity
181 // Access: Public
182 // Description: Sets the maximum speed at which the object will be
183 // allowed to descend towards a floor below it, in units
184 // per second. Set this to zero to allow it to
185 // instantly teleport any distance.
186 ////////////////////////////////////////////////////////////////////
187 INLINE void CollisionHandlerGravity::
188 set_max_velocity(PN_stdfloat max_velocity) {
189  _max_velocity = max_velocity;
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: CollisionHandlerGravity::get_max_velocity
194 // Access: Public
195 // Description: Retrieves the maximum speed at which the object will
196 // be allowed to descend towards a floor below it, in
197 // units per second. See set_max_velocity().
198 ////////////////////////////////////////////////////////////////////
199 INLINE PN_stdfloat CollisionHandlerGravity::
201  return _max_velocity;
202 }
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: CollisionHandlerGravity::set_legacy_mode
206 // Access: Public
207 // Description: Enables old behavior required by Toontown
208 // (Sellbot Factory lava room is good test case,
209 // lava and conveyor belt specifically). Behavior
210 // is to throw enter/exit events only for floor
211 // that the toon is in contact with
212 ////////////////////////////////////////////////////////////////////
213 INLINE void CollisionHandlerGravity::
214 set_legacy_mode(bool legacy_mode) {
215  _legacy_mode = legacy_mode;
216 }
217 
218 ////////////////////////////////////////////////////////////////////
219 // Function: CollisionHandlerGravity::get_legacy_mode
220 // Access: Public
221 // Description: returns true if legacy mode is enabled
222 ////////////////////////////////////////////////////////////////////
223 INLINE bool CollisionHandlerGravity::
225  return _legacy_mode;
226 }
bool is_on_ground() const
Is the object at rest?
void add_velocity(PN_stdfloat velocity)
Adds the sepcified amount to the current velocity.
PN_stdfloat get_offset() const
Returns the linear offset to add to (or subtract from) the highest detected collision point to determ...
bool get_legacy_mode() const
returns true if legacy mode is enabled
PN_stdfloat get_velocity() const
Gets the current vertical velocity.
PN_stdfloat get_reach() const
Returns the reach to add to (or subtract from) the highest collision point.
PN_stdfloat get_airborne_height() const
Return the height of the object from the ground.
void set_legacy_mode(bool legacy_mode)
Enables old behavior required by Toontown (Sellbot Factory lava room is good test case...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
PN_stdfloat get_impact_velocity() const
How hard did the object hit the ground.
PN_stdfloat get_gravity() const
Gets the linear gravity force (always plumb).
void set_offset(PN_stdfloat offset)
Sets the linear offset to add to (or subtract from) the highest detected collision point to determine...
PN_stdfloat get_max_velocity() const
Retrieves the maximum speed at which the object will be allowed to descend towards a floor below it...
void set_max_velocity(PN_stdfloat max_vel)
Sets the maximum speed at which the object will be allowed to descend towards a floor below it...
void set_reach(PN_stdfloat reach)
Sets the reach to add to (or subtract from) the highest collision point.
void set_gravity(PN_stdfloat gravity)
Sets the linear gravity force (always plumb).
void set_velocity(PN_stdfloat velocity)
Sets the current vertical velocity.