00001 // Filename: smoothMover.I 00002 // Created by: drose (19Oct01) 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: SmoothMover::set_pos 00018 // Access: Published 00019 // Description: Specifies the position of the SmoothMover at a 00020 // particular time in the past. When mark_position() is 00021 // called, this will be recorded (along with hpr and 00022 // timestamp) in a position report, which will then be 00023 // used along with all other position reports to 00024 // determine the smooth position at any particular 00025 // instant. 00026 // 00027 // The return value is true if any parameter has changed 00028 // since the last call to set_pos(), or false if they 00029 // are the same. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE bool SmoothMover:: 00032 set_pos(const LVecBase3 &pos) { 00033 return set_x(pos[0]) | set_y(pos[1]) | set_z(pos[2]); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: SmoothMover::set_pos 00038 // Access: Published 00039 // Description: Specifies the position of the SmoothMover at a 00040 // particular time in the past. When mark_position() is 00041 // called, this will be recorded (along with hpr and 00042 // timestamp) in a position report, which will then be 00043 // used along with all other position reports to 00044 // determine the smooth position at any particular 00045 // instant. 00046 // 00047 // The return value is true if any parameter has changed 00048 // since the last call to set_pos(), or false if they 00049 // are the same. 00050 //////////////////////////////////////////////////////////////////// 00051 INLINE bool SmoothMover:: 00052 set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00053 return set_x(x) | set_y(y) | set_z(z); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: SmoothMover::set_x 00058 // Access: Published 00059 // Description: Sets the X position only. See set_pos(). 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE bool SmoothMover:: 00062 set_x(PN_stdfloat x) { 00063 bool result = (x != _sample._pos[0]); 00064 /* 00065 if (deadrec_cat.is_debug()) { 00066 deadrec_cat.debug() << "set_x " << x << "\n"; 00067 } 00068 */ 00069 _sample._pos[0] = x; 00070 return result; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: SmoothMover::set_y 00075 // Access: Published 00076 // Description: Sets the Y position only. See set_pos(). 00077 //////////////////////////////////////////////////////////////////// 00078 INLINE bool SmoothMover:: 00079 set_y(PN_stdfloat y) { 00080 bool result = (y != _sample._pos[1]); 00081 /* 00082 if (deadrec_cat.is_debug()) { 00083 deadrec_cat.debug() << "set_y " << y << "\n"; 00084 } 00085 */ 00086 _sample._pos[1] = y; 00087 return result; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: SmoothMover::set_z 00092 // Access: Published 00093 // Description: Sets the Z position only. See set_pos(). 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE bool SmoothMover:: 00096 set_z(PN_stdfloat z) { 00097 bool result = (z != _sample._pos[2]); 00098 /* 00099 if (deadrec_cat.is_debug()) { 00100 deadrec_cat.debug() << "set_z " << z << "\n"; 00101 } 00102 */ 00103 _sample._pos[2] = z; 00104 return result; 00105 } 00106 00107 //////////////////////////////////////////////////////////////////// 00108 // Function: SmoothMover::set_hpr 00109 // Access: Published 00110 // Description: Specifies the orientation of the SmoothMover at a 00111 // particular time in the past. When mark_position() is 00112 // called, this will be recorded (along with hpr and 00113 // timestamp) in a position report, which will then be 00114 // used along with all other position reports to 00115 // determine the smooth position at any particular 00116 // instant. 00117 // 00118 // The return value is true if any parameter has changed 00119 // since the last call to set_hpr(), or false if they 00120 // are the same. 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE bool SmoothMover:: 00123 set_hpr(const LVecBase3 &hpr) { 00124 return set_h(hpr[0]) | set_p(hpr[1]) | set_r(hpr[2]); 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: SmoothMover::set_hpr 00129 // Access: Published 00130 // Description: Specifies the orientation of the SmoothMover at a 00131 // particular time in the past. When mark_position() is 00132 // called, this will be recorded (along with hpr and 00133 // timestamp) in a position report, which will then be 00134 // used along with all other position reports to 00135 // determine the smooth position at any particular 00136 // instant. 00137 // 00138 // The return value is true if any parameter has changed 00139 // since the last call to set_hpr(), or false if they 00140 // are the same. 00141 //////////////////////////////////////////////////////////////////// 00142 INLINE bool SmoothMover:: 00143 set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) { 00144 return set_h(h) | set_p(p) | set_r(r); 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: SmoothMover::set_h 00149 // Access: Published 00150 // Description: Sets the heading only. See set_hpr(). 00151 //////////////////////////////////////////////////////////////////// 00152 INLINE bool SmoothMover:: 00153 set_h(PN_stdfloat h) { 00154 bool result = (h != _sample._hpr[0]); 00155 /* 00156 if (deadrec_cat.is_debug()) { 00157 deadrec_cat.debug() << "set_h " << h << "\n"; 00158 } 00159 */ 00160 _sample._hpr[0] = h; 00161 return result; 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: SmoothMover::set_p 00166 // Access: Published 00167 // Description: Sets the pitch only. See set_hpr(). 00168 //////////////////////////////////////////////////////////////////// 00169 INLINE bool SmoothMover:: 00170 set_p(PN_stdfloat p) { 00171 bool result = (p != _sample._hpr[1]); 00172 /* 00173 if (deadrec_cat.is_debug()) { 00174 deadrec_cat.debug() << "set_p " << p << "\n"; 00175 } 00176 */ 00177 _sample._hpr[1] = p; 00178 return result; 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function: SmoothMover::set_r 00183 // Access: Published 00184 // Description: Sets the roll only. See set_hpr(). 00185 //////////////////////////////////////////////////////////////////// 00186 INLINE bool SmoothMover:: 00187 set_r(PN_stdfloat r) { 00188 bool result = (r != _sample._hpr[2]); 00189 /* 00190 if (deadrec_cat.is_debug()) { 00191 deadrec_cat.debug() << "set_r " << r << "\n"; 00192 } 00193 */ 00194 _sample._hpr[2] = r; 00195 return result; 00196 } 00197 00198 //////////////////////////////////////////////////////////////////// 00199 // Function: SmoothMover::set_pos_hpr 00200 // Access: Published 00201 // Description: Specifies the position and orientation of the SmoothMover at a 00202 // particular time in the past. When mark_position() is 00203 // called, this will be recorded (along with 00204 // timestamp) in a position report, which will then be 00205 // used along with all other position reports to 00206 // determine the smooth position at any particular 00207 // instant. 00208 // 00209 // The return value is true if any parameter has changed 00210 // since the last call to set_pos_hpr(), or false if they 00211 // are the same. 00212 //////////////////////////////////////////////////////////////////// 00213 INLINE bool SmoothMover:: 00214 set_pos_hpr(const LVecBase3 &pos, const LVecBase3 &hpr) { 00215 return (set_x(pos[0]) | set_y(pos[1]) | set_z(pos[2]) | 00216 set_h(hpr[0]) | set_p(hpr[1]) | set_r(hpr[2])); 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: SmoothMover::set_pos_hpr 00221 // Access: Published 00222 // Description: Specifies the position of the SmoothMover at a 00223 // particular time in the past. When mark_position() is 00224 // called, this will be recorded (along with 00225 // timestamp) in a position report, which will then be 00226 // used along with all other position reports to 00227 // determine the smooth position at any particular 00228 // instant. 00229 // 00230 // The return value is true if any parameter has changed 00231 // since the last call to set_pos_hpr(), or false if they 00232 // are the same. 00233 //////////////////////////////////////////////////////////////////// 00234 INLINE bool SmoothMover:: 00235 set_pos_hpr(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) { 00236 return set_x(x) | set_y(y) | set_z(z) | set_h(h) | set_p(p) | set_r(r); 00237 } 00238 00239 //////////////////////////////////////////////////////////////////// 00240 // Function: SmoothMover::get_sample_pos 00241 // Access: Published 00242 // Description: Returns the current position of the working sample 00243 // point. This position is updated periodically by 00244 // set_x(), set_y(), etc., and its current value is 00245 // copied to the sample point table when 00246 // mark_position() is called. 00247 //////////////////////////////////////////////////////////////////// 00248 INLINE const LPoint3 &SmoothMover:: 00249 get_sample_pos() const { 00250 return _sample._pos; 00251 } 00252 00253 //////////////////////////////////////////////////////////////////// 00254 // Function: SmoothMover::get_sample_hpr 00255 // Access: Published 00256 // Description: Returns the current orientation of the working sample 00257 // point. This orientation is updated periodically by 00258 // set_h(), set_p(), etc., and its current value is 00259 // copied to the sample point table when 00260 // mark_position() is called. 00261 //////////////////////////////////////////////////////////////////// 00262 INLINE const LVecBase3 &SmoothMover:: 00263 get_sample_hpr() const { 00264 return _sample._hpr; 00265 } 00266 00267 //////////////////////////////////////////////////////////////////// 00268 // Function: SmoothMover::set_phony_timestamp 00269 // Access: Published 00270 // Description: Lies and specifies that the current position report 00271 // was received now. This is usually used for very old 00272 // position reports for which we're not sure of the 00273 // actual receipt time. 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE void SmoothMover:: 00276 set_phony_timestamp(double timestamp, bool period_adjust) { 00277 double now = ClockObject::get_global_clock()->get_frame_time(); 00278 if (timestamp != 0.0) 00279 // we were given a specific timestamp to use 00280 now = timestamp; 00281 00282 // adjust by _delay when creating the timestamp since other 00283 // timestamps received from network updates are adjusted by this 00284 if (period_adjust) { 00285 _sample._timestamp = now - _expected_broadcast_period; 00286 } 00287 else 00288 _sample._timestamp = now; 00289 00290 _has_most_recent_timestamp = true; 00291 _most_recent_timestamp = _sample._timestamp; 00292 00293 } 00294 00295 //////////////////////////////////////////////////////////////////// 00296 // Function: SmoothMover::set_timestamp 00297 // Access: Published 00298 // Description: Specifies the time that the current position report 00299 // applies. This should be called, along with set_pos() 00300 // and set_hpr(), before a call to mark_position(). 00301 //////////////////////////////////////////////////////////////////// 00302 INLINE void SmoothMover:: 00303 set_timestamp(double timestamp) { 00304 /* 00305 if (deadrec_cat.is_debug()) { 00306 deadrec_cat.debug() << "set_timestamp " << timestamp << "\n"; 00307 } 00308 */ 00309 _sample._timestamp = timestamp; 00310 _has_most_recent_timestamp = true; 00311 _most_recent_timestamp = timestamp; 00312 record_timestamp_delay(timestamp); 00313 } 00314 00315 //////////////////////////////////////////////////////////////////// 00316 // Function: SmoothMover::has_most_recent_timestamp 00317 // Access: Published 00318 // Description: Returns true if we have most recently recorded timestamp 00319 //////////////////////////////////////////////////////////////////// 00320 INLINE bool SmoothMover:: 00321 has_most_recent_timestamp() const { 00322 return _has_most_recent_timestamp; 00323 } 00324 00325 //////////////////////////////////////////////////////////////////// 00326 // Function: SmoothMover::get_most_recent_timestamp 00327 // Access: Published 00328 // Description: Returns most recently recorded timestamp 00329 //////////////////////////////////////////////////////////////////// 00330 INLINE double SmoothMover:: 00331 get_most_recent_timestamp() const { 00332 return _most_recent_timestamp; 00333 } 00334 00335 //////////////////////////////////////////////////////////////////// 00336 // Function: SmoothMover::compute_smooth_position 00337 // Access: Published 00338 // Description: Computes the smoothed position (and orientation) of 00339 // the mover at the indicated point in time, based on 00340 // the previous position reports. After this call has 00341 // been made, get_smooth_pos() etc. may be called to 00342 // retrieve the smoothed position. 00343 // 00344 // With no parameter, the function uses 00345 // ClockObject::get_frame_time() as the default time. 00346 //////////////////////////////////////////////////////////////////// 00347 INLINE bool SmoothMover:: 00348 compute_smooth_position() { 00349 return compute_smooth_position(ClockObject::get_global_clock()->get_frame_time()); 00350 } 00351 00352 //////////////////////////////////////////////////////////////////// 00353 // Function: SmoothMover::get_smooth_pos 00354 // Access: Published 00355 // Description: Returns the smoothed position as computed by a 00356 // previous call to compute_smooth_position(). 00357 //////////////////////////////////////////////////////////////////// 00358 INLINE const LPoint3 &SmoothMover:: 00359 get_smooth_pos() const { 00360 return _smooth_pos; 00361 } 00362 00363 //////////////////////////////////////////////////////////////////// 00364 // Function: SmoothMover::get_forward_axis 00365 // Access: Published 00366 // Description: Returns the smoothed position as computed by a 00367 // previous call to compute_smooth_position(). 00368 //////////////////////////////////////////////////////////////////// 00369 INLINE const LVecBase3 &SmoothMover:: 00370 get_forward_axis() const { 00371 return _forward_axis; 00372 } 00373 00374 //////////////////////////////////////////////////////////////////// 00375 // Function: SmoothMover::get_smooth_hpr 00376 // Access: Published 00377 // Description: Returns the smoothed orientation as computed by a 00378 // previous call to compute_smooth_position(). 00379 //////////////////////////////////////////////////////////////////// 00380 INLINE const LVecBase3 &SmoothMover:: 00381 get_smooth_hpr() const { 00382 return _smooth_hpr; 00383 } 00384 00385 //////////////////////////////////////////////////////////////////// 00386 // Function: SmoothMover::apply_smooth_pos 00387 // Access: Published 00388 // Description: Applies the smoothed position to the indicated 00389 // NodePath. This is equivalent to calling 00390 // node.set_pos(smooth_mover->get_smooth_pos()). It 00391 // exists as an optimization only, to avoid the overhead 00392 // of passing the return value through Python. 00393 //////////////////////////////////////////////////////////////////// 00394 INLINE void SmoothMover:: 00395 apply_smooth_pos(NodePath &node) const { 00396 node.set_pos(get_smooth_pos()); 00397 } 00398 00399 //////////////////////////////////////////////////////////////////// 00400 // Function: SmoothMover::apply_smooth_pos_hpr 00401 // Access: Published 00402 // Description: Applies the smoothed position and orientation to the 00403 // indicated NodePath. This is equivalent to calling 00404 // node.set_pos_hpr(smooth_mover->get_smooth_pos(), 00405 // smooth_mover->get_smooth_hpr()). It exists as an 00406 // optimization only, to avoid the overhead of passing 00407 // the return value through Python. 00408 //////////////////////////////////////////////////////////////////// 00409 INLINE void SmoothMover:: 00410 apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) const { 00411 pos_node.set_pos(get_smooth_pos()); 00412 hpr_node.set_hpr(get_smooth_hpr()); 00413 } 00414 00415 //////////////////////////////////////////////////////////////////// 00416 // Function: SmoothMover::apply_smooth_hpr 00417 // Access: Published 00418 // Description: Applies the smoothed orientation to the indicated 00419 // NodePath. This is equivalent to calling 00420 // node.set_hpr(smooth_mover->get_smooth_hpr()). It 00421 // exists as an optimization only, to avoid the overhead 00422 // of passing the return value through Python. 00423 //////////////////////////////////////////////////////////////////// 00424 INLINE void SmoothMover:: 00425 apply_smooth_hpr(NodePath &node) const { 00426 node.set_hpr(get_smooth_hpr()); 00427 } 00428 00429 //////////////////////////////////////////////////////////////////// 00430 // Function: SmoothMover::compute_and_apply_smooth_pos 00431 // Access: Published 00432 // Description: A further optimization to reduce Python calls. This 00433 // computes the smooth position and applies it to the 00434 // indicated node in one call. 00435 //////////////////////////////////////////////////////////////////// 00436 INLINE void SmoothMover:: 00437 compute_and_apply_smooth_pos(NodePath &node) { 00438 if (compute_smooth_position()) { 00439 apply_smooth_pos(node); 00440 } 00441 } 00442 00443 //////////////////////////////////////////////////////////////////// 00444 // Function: SmoothMover::compute_and_apply_smooth_pos_hpr 00445 // Access: Published 00446 // Description: A further optimization to reduce Python calls. This 00447 // computes the smooth position and applies it to the 00448 // indicated node or nodes in one call. The pos_node 00449 // and hpr_node might be the same NodePath. 00450 //////////////////////////////////////////////////////////////////// 00451 INLINE void SmoothMover:: 00452 compute_and_apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) { 00453 if (compute_smooth_position()) { 00454 apply_smooth_pos(pos_node); 00455 apply_smooth_hpr(hpr_node); 00456 } 00457 } 00458 00459 //////////////////////////////////////////////////////////////////// 00460 // Function: SmoothMover::compute_and_apply_smooth_pos_hpr 00461 // Access: Published 00462 // Description: A further optimization to reduce Python calls. This 00463 // computes the smooth position and applies it to the 00464 // indicated node or nodes in one call. The pos_node 00465 // and hpr_node might be the same NodePath. 00466 //////////////////////////////////////////////////////////////////// 00467 INLINE void SmoothMover:: 00468 compute_and_apply_smooth_hpr(NodePath &hpr_node) { 00469 if (compute_smooth_position()) { 00470 apply_smooth_hpr(hpr_node); 00471 } 00472 } 00473 00474 //////////////////////////////////////////////////////////////////// 00475 // Function: SmoothMover::get_smooth_forward_velocity 00476 // Access: Published 00477 // Description: Returns the speed at which the avatar is moving, in 00478 // feet per second, along its own forward axis (after 00479 // applying the avatar's hpr). This will be a positive 00480 // number if the avatar is moving forward, and a 00481 // negative number if it is moving backward. 00482 //////////////////////////////////////////////////////////////////// 00483 INLINE PN_stdfloat SmoothMover:: 00484 get_smooth_forward_velocity() const { 00485 return _smooth_forward_velocity; 00486 } 00487 00488 //////////////////////////////////////////////////////////////////// 00489 // Function: SmoothMover::get_smooth_lateral_velocity 00490 // Access: Published 00491 // Description: Returns the speed at which the avatar is moving, in 00492 // feet per second, along its own lateral axis (after 00493 // applying the avatar's hpr). This will be a positive 00494 // number if the avatar is moving right, and a 00495 // negative number if it is moving left. 00496 //////////////////////////////////////////////////////////////////// 00497 INLINE PN_stdfloat SmoothMover:: 00498 get_smooth_lateral_velocity() const { 00499 return _smooth_lateral_velocity; 00500 } 00501 00502 //////////////////////////////////////////////////////////////////// 00503 // Function: SmoothMover::get_smooth_rotational_velocity 00504 // Access: Published 00505 // Description: Returns the speed at which the avatar is rotating in 00506 // the horizontal plane (i.e. heading), in degrees per 00507 // second. This may be positive or negative, according 00508 // to the direction of rotation. 00509 //////////////////////////////////////////////////////////////////// 00510 INLINE PN_stdfloat SmoothMover:: 00511 get_smooth_rotational_velocity() const { 00512 return _smooth_rotational_velocity; 00513 } 00514 00515 //////////////////////////////////////////////////////////////////// 00516 // Function: SmoothMover::set_smooth_mode 00517 // Access: Published, Static 00518 // Description: Sets the smoothing mode of all SmoothMovers in the 00519 // world. If this is SM_off, no smoothing or prediction 00520 // will be performed, and get_smooth_pos() will simply 00521 // return the position last set by mark_position(). 00522 //////////////////////////////////////////////////////////////////// 00523 INLINE void SmoothMover:: 00524 set_smooth_mode(SmoothMover::SmoothMode mode) { 00525 _smooth_mode = mode; 00526 } 00527 00528 //////////////////////////////////////////////////////////////////// 00529 // Function: SmoothMover::get_smooth_mode 00530 // Access: Published, Static 00531 // Description: Returns the smoothing mode of all SmoothMovers in the 00532 // world. See set_smooth_mode(). 00533 //////////////////////////////////////////////////////////////////// 00534 INLINE SmoothMover::SmoothMode SmoothMover:: 00535 get_smooth_mode() { 00536 return _smooth_mode; 00537 } 00538 00539 //////////////////////////////////////////////////////////////////// 00540 // Function: SmoothMover::set_prediction_mode 00541 // Access: Published, Static 00542 // Description: Sets the predictioning mode of all SmoothMovers in the 00543 // world. If this is PM_off, no prediction will be 00544 // performed, but smoothing might still be performed. 00545 //////////////////////////////////////////////////////////////////// 00546 INLINE void SmoothMover:: 00547 set_prediction_mode(SmoothMover::PredictionMode mode) { 00548 _prediction_mode = mode; 00549 } 00550 00551 //////////////////////////////////////////////////////////////////// 00552 // Function: SmoothMover::get_prediction_mode 00553 // Access: Published, Static 00554 // Description: Returns the predictioning mode of all SmoothMovers in the 00555 // world. See set_prediction_mode(). 00556 //////////////////////////////////////////////////////////////////// 00557 INLINE SmoothMover::PredictionMode SmoothMover:: 00558 get_prediction_mode() { 00559 return _prediction_mode; 00560 } 00561 00562 //////////////////////////////////////////////////////////////////// 00563 // Function: SmoothMover::set_delay 00564 // Access: Published, Static 00565 // Description: Sets the amount of time, in seconds, to delay the 00566 // computed position of a SmoothMover. This is 00567 // particularly useful when the prediction mode is off, 00568 // because it can allow the apparent motion of an avatar 00569 // to appear smooth without relying on prediction, at 00570 // the cost of introducing additional lag in the 00571 // avatar's apparent position. 00572 //////////////////////////////////////////////////////////////////// 00573 INLINE void SmoothMover:: 00574 set_delay(double delay) { 00575 _delay = delay; 00576 } 00577 00578 //////////////////////////////////////////////////////////////////// 00579 // Function: SmoothMover::get_delay 00580 // Access: Published, Static 00581 // Description: Returns the amount of time, in seconds, to delay the 00582 // computed position of a SmoothMover. See set_delay(). 00583 //////////////////////////////////////////////////////////////////// 00584 INLINE double SmoothMover:: 00585 get_delay() { 00586 return _delay; 00587 } 00588 00589 //////////////////////////////////////////////////////////////////// 00590 // Function: SmoothMover::set_accept_clock_skew 00591 // Access: Published, Static 00592 // Description: Sets the 'accept clock skew' flag. When this flag is 00593 // true, clock skew from the other clients will be 00594 // tolerated by delaying each smooth mover's position an 00595 // additional amount, on top of that specified by 00596 // set_delay(), based on the measured average latency 00597 // for timestamp messages received by the client. 00598 // 00599 // In this way, if the other client has significant 00600 // clock skew with respect to our clock, it will be 00601 // evident as a large positive or negative average 00602 // latency for timestamps. By subtracting out this 00603 // average latency, we compensate for poor clock sync. 00604 //////////////////////////////////////////////////////////////////// 00605 INLINE void SmoothMover:: 00606 set_accept_clock_skew(bool flag) { 00607 _accept_clock_skew = flag; 00608 } 00609 00610 //////////////////////////////////////////////////////////////////// 00611 // Function: SmoothMover::get_accept_clock_skew 00612 // Access: Published, Static 00613 // Description: Returns the current state of the 'accept clock skew' 00614 // flag. See set_accept_clock_skew(). 00615 //////////////////////////////////////////////////////////////////// 00616 INLINE bool SmoothMover:: 00617 get_accept_clock_skew() { 00618 return _accept_clock_skew; 00619 } 00620 00621 //////////////////////////////////////////////////////////////////// 00622 // Function: SmoothMover::set_max_position_age 00623 // Access: Published, Static 00624 // Description: Sets the maximum amount of time a position is allowed 00625 // to remain unchanged before assuming it represents the 00626 // avatar actually standing still. 00627 //////////////////////////////////////////////////////////////////// 00628 INLINE void SmoothMover:: 00629 set_max_position_age(double age) { 00630 _max_position_age = age; 00631 } 00632 00633 //////////////////////////////////////////////////////////////////// 00634 // Function: SmoothMover::get_max_position_age 00635 // Access: Published, Static 00636 // Description: Returns the maximum amount of time a position is 00637 // allowed to remain unchanged before assuming it 00638 // represents the avatar actually standing still. 00639 //////////////////////////////////////////////////////////////////// 00640 INLINE double SmoothMover:: 00641 get_max_position_age() { 00642 return _max_position_age; 00643 } 00644 00645 //////////////////////////////////////////////////////////////////// 00646 // Function: SmoothMover::set_expected_broadcast_period 00647 // Access: Published, Static 00648 // Description: Sets the interval at which we expect the SmoothNodes 00649 // to broadcast their position, in elapsed seconds. 00650 // This controls the length of time we assume the object 00651 // has truly stopped, when we receive a long sequence of 00652 // no updates. 00653 //////////////////////////////////////////////////////////////////// 00654 INLINE void SmoothMover:: 00655 set_expected_broadcast_period(double period) { 00656 _expected_broadcast_period = period; 00657 } 00658 00659 //////////////////////////////////////////////////////////////////// 00660 // Function: SmoothMover::get_expected_broadcast_period 00661 // Access: Published, Static 00662 // Description: Returns the interval at which we expect the SmoothNodes 00663 // to broadcast their position, in elapsed seconds. See 00664 // set_expected_broadcast_period(). 00665 //////////////////////////////////////////////////////////////////// 00666 INLINE double SmoothMover:: 00667 get_expected_broadcast_period() { 00668 return _expected_broadcast_period; 00669 } 00670 00671 //////////////////////////////////////////////////////////////////// 00672 // Function: SmoothMover::set_reset_velocity_age 00673 // Access: Published, Static 00674 // Description: Sets the amount of time that should elapse after the 00675 // last position report before the velocity is reset to 00676 // 0. This is similar to max_position_age, but it is 00677 // only used to determine the resetting of the reported 00678 // velocity. It should always be greater than or equal 00679 // to max_position_age. 00680 //////////////////////////////////////////////////////////////////// 00681 INLINE void SmoothMover:: 00682 set_reset_velocity_age(double age) { 00683 _reset_velocity_age = age; 00684 } 00685 00686 //////////////////////////////////////////////////////////////////// 00687 // Function: SmoothMover::get_reset_velocity_age 00688 // Access: Published, Static 00689 // Description: Returns the amount of time that should elapse after 00690 // the last position report before the velocity is reset 00691 // to 0. See set_reset_velocity_age(). 00692 //////////////////////////////////////////////////////////////////// 00693 INLINE double SmoothMover:: 00694 get_reset_velocity_age() { 00695 return _reset_velocity_age; 00696 } 00697 00698 //////////////////////////////////////////////////////////////////// 00699 // Function: SmoothMover::set_directional_velocity 00700 // Access: Published, Static 00701 // Description: Sets the flag that indicates whether the avatar's 00702 // direction is considered in computing the velocity. 00703 // When this is true, velocity is automatically 00704 // decomposed into a forward and a lateral velocity (and 00705 // both may be positive or negative); when it is false, 00706 // all velocity is always returned as forward velocity 00707 // (and it is always positive). 00708 //////////////////////////////////////////////////////////////////// 00709 INLINE void SmoothMover:: 00710 set_directional_velocity(bool flag) { 00711 _directional_velocity = flag; 00712 } 00713 00714 //////////////////////////////////////////////////////////////////// 00715 // Function: SmoothMover::get_directional_velocity 00716 // Access: Published, Static 00717 // Description: Returns the current state of the 'directional 00718 // velocity' flag. See set_directional_velocity(). 00719 //////////////////////////////////////////////////////////////////// 00720 INLINE bool SmoothMover:: 00721 get_directional_velocity() { 00722 return _directional_velocity; 00723 } 00724 00725 //////////////////////////////////////////////////////////////////// 00726 // Function: SmoothMover::set_default_to_standing_still 00727 // Access: Published, Static 00728 // Description: Sets the flag that indicates whether to assume that 00729 // the node stopped moving during periods when we don't 00730 // get enough position updates. If true, the object will 00731 // stand still momentarily. If false, the object will 00732 // continuously lerp between the position updates that 00733 // we did get. 00734 //////////////////////////////////////////////////////////////////// 00735 INLINE void SmoothMover:: 00736 set_default_to_standing_still(bool flag) { 00737 _default_to_standing_still = flag; 00738 } 00739 00740 //////////////////////////////////////////////////////////////////// 00741 // Function: SmoothMover::get_default_to_standing_still 00742 // Access: Published, Static 00743 // Description: Returns the current state of the 'default to standing 00744 // still' flag. See set_default_to_standing_still(). 00745 //////////////////////////////////////////////////////////////////// 00746 INLINE bool SmoothMover:: 00747 get_default_to_standing_still() { 00748 return _default_to_standing_still; 00749 } 00750 00751 //////////////////////////////////////////////////////////////////// 00752 // Function: SmoothMover::get_avg_timestamp_delay 00753 // Access: Private 00754 // Description: Returns the average delay observed in the last n 00755 // timestamps received from this client, in seconds. 00756 // This number represents the combination of the network 00757 // lag from this client, as well as the client's clock 00758 // skew relative to our clock. It could be negative if 00759 // the client's clock is running faster than our clock. 00760 //////////////////////////////////////////////////////////////////// 00761 INLINE double SmoothMover:: 00762 get_avg_timestamp_delay() const { 00763 nassertr(!_timestamp_delays.empty(), 0.0); 00764 return (double)_net_timestamp_delay / (double)_timestamp_delays.size() / 1000.0; 00765 }