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