Panda3D
 All Classes Functions Variables Enumerations
collisionHandlerGravity.I
00001 // Filename: CollisionHandlerGravity.I
00002 // Created by:  drose (16Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: CollisionHandlerGravity::set_offset
00018 //       Access: Public
00019 //  Description: Sets the linear offset to add to (or subtract from)
00020 //               the highest detected collision point to determine the
00021 //               actual height at which to set the collider.
00022 ////////////////////////////////////////////////////////////////////
00023 INLINE void CollisionHandlerGravity::
00024 set_offset(PN_stdfloat offset) {
00025   _offset = offset;
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: CollisionHandlerGravity::get_offset
00030 //       Access: Public
00031 //  Description: Returns the linear offset to add to (or subtract from)
00032 //               the highest detected collision point to determine the
00033 //               actual height at which to set the collider.
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE PN_stdfloat CollisionHandlerGravity::
00036 get_offset() const {
00037   return _offset;
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: CollisionHandlerGravity::set_reach
00042 //       Access: Public
00043 //  Description: Sets the reach to add to (or subtract from)
00044 //               the highest collision point
00045 ////////////////////////////////////////////////////////////////////
00046 INLINE void CollisionHandlerGravity::
00047 set_reach(PN_stdfloat reach) {
00048   _reach = reach;
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: CollisionHandlerGravity::get_reach
00053 //       Access: Public
00054 //  Description: Returns the reach to add to (or subtract from)
00055 //               the highest collision point
00056 ////////////////////////////////////////////////////////////////////
00057 INLINE PN_stdfloat CollisionHandlerGravity::
00058 get_reach() const {
00059   return _reach;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: CollisionHandlerGravity::get_airborne_height
00064 //       Access: Public
00065 //  Description: Return the height of the object from the ground.
00066 //
00067 //               The object might not necessarily be at rest.  Use
00068 //               is_on_ground() if you want to know whether the
00069 //               object is on the ground and at rest.
00070 //
00071 //               See Also: is_in_outer_space()
00072 ////////////////////////////////////////////////////////////////////
00073 INLINE PN_stdfloat CollisionHandlerGravity::
00074 get_airborne_height() const {
00075   return _airborne_height;
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: CollisionHandlerGravity::is_on_ground
00080 //       Access: Public
00081 //  Description: Is the object at rest?
00082 ////////////////////////////////////////////////////////////////////
00083 INLINE bool CollisionHandlerGravity::
00084 is_on_ground() const {
00085   // Testing for 0.0f here is not as foolhardy as it may appear.  The
00086   // handle_entries() function will set these values to 0.0f if they
00087   // are within a threshold.
00088   return get_airborne_height() == 0.0f && _current_velocity == 0.0f;
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: CollisionHandlerGravity::get_impact_velocity
00093 //       Access: Public
00094 //  Description: How hard did the object hit the ground.
00095 //               This value is set on impact with the ground.
00096 //               You may want to watch (poll) on is_on_groun() and
00097 //               when that is true, call get_impact_velocity().
00098 //               Normally I avoid polling, but we are calling
00099 //               is_on_ground() frequently anyway.
00100 ////////////////////////////////////////////////////////////////////
00101 INLINE PN_stdfloat CollisionHandlerGravity::
00102 get_impact_velocity() const {
00103   return _impact_velocity;
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //    Function : CollisionHandlerGravity::get_contact_normal
00108 //      Access : Public
00109 // Description : 
00110 ////////////////////////////////////////////////////////////////////
00111 INLINE const LVector3 &CollisionHandlerGravity::
00112 get_contact_normal() const {
00113   return _contact_normal;
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: CollisionHandlerGravity::add_velocity
00118 //       Access: Public
00119 //  Description: Adds the sepcified amount to the current velocity.
00120 //               This is mostly here allow this common operation to
00121 //               be faster for scripting, but it's also more concise
00122 //               even in cpp.
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE void CollisionHandlerGravity::
00125 add_velocity(PN_stdfloat velocity) {
00126   _current_velocity += velocity;
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: CollisionHandlerGravity::set_velocity
00131 //       Access: Public
00132 //  Description: Sets the current vertical velocity.
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE void CollisionHandlerGravity::
00135 set_velocity(PN_stdfloat velocity) {
00136   _current_velocity = velocity;
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: CollisionHandlerGravity::get_velocity
00141 //       Access: Public
00142 //  Description: Gets the current vertical velocity.
00143 //
00144 //               Generally, negative values mean the object is in
00145 //               free fall; while postive values mean the object has
00146 //               vertical thrust.
00147 //
00148 //               A zero value does not necessarily mean the object
00149 //               on the ground, it may also be weightless and/or at
00150 //               the apex of its jump.
00151 //
00152 //               See Also: is_on_ground() and get_gravity()
00153 ////////////////////////////////////////////////////////////////////
00154 INLINE PN_stdfloat CollisionHandlerGravity::
00155 get_velocity() const {
00156   return _current_velocity;
00157 }
00158 
00159 ////////////////////////////////////////////////////////////////////
00160 //     Function: CollisionHandlerGravity::set_gravity
00161 //       Access: Public
00162 //  Description: Sets the linear gravity force (always plumb).
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE void CollisionHandlerGravity::
00165 set_gravity(PN_stdfloat gravity) {
00166   _gravity = gravity;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: CollisionHandlerGravity::get_gravity
00171 //       Access: Public
00172 //  Description: Gets the linear gravity force (always plumb).
00173 ////////////////////////////////////////////////////////////////////
00174 INLINE PN_stdfloat CollisionHandlerGravity::
00175 get_gravity() const {
00176   return _gravity;
00177 }
00178 
00179 ////////////////////////////////////////////////////////////////////
00180 //     Function: CollisionHandlerGravity::set_max_velocity
00181 //       Access: Public
00182 //  Description: Sets the maximum speed at which the object will be
00183 //               allowed to descend towards a floor below it, in units
00184 //               per second.  Set this to zero to allow it to
00185 //               instantly teleport any distance.
00186 ////////////////////////////////////////////////////////////////////
00187 INLINE void CollisionHandlerGravity::
00188 set_max_velocity(PN_stdfloat max_velocity) {
00189   _max_velocity = max_velocity;
00190 }
00191 
00192 ////////////////////////////////////////////////////////////////////
00193 //     Function: CollisionHandlerGravity::get_max_velocity
00194 //       Access: Public
00195 //  Description: Retrieves the maximum speed at which the object will
00196 //               be allowed to descend towards a floor below it, in
00197 //               units per second.  See set_max_velocity().
00198 ////////////////////////////////////////////////////////////////////
00199 INLINE PN_stdfloat CollisionHandlerGravity::
00200 get_max_velocity() const {
00201   return _max_velocity;
00202 }
00203 
00204 ////////////////////////////////////////////////////////////////////
00205 //     Function: CollisionHandlerGravity::set_legacy_mode
00206 //       Access: Public
00207 //  Description: Enables old behavior required by Toontown
00208 //               (Sellbot Factory lava room is good test case,
00209 //               lava and conveyor belt specifically). Behavior
00210 //               is to throw enter/exit events only for floor
00211 //               that the toon is in contact with
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE void CollisionHandlerGravity::
00214 set_legacy_mode(bool legacy_mode) {
00215   _legacy_mode = legacy_mode;
00216 }
00217 
00218 ////////////////////////////////////////////////////////////////////
00219 //     Function: CollisionHandlerGravity::get_legacy_mode
00220 //       Access: Public
00221 //  Description: returns true if legacy mode is enabled
00222 ////////////////////////////////////////////////////////////////////
00223 INLINE bool CollisionHandlerGravity::
00224 get_legacy_mode() const {
00225   return _legacy_mode;
00226 }
 All Classes Functions Variables Enumerations