Browse Source

added setDefaultToStandingStill

Darren Ranalli 18 years ago
parent
commit
49c6aa19b3

+ 26 - 0
direct/src/deadrec/smoothMover.I

@@ -693,6 +693,32 @@ get_directional_velocity() {
   return _directional_velocity;
   return _directional_velocity;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: SmoothMover::set_default_to_standing_still
+//       Access: Published, Static
+//  Description: Sets the flag that indicates whether to assume that
+//               the node stopped moving during periods when we don't
+//               get enough position updates. If true, the object will
+//               stand still momentarily. If false, the object will
+//               continuously lerp between the position updates that
+//               we did get.
+////////////////////////////////////////////////////////////////////
+INLINE void SmoothMover::
+set_default_to_standing_still(bool flag) {
+  _default_to_standing_still = flag;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: SmoothMover::get_default_to_standing_still
+//       Access: Published, Static
+//  Description: Returns the current state of the 'default to standing
+//               still' flag.  See set_default_to_standing_still().
+////////////////////////////////////////////////////////////////////
+INLINE bool SmoothMover::
+get_default_to_standing_still() {
+  return _default_to_standing_still;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: SmoothMover::get_avg_timestamp_delay
 //     Function: SmoothMover::get_avg_timestamp_delay
 //       Access: Private
 //       Access: Private

+ 2 - 1
direct/src/deadrec/smoothMover.cxx

@@ -61,6 +61,7 @@ SmoothMover() {
   _delay = 0.2;
   _delay = 0.2;
   _accept_clock_skew = true;
   _accept_clock_skew = true;
   _directional_velocity = true;
   _directional_velocity = true;
+  _default_to_standing_still = true;
   _max_position_age = 0.25;
   _max_position_age = 0.25;
   _expected_broadcast_period = 0.2;
   _expected_broadcast_period = 0.2;
   _reset_velocity_age = 0.3;
   _reset_velocity_age = 0.3;
@@ -413,7 +414,7 @@ compute_smooth_position(double timestamp) {
       // The points are different, so we have to do some work.
       // The points are different, so we have to do some work.
       double age = (point_a._timestamp - point_b._timestamp);
       double age = (point_a._timestamp - point_b._timestamp);
     
     
-      if (age > _max_position_age) {
+      if (_default_to_standing_still && (age > _max_position_age)) {
         // If the first point is too old, assume there were a lot of
         // If the first point is too old, assume there were a lot of
         // implicit standing still messages that weren't sent.  Insert a new
         // implicit standing still messages that weren't sent.  Insert a new
         // sample point to reflect this.
         // sample point to reflect this.

+ 4 - 0
direct/src/deadrec/smoothMover.h

@@ -149,6 +149,9 @@ PUBLISHED:
   INLINE void set_directional_velocity(bool flag); 
   INLINE void set_directional_velocity(bool flag); 
   INLINE bool get_directional_velocity(); 
   INLINE bool get_directional_velocity(); 
 
 
+  INLINE void set_default_to_standing_still(bool flag); 
+  INLINE bool get_default_to_standing_still(); 
+
   void output(ostream &out) const;
   void output(ostream &out) const;
   void write(ostream &out) const;
   void write(ostream &out) const;
 
 
@@ -217,6 +220,7 @@ private:
   double _expected_broadcast_period;
   double _expected_broadcast_period;
   double _reset_velocity_age;
   double _reset_velocity_age;
   bool _directional_velocity;
   bool _directional_velocity;
+  bool _default_to_standing_still;
 };
 };
 
 
 #include "smoothMover.I"
 #include "smoothMover.I"