瀏覽代碼

*** empty log message ***

David Rose 25 年之前
父節點
當前提交
874162e6c3

+ 26 - 0
panda/src/collide/collisionHandlerFloor.I

@@ -3,6 +3,7 @@
 // 
 ////////////////////////////////////////////////////////////////////
 
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionHandlerFloor::set_offset
 //       Access: Public
@@ -26,3 +27,28 @@ INLINE float CollisionHandlerFloor::
 get_offset() const {
   return _offset;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionHandlerFloor::set_max_velocity
+//       Access: Public
+//  Description: Sets the maximum speed at which the object will be
+//               allowed to descend towards a floor below it, in units
+//               per second.  Set this to zero to allow it to
+//               instantly teleport any distance.
+////////////////////////////////////////////////////////////////////
+INLINE void CollisionHandlerFloor::
+set_max_velocity(float max_velocity) {
+  _max_velocity = max_velocity;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionHandlerFloor::get_max_velocity
+//       Access: Public
+//  Description: Retrieves the maximum speed at which the object will
+//               be allowed to descend towards a floor below it, in
+//               units per second.  See set_max_velocity().
+////////////////////////////////////////////////////////////////////
+INLINE float CollisionHandlerFloor::
+get_max_velocity() const {
+  return _max_velocity;
+}

+ 13 - 3
panda/src/collide/collisionHandlerFloor.cxx

@@ -8,6 +8,7 @@
 
 #include <renderRelation.h>
 #include <transformTransition.h>
+#include <clockObject.h>
 
 TypeHandle CollisionHandlerFloor::_type_handle;
 
@@ -19,6 +20,7 @@ TypeHandle CollisionHandlerFloor::_type_handle;
 CollisionHandlerFloor::
 CollisionHandlerFloor() {
   _offset = 0.0;
+  _max_velocity = 0.0;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -84,14 +86,22 @@ handle_entries() {
       }
 
       // Now set our height accordingly.
-      if (!IS_THRESHOLD_ZERO(max_height + _offset, 0.001)) {
+      float adjust = max_height + _offset;
+      if (!IS_THRESHOLD_ZERO(adjust, 0.001)) {
 	if (collide_cat.is_debug()) {
 	  collide_cat.debug()
-	    << "Adjusting height by " << max_height + _offset << "\n";
+	    << "Adjusting height by " << adjust << "\n";
 	}
+
+	if (adjust < 0.0 && _max_velocity != 0.0) {
+	  float max_adjust = 
+	    _max_velocity * ClockObject::get_global_clock()->get_dt();
+	  adjust = max(adjust, -max_adjust);
+	}
+
 	LMatrix4f mat;
 	def.get_mat(mat);
-	mat(3, 2) += max_height + _offset;
+	mat(3, 2) += adjust;
 	def.set_mat(mat);
       } else {
 	if (collide_cat.is_spam()) {

+ 4 - 0
panda/src/collide/collisionHandlerFloor.h

@@ -28,11 +28,15 @@ PUBLISHED:
   INLINE void set_offset(float offset);
   INLINE float get_offset() const;
 
+  INLINE void set_max_velocity(float max_vel);
+  INLINE float get_max_velocity() const;
+
 protected:
   virtual void handle_entries();
 
 private:
   float _offset;
+  float _max_velocity;
 
 
 public:

+ 26 - 12
panda/src/tform/driveInterface.cxx

@@ -396,13 +396,38 @@ recompute() {
 ////////////////////////////////////////////////////////////////////
 void DriveInterface::
 transmit_data(NodeAttributes &data) {
+
+  // Look for mouse activity.
+  double x = 0.0;
+  double y = 0.0;
+
+  bool got_mouse = false;
+
+  const Vec3DataAttribute *xyz;
+  if (get_attribute_into(xyz, data, _xyz_type)) {
+    LVecBase3f p = xyz->get_value();
+    x = p[0];
+    y = p[1];
+
+    got_mouse = true;
+  }
+
   // Look for keyboard events.
   const ButtonEventDataAttribute *b;
   if (get_attribute_into(b, data, _button_events_type)) {
     ButtonEventDataAttribute::const_iterator bi;
     for (bi = b->begin(); bi != b->end(); ++bi) {
       const ButtonEvent &be = (*bi);
-      if (!(_ignore_mouse && be._down)) {
+      if (be._down) {
+	// We only trap button down events if (a) the mouse is in the
+	// window, and (b) we aren't set to ignore the mouse.
+	if (got_mouse && !_ignore_mouse) {
+	  _mods.add_event(be);
+	}
+      } else {
+	// However, we always trap button up events, so we don't get
+	// confused and believe a button is still being held down when
+	// it is not.
 	_mods.add_event(be);
       }
 
@@ -418,17 +443,6 @@ transmit_data(NodeAttributes &data) {
     }
   }
 
-  // Now look for mouse activity.
-  double x = 0.0;
-  double y = 0.0;
-
-  const Vec3DataAttribute *xyz;
-  if (get_attribute_into(xyz, data, _xyz_type)) {
-    LVecBase3f p = xyz->get_value();
-    x = p[0];
-    y = p[1];
-  }
-
   apply(x, y, _mods.is_any_down());
   _transform->set_value(_mat);