ソースを参照

added get_impact_velocity

Dave Schuyler 22 年 前
コミット
ad6b8e1c80

+ 2 - 2
direct/src/showbase/GravityWalker.py

@@ -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()) #*#

+ 15 - 0
panda/src/collide/collisionHandlerGravity.I

@@ -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

+ 2 - 0
panda/src/collide/collisionHandlerGravity.cxx

@@ -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;
           }

+ 2 - 0
panda/src/collide/collisionHandlerGravity.h

@@ -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;