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