added get_impact_velocity

This commit is contained in:
Dave Schuyler 2003-12-09 04:35:29 +00:00
parent d5af5d35c3
commit ad6b8e1c80
4 changed files with 21 additions and 2 deletions

View File

@ -257,7 +257,7 @@ class GravityWalker(DirectObject.DirectObject):
self.jumpDelayTask.remove()
self.mayJump = 0
self.jumpDelayTask=taskMgr.doMethodLater(
0.1,
0.5,
self.setMayJump,
"jumpDelay-%s"%id(self))
@ -291,7 +291,7 @@ class GravityWalker(DirectObject.DirectObject):
self.rotationSpeed = 0
jump = 0
if 0:
if 1:
onScreenDebug.add("airborneHeight", self.lifter.getAirborneHeight()) #*#
onScreenDebug.add("falling", self.falling) #*#
onScreenDebug.add("isOnGround", self.lifter.isOnGround()) #*#

View File

@ -68,6 +68,21 @@ is_on_ground() const {
return get_airborne_height() == 0.0f && _current_velocity == 0.0f;
}
////////////////////////////////////////////////////////////////////
// Function: CollisionHandlerGravity::get_impact_velocity
// Access: Public
// Description: How hard did the object hit the ground.
// This value is set on impact with the ground.
// You may want to watch (poll) on is_on_groun() and
// when that is true, call get_impact_velocity().
// Normally I avoid polling, but we are calling
// is_on_ground() frequently anyway.
////////////////////////////////////////////////////////////////////
INLINE float CollisionHandlerGravity::
get_impact_velocity() const {
return _impact_velocity;
}
////////////////////////////////////////////////////////////////////
// Function: CollisionHandlerGravity::add_velocity
// Access: Public

View File

@ -34,6 +34,7 @@ CollisionHandlerGravity::
CollisionHandlerGravity() {
_offset = 0.0f;
_airborne_height = 0.0f;
_impact_velocity = 0.0f;
_gravity = 32.174f;
_current_velocity = 0.0f;
_max_velocity = 400.0f;
@ -140,6 +141,7 @@ handle_entries() {
if (_airborne_height < 0.001f && _current_velocity < 0.001f) {
// ...the node is under the floor, so it has landed.
_impact_velocity = _current_velocity;
// These values are used by is_on_ground().
_current_velocity = _airborne_height = 0.0f;
}

View File

@ -42,6 +42,7 @@ PUBLISHED:
INLINE float get_airborne_height() const;
INLINE bool is_on_ground() const;
INLINE float get_impact_velocity() const;
INLINE void add_velocity(float velocity);
INLINE void set_velocity(float velocity);
@ -60,6 +61,7 @@ protected:
private:
float _offset;
float _airborne_height;
float _impact_velocity;
float _gravity;
float _current_velocity;
float _max_velocity;