Panda3D
 All Classes Functions Variables Enumerations
smoothMover.I
1 // Filename: smoothMover.I
2 // Created by: drose (19Oct01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: SmoothMover::set_pos
18 // Access: Published
19 // Description: Specifies the position of the SmoothMover at a
20 // particular time in the past. When mark_position() is
21 // called, this will be recorded (along with hpr and
22 // timestamp) in a position report, which will then be
23 // used along with all other position reports to
24 // determine the smooth position at any particular
25 // instant.
26 //
27 // The return value is true if any parameter has changed
28 // since the last call to set_pos(), or false if they
29 // are the same.
30 ////////////////////////////////////////////////////////////////////
31 INLINE bool SmoothMover::
32 set_pos(const LVecBase3 &pos) {
33  return set_x(pos[0]) | set_y(pos[1]) | set_z(pos[2]);
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: SmoothMover::set_pos
38 // Access: Published
39 // Description: Specifies the position of the SmoothMover at a
40 // particular time in the past. When mark_position() is
41 // called, this will be recorded (along with hpr and
42 // timestamp) in a position report, which will then be
43 // used along with all other position reports to
44 // determine the smooth position at any particular
45 // instant.
46 //
47 // The return value is true if any parameter has changed
48 // since the last call to set_pos(), or false if they
49 // are the same.
50 ////////////////////////////////////////////////////////////////////
51 INLINE bool SmoothMover::
52 set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
53  return set_x(x) | set_y(y) | set_z(z);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: SmoothMover::set_x
58 // Access: Published
59 // Description: Sets the X position only. See set_pos().
60 ////////////////////////////////////////////////////////////////////
61 INLINE bool SmoothMover::
62 set_x(PN_stdfloat x) {
63  bool result = (x != _sample._pos[0]);
64  /*
65  if (deadrec_cat.is_debug()) {
66  deadrec_cat.debug() << "set_x " << x << "\n";
67  }
68  */
69  _sample._pos[0] = x;
70  return result;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: SmoothMover::set_y
75 // Access: Published
76 // Description: Sets the Y position only. See set_pos().
77 ////////////////////////////////////////////////////////////////////
78 INLINE bool SmoothMover::
79 set_y(PN_stdfloat y) {
80  bool result = (y != _sample._pos[1]);
81  /*
82  if (deadrec_cat.is_debug()) {
83  deadrec_cat.debug() << "set_y " << y << "\n";
84  }
85  */
86  _sample._pos[1] = y;
87  return result;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: SmoothMover::set_z
92 // Access: Published
93 // Description: Sets the Z position only. See set_pos().
94 ////////////////////////////////////////////////////////////////////
95 INLINE bool SmoothMover::
96 set_z(PN_stdfloat z) {
97  bool result = (z != _sample._pos[2]);
98  /*
99  if (deadrec_cat.is_debug()) {
100  deadrec_cat.debug() << "set_z " << z << "\n";
101  }
102  */
103  _sample._pos[2] = z;
104  return result;
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: SmoothMover::set_hpr
109 // Access: Published
110 // Description: Specifies the orientation of the SmoothMover at a
111 // particular time in the past. When mark_position() is
112 // called, this will be recorded (along with hpr and
113 // timestamp) in a position report, which will then be
114 // used along with all other position reports to
115 // determine the smooth position at any particular
116 // instant.
117 //
118 // The return value is true if any parameter has changed
119 // since the last call to set_hpr(), or false if they
120 // are the same.
121 ////////////////////////////////////////////////////////////////////
122 INLINE bool SmoothMover::
123 set_hpr(const LVecBase3 &hpr) {
124  return set_h(hpr[0]) | set_p(hpr[1]) | set_r(hpr[2]);
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: SmoothMover::set_hpr
129 // Access: Published
130 // Description: Specifies the orientation of the SmoothMover at a
131 // particular time in the past. When mark_position() is
132 // called, this will be recorded (along with hpr and
133 // timestamp) in a position report, which will then be
134 // used along with all other position reports to
135 // determine the smooth position at any particular
136 // instant.
137 //
138 // The return value is true if any parameter has changed
139 // since the last call to set_hpr(), or false if they
140 // are the same.
141 ////////////////////////////////////////////////////////////////////
142 INLINE bool SmoothMover::
143 set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) {
144  return set_h(h) | set_p(p) | set_r(r);
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: SmoothMover::set_h
149 // Access: Published
150 // Description: Sets the heading only. See set_hpr().
151 ////////////////////////////////////////////////////////////////////
152 INLINE bool SmoothMover::
153 set_h(PN_stdfloat h) {
154  bool result = (h != _sample._hpr[0]);
155  /*
156  if (deadrec_cat.is_debug()) {
157  deadrec_cat.debug() << "set_h " << h << "\n";
158  }
159  */
160  _sample._hpr[0] = h;
161  return result;
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: SmoothMover::set_p
166 // Access: Published
167 // Description: Sets the pitch only. See set_hpr().
168 ////////////////////////////////////////////////////////////////////
169 INLINE bool SmoothMover::
170 set_p(PN_stdfloat p) {
171  bool result = (p != _sample._hpr[1]);
172  /*
173  if (deadrec_cat.is_debug()) {
174  deadrec_cat.debug() << "set_p " << p << "\n";
175  }
176  */
177  _sample._hpr[1] = p;
178  return result;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: SmoothMover::set_r
183 // Access: Published
184 // Description: Sets the roll only. See set_hpr().
185 ////////////////////////////////////////////////////////////////////
186 INLINE bool SmoothMover::
187 set_r(PN_stdfloat r) {
188  bool result = (r != _sample._hpr[2]);
189  /*
190  if (deadrec_cat.is_debug()) {
191  deadrec_cat.debug() << "set_r " << r << "\n";
192  }
193  */
194  _sample._hpr[2] = r;
195  return result;
196 }
197 
198 ////////////////////////////////////////////////////////////////////
199 // Function: SmoothMover::set_pos_hpr
200 // Access: Published
201 // Description: Specifies the position and orientation of the SmoothMover at a
202 // particular time in the past. When mark_position() is
203 // called, this will be recorded (along with
204 // timestamp) in a position report, which will then be
205 // used along with all other position reports to
206 // determine the smooth position at any particular
207 // instant.
208 //
209 // The return value is true if any parameter has changed
210 // since the last call to set_pos_hpr(), or false if they
211 // are the same.
212 ////////////////////////////////////////////////////////////////////
213 INLINE bool SmoothMover::
214 set_pos_hpr(const LVecBase3 &pos, const LVecBase3 &hpr) {
215  return (set_x(pos[0]) | set_y(pos[1]) | set_z(pos[2]) |
216  set_h(hpr[0]) | set_p(hpr[1]) | set_r(hpr[2]));
217 }
218 
219 ////////////////////////////////////////////////////////////////////
220 // Function: SmoothMover::set_pos_hpr
221 // Access: Published
222 // Description: Specifies the position of the SmoothMover at a
223 // particular time in the past. When mark_position() is
224 // called, this will be recorded (along with
225 // timestamp) in a position report, which will then be
226 // used along with all other position reports to
227 // determine the smooth position at any particular
228 // instant.
229 //
230 // The return value is true if any parameter has changed
231 // since the last call to set_pos_hpr(), or false if they
232 // are the same.
233 ////////////////////////////////////////////////////////////////////
234 INLINE bool SmoothMover::
235 set_pos_hpr(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat h, PN_stdfloat p, PN_stdfloat r) {
236  return set_x(x) | set_y(y) | set_z(z) | set_h(h) | set_p(p) | set_r(r);
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: SmoothMover::get_sample_pos
241 // Access: Published
242 // Description: Returns the current position of the working sample
243 // point. This position is updated periodically by
244 // set_x(), set_y(), etc., and its current value is
245 // copied to the sample point table when
246 // mark_position() is called.
247 ////////////////////////////////////////////////////////////////////
248 INLINE const LPoint3 &SmoothMover::
249 get_sample_pos() const {
250  return _sample._pos;
251 }
252 
253 ////////////////////////////////////////////////////////////////////
254 // Function: SmoothMover::get_sample_hpr
255 // Access: Published
256 // Description: Returns the current orientation of the working sample
257 // point. This orientation is updated periodically by
258 // set_h(), set_p(), etc., and its current value is
259 // copied to the sample point table when
260 // mark_position() is called.
261 ////////////////////////////////////////////////////////////////////
262 INLINE const LVecBase3 &SmoothMover::
263 get_sample_hpr() const {
264  return _sample._hpr;
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function: SmoothMover::set_phony_timestamp
269 // Access: Published
270 // Description: Lies and specifies that the current position report
271 // was received now. This is usually used for very old
272 // position reports for which we're not sure of the
273 // actual receipt time.
274 ////////////////////////////////////////////////////////////////////
275 INLINE void SmoothMover::
276 set_phony_timestamp(double timestamp, bool period_adjust) {
278  if (timestamp != 0.0)
279  // we were given a specific timestamp to use
280  now = timestamp;
281 
282  // adjust by _delay when creating the timestamp since other
283  // timestamps received from network updates are adjusted by this
284  if (period_adjust) {
285  _sample._timestamp = now - _expected_broadcast_period;
286  }
287  else
288  _sample._timestamp = now;
289 
290  _has_most_recent_timestamp = true;
291  _most_recent_timestamp = _sample._timestamp;
292 
293 }
294 
295 ////////////////////////////////////////////////////////////////////
296 // Function: SmoothMover::set_timestamp
297 // Access: Published
298 // Description: Specifies the time that the current position report
299 // applies. This should be called, along with set_pos()
300 // and set_hpr(), before a call to mark_position().
301 ////////////////////////////////////////////////////////////////////
302 INLINE void SmoothMover::
303 set_timestamp(double timestamp) {
304  /*
305  if (deadrec_cat.is_debug()) {
306  deadrec_cat.debug() << "set_timestamp " << timestamp << "\n";
307  }
308  */
309  _sample._timestamp = timestamp;
310  _has_most_recent_timestamp = true;
311  _most_recent_timestamp = timestamp;
312  record_timestamp_delay(timestamp);
313 }
314 
315 ////////////////////////////////////////////////////////////////////
316 // Function: SmoothMover::has_most_recent_timestamp
317 // Access: Published
318 // Description: Returns true if we have most recently recorded timestamp
319 ////////////////////////////////////////////////////////////////////
320 INLINE bool SmoothMover::
322  return _has_most_recent_timestamp;
323 }
324 
325 ////////////////////////////////////////////////////////////////////
326 // Function: SmoothMover::get_most_recent_timestamp
327 // Access: Published
328 // Description: Returns most recently recorded timestamp
329 ////////////////////////////////////////////////////////////////////
330 INLINE double SmoothMover::
332  return _most_recent_timestamp;
333 }
334 
335 ////////////////////////////////////////////////////////////////////
336 // Function: SmoothMover::compute_smooth_position
337 // Access: Published
338 // Description: Computes the smoothed position (and orientation) of
339 // the mover at the indicated point in time, based on
340 // the previous position reports. After this call has
341 // been made, get_smooth_pos() etc. may be called to
342 // retrieve the smoothed position.
343 //
344 // With no parameter, the function uses
345 // ClockObject::get_frame_time() as the default time.
346 ////////////////////////////////////////////////////////////////////
347 INLINE bool SmoothMover::
349  return compute_smooth_position(ClockObject::get_global_clock()->get_frame_time());
350 }
351 
352 ////////////////////////////////////////////////////////////////////
353 // Function: SmoothMover::get_smooth_pos
354 // Access: Published
355 // Description: Returns the smoothed position as computed by a
356 // previous call to compute_smooth_position().
357 ////////////////////////////////////////////////////////////////////
358 INLINE const LPoint3 &SmoothMover::
359 get_smooth_pos() const {
360  return _smooth_pos;
361 }
362 
363 ////////////////////////////////////////////////////////////////////
364 // Function: SmoothMover::get_forward_axis
365 // Access: Published
366 // Description: Returns the smoothed position as computed by a
367 // previous call to compute_smooth_position().
368 ////////////////////////////////////////////////////////////////////
369 INLINE const LVecBase3 &SmoothMover::
371  return _forward_axis;
372 }
373 
374 ////////////////////////////////////////////////////////////////////
375 // Function: SmoothMover::get_smooth_hpr
376 // Access: Published
377 // Description: Returns the smoothed orientation as computed by a
378 // previous call to compute_smooth_position().
379 ////////////////////////////////////////////////////////////////////
380 INLINE const LVecBase3 &SmoothMover::
381 get_smooth_hpr() const {
382  return _smooth_hpr;
383 }
384 
385 ////////////////////////////////////////////////////////////////////
386 // Function: SmoothMover::apply_smooth_pos
387 // Access: Published
388 // Description: Applies the smoothed position to the indicated
389 // NodePath. This is equivalent to calling
390 // node.set_pos(smooth_mover->get_smooth_pos()). It
391 // exists as an optimization only, to avoid the overhead
392 // of passing the return value through Python.
393 ////////////////////////////////////////////////////////////////////
394 INLINE void SmoothMover::
396  node.set_pos(get_smooth_pos());
397 }
398 
399 ////////////////////////////////////////////////////////////////////
400 // Function: SmoothMover::apply_smooth_pos_hpr
401 // Access: Published
402 // Description: Applies the smoothed position and orientation to the
403 // indicated NodePath. This is equivalent to calling
404 // node.set_pos_hpr(smooth_mover->get_smooth_pos(),
405 // smooth_mover->get_smooth_hpr()). It exists as an
406 // optimization only, to avoid the overhead of passing
407 // the return value through Python.
408 ////////////////////////////////////////////////////////////////////
409 INLINE void SmoothMover::
410 apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) const {
411  pos_node.set_pos(get_smooth_pos());
412  hpr_node.set_hpr(get_smooth_hpr());
413 }
414 
415 ////////////////////////////////////////////////////////////////////
416 // Function: SmoothMover::apply_smooth_hpr
417 // Access: Published
418 // Description: Applies the smoothed orientation to the indicated
419 // NodePath. This is equivalent to calling
420 // node.set_hpr(smooth_mover->get_smooth_hpr()). It
421 // exists as an optimization only, to avoid the overhead
422 // of passing the return value through Python.
423 ////////////////////////////////////////////////////////////////////
424 INLINE void SmoothMover::
426  node.set_hpr(get_smooth_hpr());
427 }
428 
429 ////////////////////////////////////////////////////////////////////
430 // Function: SmoothMover::compute_and_apply_smooth_pos
431 // Access: Published
432 // Description: A further optimization to reduce Python calls. This
433 // computes the smooth position and applies it to the
434 // indicated node in one call.
435 ////////////////////////////////////////////////////////////////////
436 INLINE void SmoothMover::
438  if (compute_smooth_position()) {
439  apply_smooth_pos(node);
440  }
441 }
442 
443 ////////////////////////////////////////////////////////////////////
444 // Function: SmoothMover::compute_and_apply_smooth_pos_hpr
445 // Access: Published
446 // Description: A further optimization to reduce Python calls. This
447 // computes the smooth position and applies it to the
448 // indicated node or nodes in one call. The pos_node
449 // and hpr_node might be the same NodePath.
450 ////////////////////////////////////////////////////////////////////
451 INLINE void SmoothMover::
453  if (compute_smooth_position()) {
454  apply_smooth_pos(pos_node);
455  apply_smooth_hpr(hpr_node);
456  }
457 }
458 
459 ////////////////////////////////////////////////////////////////////
460 // Function: SmoothMover::compute_and_apply_smooth_pos_hpr
461 // Access: Published
462 // Description: A further optimization to reduce Python calls. This
463 // computes the smooth position and applies it to the
464 // indicated node or nodes in one call. The pos_node
465 // and hpr_node might be the same NodePath.
466 ////////////////////////////////////////////////////////////////////
467 INLINE void SmoothMover::
469  if (compute_smooth_position()) {
470  apply_smooth_hpr(hpr_node);
471  }
472 }
473 
474 ////////////////////////////////////////////////////////////////////
475 // Function: SmoothMover::get_smooth_forward_velocity
476 // Access: Published
477 // Description: Returns the speed at which the avatar is moving, in
478 // feet per second, along its own forward axis (after
479 // applying the avatar's hpr). This will be a positive
480 // number if the avatar is moving forward, and a
481 // negative number if it is moving backward.
482 ////////////////////////////////////////////////////////////////////
483 INLINE PN_stdfloat SmoothMover::
485  return _smooth_forward_velocity;
486 }
487 
488 ////////////////////////////////////////////////////////////////////
489 // Function: SmoothMover::get_smooth_lateral_velocity
490 // Access: Published
491 // Description: Returns the speed at which the avatar is moving, in
492 // feet per second, along its own lateral axis (after
493 // applying the avatar's hpr). This will be a positive
494 // number if the avatar is moving right, and a
495 // negative number if it is moving left.
496 ////////////////////////////////////////////////////////////////////
497 INLINE PN_stdfloat SmoothMover::
499  return _smooth_lateral_velocity;
500 }
501 
502 ////////////////////////////////////////////////////////////////////
503 // Function: SmoothMover::get_smooth_rotational_velocity
504 // Access: Published
505 // Description: Returns the speed at which the avatar is rotating in
506 // the horizontal plane (i.e. heading), in degrees per
507 // second. This may be positive or negative, according
508 // to the direction of rotation.
509 ////////////////////////////////////////////////////////////////////
510 INLINE PN_stdfloat SmoothMover::
512  return _smooth_rotational_velocity;
513 }
514 
515 ////////////////////////////////////////////////////////////////////
516 // Function: SmoothMover::set_smooth_mode
517 // Access: Published, Static
518 // Description: Sets the smoothing mode of all SmoothMovers in the
519 // world. If this is SM_off, no smoothing or prediction
520 // will be performed, and get_smooth_pos() will simply
521 // return the position last set by mark_position().
522 ////////////////////////////////////////////////////////////////////
523 INLINE void SmoothMover::
524 set_smooth_mode(SmoothMover::SmoothMode mode) {
525  _smooth_mode = mode;
526 }
527 
528 ////////////////////////////////////////////////////////////////////
529 // Function: SmoothMover::get_smooth_mode
530 // Access: Published, Static
531 // Description: Returns the smoothing mode of all SmoothMovers in the
532 // world. See set_smooth_mode().
533 ////////////////////////////////////////////////////////////////////
534 INLINE SmoothMover::SmoothMode SmoothMover::
536  return _smooth_mode;
537 }
538 
539 ////////////////////////////////////////////////////////////////////
540 // Function: SmoothMover::set_prediction_mode
541 // Access: Published, Static
542 // Description: Sets the predictioning mode of all SmoothMovers in the
543 // world. If this is PM_off, no prediction will be
544 // performed, but smoothing might still be performed.
545 ////////////////////////////////////////////////////////////////////
546 INLINE void SmoothMover::
547 set_prediction_mode(SmoothMover::PredictionMode mode) {
548  _prediction_mode = mode;
549 }
550 
551 ////////////////////////////////////////////////////////////////////
552 // Function: SmoothMover::get_prediction_mode
553 // Access: Published, Static
554 // Description: Returns the predictioning mode of all SmoothMovers in the
555 // world. See set_prediction_mode().
556 ////////////////////////////////////////////////////////////////////
557 INLINE SmoothMover::PredictionMode SmoothMover::
559  return _prediction_mode;
560 }
561 
562 ////////////////////////////////////////////////////////////////////
563 // Function: SmoothMover::set_delay
564 // Access: Published, Static
565 // Description: Sets the amount of time, in seconds, to delay the
566 // computed position of a SmoothMover. This is
567 // particularly useful when the prediction mode is off,
568 // because it can allow the apparent motion of an avatar
569 // to appear smooth without relying on prediction, at
570 // the cost of introducing additional lag in the
571 // avatar's apparent position.
572 ////////////////////////////////////////////////////////////////////
573 INLINE void SmoothMover::
574 set_delay(double delay) {
575  _delay = delay;
576 }
577 
578 ////////////////////////////////////////////////////////////////////
579 // Function: SmoothMover::get_delay
580 // Access: Published, Static
581 // Description: Returns the amount of time, in seconds, to delay the
582 // computed position of a SmoothMover. See set_delay().
583 ////////////////////////////////////////////////////////////////////
584 INLINE double SmoothMover::
586  return _delay;
587 }
588 
589 ////////////////////////////////////////////////////////////////////
590 // Function: SmoothMover::set_accept_clock_skew
591 // Access: Published, Static
592 // Description: Sets the 'accept clock skew' flag. When this flag is
593 // true, clock skew from the other clients will be
594 // tolerated by delaying each smooth mover's position an
595 // additional amount, on top of that specified by
596 // set_delay(), based on the measured average latency
597 // for timestamp messages received by the client.
598 //
599 // In this way, if the other client has significant
600 // clock skew with respect to our clock, it will be
601 // evident as a large positive or negative average
602 // latency for timestamps. By subtracting out this
603 // average latency, we compensate for poor clock sync.
604 ////////////////////////////////////////////////////////////////////
605 INLINE void SmoothMover::
607  _accept_clock_skew = flag;
608 }
609 
610 ////////////////////////////////////////////////////////////////////
611 // Function: SmoothMover::get_accept_clock_skew
612 // Access: Published, Static
613 // Description: Returns the current state of the 'accept clock skew'
614 // flag. See set_accept_clock_skew().
615 ////////////////////////////////////////////////////////////////////
616 INLINE bool SmoothMover::
618  return _accept_clock_skew;
619 }
620 
621 ////////////////////////////////////////////////////////////////////
622 // Function: SmoothMover::set_max_position_age
623 // Access: Published, Static
624 // Description: Sets the maximum amount of time a position is allowed
625 // to remain unchanged before assuming it represents the
626 // avatar actually standing still.
627 ////////////////////////////////////////////////////////////////////
628 INLINE void SmoothMover::
629 set_max_position_age(double age) {
630  _max_position_age = age;
631 }
632 
633 ////////////////////////////////////////////////////////////////////
634 // Function: SmoothMover::get_max_position_age
635 // Access: Published, Static
636 // Description: Returns the maximum amount of time a position is
637 // allowed to remain unchanged before assuming it
638 // represents the avatar actually standing still.
639 ////////////////////////////////////////////////////////////////////
640 INLINE double SmoothMover::
642  return _max_position_age;
643 }
644 
645 ////////////////////////////////////////////////////////////////////
646 // Function: SmoothMover::set_expected_broadcast_period
647 // Access: Published, Static
648 // Description: Sets the interval at which we expect the SmoothNodes
649 // to broadcast their position, in elapsed seconds.
650 // This controls the length of time we assume the object
651 // has truly stopped, when we receive a long sequence of
652 // no updates.
653 ////////////////////////////////////////////////////////////////////
654 INLINE void SmoothMover::
656  _expected_broadcast_period = period;
657 }
658 
659 ////////////////////////////////////////////////////////////////////
660 // Function: SmoothMover::get_expected_broadcast_period
661 // Access: Published, Static
662 // Description: Returns the interval at which we expect the SmoothNodes
663 // to broadcast their position, in elapsed seconds. See
664 // set_expected_broadcast_period().
665 ////////////////////////////////////////////////////////////////////
666 INLINE double SmoothMover::
668  return _expected_broadcast_period;
669 }
670 
671 ////////////////////////////////////////////////////////////////////
672 // Function: SmoothMover::set_reset_velocity_age
673 // Access: Published, Static
674 // Description: Sets the amount of time that should elapse after the
675 // last position report before the velocity is reset to
676 // 0. This is similar to max_position_age, but it is
677 // only used to determine the resetting of the reported
678 // velocity. It should always be greater than or equal
679 // to max_position_age.
680 ////////////////////////////////////////////////////////////////////
681 INLINE void SmoothMover::
683  _reset_velocity_age = age;
684 }
685 
686 ////////////////////////////////////////////////////////////////////
687 // Function: SmoothMover::get_reset_velocity_age
688 // Access: Published, Static
689 // Description: Returns the amount of time that should elapse after
690 // the last position report before the velocity is reset
691 // to 0. See set_reset_velocity_age().
692 ////////////////////////////////////////////////////////////////////
693 INLINE double SmoothMover::
695  return _reset_velocity_age;
696 }
697 
698 ////////////////////////////////////////////////////////////////////
699 // Function: SmoothMover::set_directional_velocity
700 // Access: Published, Static
701 // Description: Sets the flag that indicates whether the avatar's
702 // direction is considered in computing the velocity.
703 // When this is true, velocity is automatically
704 // decomposed into a forward and a lateral velocity (and
705 // both may be positive or negative); when it is false,
706 // all velocity is always returned as forward velocity
707 // (and it is always positive).
708 ////////////////////////////////////////////////////////////////////
709 INLINE void SmoothMover::
711  _directional_velocity = flag;
712 }
713 
714 ////////////////////////////////////////////////////////////////////
715 // Function: SmoothMover::get_directional_velocity
716 // Access: Published, Static
717 // Description: Returns the current state of the 'directional
718 // velocity' flag. See set_directional_velocity().
719 ////////////////////////////////////////////////////////////////////
720 INLINE bool SmoothMover::
722  return _directional_velocity;
723 }
724 
725 ////////////////////////////////////////////////////////////////////
726 // Function: SmoothMover::set_default_to_standing_still
727 // Access: Published, Static
728 // Description: Sets the flag that indicates whether to assume that
729 // the node stopped moving during periods when we don't
730 // get enough position updates. If true, the object will
731 // stand still momentarily. If false, the object will
732 // continuously lerp between the position updates that
733 // we did get.
734 ////////////////////////////////////////////////////////////////////
735 INLINE void SmoothMover::
737  _default_to_standing_still = flag;
738 }
739 
740 ////////////////////////////////////////////////////////////////////
741 // Function: SmoothMover::get_default_to_standing_still
742 // Access: Published, Static
743 // Description: Returns the current state of the 'default to standing
744 // still' flag. See set_default_to_standing_still().
745 ////////////////////////////////////////////////////////////////////
746 INLINE bool SmoothMover::
748  return _default_to_standing_still;
749 }
750 
751 ////////////////////////////////////////////////////////////////////
752 // Function: SmoothMover::get_avg_timestamp_delay
753 // Access: Private
754 // Description: Returns the average delay observed in the last n
755 // timestamps received from this client, in seconds.
756 // This number represents the combination of the network
757 // lag from this client, as well as the client's clock
758 // skew relative to our clock. It could be negative if
759 // the client's clock is running faster than our clock.
760 ////////////////////////////////////////////////////////////////////
761 INLINE double SmoothMover::
762 get_avg_timestamp_delay() const {
763  nassertr(!_timestamp_delays.empty(), 0.0);
764  return (double)_net_timestamp_delay / (double)_timestamp_delays.size() / 1000.0;
765 }
void compute_and_apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node)
A further optimization to reduce Python calls.
Definition: smoothMover.I:452
double get_most_recent_timestamp() const
Returns most recently recorded timestamp.
Definition: smoothMover.I:331
bool set_h(PN_stdfloat h)
Sets the heading only.
Definition: smoothMover.I:153
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Definition: clockObject.I:271
void set_phony_timestamp(double timestamp=0.0, bool period_adjust=false)
Lies and specifies that the current position report was received now.
Definition: smoothMover.I:276
void set_prediction_mode(PredictionMode mode)
Sets the predictioning mode of all SmoothMovers in the world.
Definition: smoothMover.I:547
void set_smooth_mode(SmoothMode mode)
Sets the smoothing mode of all SmoothMovers in the world.
Definition: smoothMover.I:524
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
void compute_and_apply_smooth_pos(NodePath &node)
A further optimization to reduce Python calls.
Definition: smoothMover.I:437
bool get_default_to_standing_still()
Returns the current state of the &#39;default to standing still&#39; flag.
Definition: smoothMover.I:747
bool set_r(PN_stdfloat r)
Sets the roll only.
Definition: smoothMover.I:187
bool set_hpr(const LVecBase3 &hpr)
Specifies the orientation of the SmoothMover at a particular time in the past.
Definition: smoothMover.I:123
void set_default_to_standing_still(bool flag)
Sets the flag that indicates whether to assume that the node stopped moving during periods when we do...
Definition: smoothMover.I:736
const LVecBase3 & get_sample_hpr() const
Returns the current orientation of the working sample point.
Definition: smoothMover.I:263
void set_reset_velocity_age(double age)
Sets the amount of time that should elapse after the last position report before the velocity is rese...
Definition: smoothMover.I:682
bool compute_smooth_position()
Computes the smoothed position (and orientation) of the mover at the indicated point in time...
Definition: smoothMover.I:348
PN_stdfloat get_smooth_lateral_velocity() const
Returns the speed at which the avatar is moving, in feet per second, along its own lateral axis (afte...
Definition: smoothMover.I:498
void set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the translation component of the transform, leaving rotation and scale untouched.
Definition: nodePath.I:783
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
const LPoint3 & get_sample_pos() const
Returns the current position of the working sample point.
Definition: smoothMover.I:249
double get_expected_broadcast_period()
Returns the interval at which we expect the SmoothNodes to broadcast their position, in elapsed seconds.
Definition: smoothMover.I:667
bool has_most_recent_timestamp() const
Returns true if we have most recently recorded timestamp.
Definition: smoothMover.I:321
double get_reset_velocity_age()
Returns the amount of time that should elapse after the last position report before the velocity is r...
Definition: smoothMover.I:694
PredictionMode get_prediction_mode()
Returns the predictioning mode of all SmoothMovers in the world.
Definition: smoothMover.I:558
SmoothMode get_smooth_mode()
Returns the smoothing mode of all SmoothMovers in the world.
Definition: smoothMover.I:535
void set_max_position_age(double age)
Sets the maximum amount of time a position is allowed to remain unchanged before assuming it represen...
Definition: smoothMover.I:629
bool set_p(PN_stdfloat p)
Sets the pitch only.
Definition: smoothMover.I:170
void set_expected_broadcast_period(double period)
Sets the interval at which we expect the SmoothNodes to broadcast their position, in elapsed seconds...
Definition: smoothMover.I:655
bool set_pos_hpr(const LVecBase3 &pos, const LVecBase3 &hpr)
Specifies the position and orientation of the SmoothMover at a particular time in the past...
Definition: smoothMover.I:214
void set_timestamp(double timestamp)
Specifies the time that the current position report applies.
Definition: smoothMover.I:303
const LPoint3 & get_smooth_pos() const
Returns the smoothed position as computed by a previous call to compute_smooth_position().
Definition: smoothMover.I:359
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
Definition: clockObject.I:48
void apply_smooth_hpr(NodePath &node) const
Applies the smoothed orientation to the indicated NodePath.
Definition: smoothMover.I:425
bool set_pos(const LVecBase3 &pos)
Specifies the position of the SmoothMover at a particular time in the past.
Definition: smoothMover.I:32
double get_max_position_age()
Returns the maximum amount of time a position is allowed to remain unchanged before assuming it repre...
Definition: smoothMover.I:641
void apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) const
Applies the smoothed position and orientation to the indicated NodePath.
Definition: smoothMover.I:410
const LVecBase3 & get_smooth_hpr() const
Returns the smoothed orientation as computed by a previous call to compute_smooth_position().
Definition: smoothMover.I:381
double get_delay()
Returns the amount of time, in seconds, to delay the computed position of a SmoothMover.
Definition: smoothMover.I:585
void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r)
Sets the rotation component of the transform, leaving translation and scale untouched.
Definition: nodePath.I:822
bool get_directional_velocity()
Returns the current state of the &#39;directional velocity&#39; flag.
Definition: smoothMover.I:721
bool set_y(PN_stdfloat y)
Sets the Y position only.
Definition: smoothMover.I:79
PN_stdfloat get_smooth_rotational_velocity() const
Returns the speed at which the avatar is rotating in the horizontal plane (i.e.
Definition: smoothMover.I:511
bool set_x(PN_stdfloat x)
Sets the X position only.
Definition: smoothMover.I:62
void set_delay(double delay)
Sets the amount of time, in seconds, to delay the computed position of a SmoothMover.
Definition: smoothMover.I:574
bool empty() const
Returns true if the buffer is empty.
Definition: circBuffer.I:66
void set_accept_clock_skew(bool flag)
Sets the &#39;accept clock skew&#39; flag.
Definition: smoothMover.I:606
bool get_accept_clock_skew()
Returns the current state of the &#39;accept clock skew&#39; flag.
Definition: smoothMover.I:617
bool set_z(PN_stdfloat z)
Sets the Z position only.
Definition: smoothMover.I:96
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
void set_directional_velocity(bool flag)
Sets the flag that indicates whether the avatar&#39;s direction is considered in computing the velocity...
Definition: smoothMover.I:710
void compute_and_apply_smooth_hpr(NodePath &hpr_node)
A further optimization to reduce Python calls.
Definition: smoothMover.I:468
int size() const
Returns the number of items currently in the buffer.
Definition: circBuffer.I:51
const LVecBase3 & get_forward_axis() const
Returns the smoothed position as computed by a previous call to compute_smooth_position().
Definition: smoothMover.I:370
PN_stdfloat get_smooth_forward_velocity() const
Returns the speed at which the avatar is moving, in feet per second, along its own forward axis (afte...
Definition: smoothMover.I:484
void apply_smooth_pos(NodePath &node) const
Applies the smoothed position to the indicated NodePath.
Definition: smoothMover.I:395