#include <smoothMover.h>
Public Types | |
enum | SmoothMode { SM_off, SM_on } |
enum | PredictionMode { PM_off, PM_on } |
Public Member Functions | |
SmoothMover () | |
~SmoothMover () | |
bool | set_scale (const LVecBase3f &scale) |
Specifies the current scale that should be applied to the transform. | |
bool | set_scale (float sx, float sy, float sz) |
Specifies the current scale that should be applied to the transform. | |
bool | set_sx (float sx) |
Sets the X-axis scale only. | |
bool | set_sy (float sy) |
Sets the Y-axis scale only. | |
bool | set_sz (float sz) |
Sets the Z-axis scale only. | |
bool | set_pos (const LVecBase3f &pos) |
Specifies the position of the SmoothMover at a particular time in the past. | |
bool | set_pos (float x, float y, float z) |
Specifies the position of the SmoothMover at a particular time in the past. | |
bool | set_x (float x) |
Sets the X position only. | |
bool | set_y (float y) |
Sets the Y position only. | |
bool | set_z (float z) |
Sets the Z position only. | |
bool | set_hpr (const LVecBase3f &hpr) |
Specifies the orientation of the SmoothMover at a particular time in the past. | |
bool | set_hpr (float h, float p, float r) |
Specifies the orientation of the SmoothMover at a particular time in the past. | |
bool | set_h (float h) |
Sets the heading only. | |
bool | set_p (float p) |
Sets the pitch only. | |
bool | set_r (float r) |
Sets the roll only. | |
bool | set_mat (const LMatrix4f &mat) |
Specifies the scale, hpr, and pos for the SmoothMover at some particular point, based on the matrix. | |
void | set_phony_timestamp () |
Lies and specifies that the current position report was received now. | |
void | set_timestamp (double timestamp) |
Specifies the time that the current position report applies. | |
void | mark_position () |
Stores the position, orientation, and timestamp (if relevant) indicated by previous calls to set_pos(), set_hpr(), and set_timestamp() in a new position report. | |
void | clear_positions (bool reset_velocity) |
Erases all the old position reports. | |
bool | compute_smooth_position () |
Computes the smoothed position (and orientation) of the mover at the indicated point in time, based on the previous position reports. | |
bool | compute_smooth_position (double timestamp) |
Computes the smoothed position (and orientation) of the mover at the indicated point in time, based on the previous position reports. | |
bool | get_latest_position () |
Updates the smooth_pos (and smooth_hpr, etc.) members to reflect the absolute latest position known for this avatar. | |
const LPoint3f & | get_smooth_pos () const |
Returns the smoothed position as computed by a previous call to compute_smooth_position(). | |
const LVecBase3f & | get_smooth_hpr () const |
Returns the smoothed orientation as computed by a previous call to compute_smooth_position(). | |
const LMatrix4f & | get_smooth_mat () |
Returns the complete smoothed transformation matrix as computed by a previous call to compute_smooth_position(). | |
float | get_smooth_forward_velocity () const |
Returns the speed at which the avatar is moving, in feet per second, along its own forward axis (after applying the avatar's hpr). | |
float | get_smooth_rotational_velocity () const |
Returns the speed at which the avatar is rotating in the horizontal plane (i.e. | |
void | output (ostream &out) const |
void | write (ostream &out) const |
Static Public Member Functions | |
void | set_smooth_mode (SmoothMode mode) |
Sets the smoothing mode of all SmoothMovers in the world. | |
SmoothMode | get_smooth_mode () |
Returns the smoothing mode of all SmoothMovers in the world. | |
void | set_prediction_mode (PredictionMode mode) |
Sets the predictioning mode of all SmoothMovers in the world. | |
PredictionMode | get_prediction_mode () |
Returns the predictioning mode of all SmoothMovers in the world. | |
void | set_delay (double delay) |
Sets the amount of time, in seconds, to delay the computed position of a SmoothMover. | |
double | get_delay () |
Returns the amount of time, in seconds, to delay the computed position of a SmoothMover. | |
void | set_accept_clock_skew (bool flag) |
Sets the 'accept clock skew' flag. | |
bool | get_accept_clock_skew () |
Returns the current state of the 'accept clock skew' flag. | |
void | set_max_position_age (double age) |
Sets the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still. | |
double | get_max_position_age () |
Returns the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still. | |
void | set_reset_velocity_age (double age) |
Sets the amount of time that should elapse after the last position report before the velocity is reset to 0. | |
double | get_reset_velocity_age () |
Returns the amount of time that should elapse after the last position report before the velocity is reset to 0. | |
Private Types | |
typedef CircBuffer< SamplePoint, max_position_reports > | Points |
typedef CircBuffer< int, max_timestamp_delays > | TimestampDelays |
Private Member Functions | |
void | set_smooth_pos (const LPoint3f &pos, const LVecBase3f &hpr, double timestamp) |
Sets the computed smooth position and orientation for the indicated timestamp. | |
void | compose_smooth_mat () |
Computes the smooth_mat based on smooth_pos and smooth_hpr. | |
void | linear_interpolate (int point_before, int point_after, double timestamp) |
Interpolates the smooth position linearly between the two bracketing position reports. | |
void | compute_velocity (const LVector3f &pos_delta, const LVecBase3f &hpr_delta, double age) |
Computes the forward and rotational velocities of the moving object. | |
void | record_timestamp_delay (double timestamp) |
Records the delay measured in receiving this particular timestamp. | |
double | get_avg_timestamp_delay () const |
Returns the average delay observed in the last n timestamps received from this client, in seconds. | |
Private Attributes | |
LVecBase3f | _scale |
SamplePoint | _sample |
LPoint3f | _smooth_pos |
LVecBase3f | _smooth_hpr |
LMatrix4f | _smooth_mat |
double | _smooth_timestamp |
bool | _smooth_position_known |
bool | _smooth_position_changed |
bool | _computed_smooth_mat |
double | _smooth_forward_velocity |
double | _smooth_rotational_velocity |
Points | _points |
int | _last_point_before |
int | _last_point_after |
TimestampDelays | _timestamp_delays |
int | _net_timestamp_delay |
double | _last_heard_from |
Static Private Attributes | |
SmoothMode | _smooth_mode = SmoothMover::SM_off |
PredictionMode | _prediction_mode = SmoothMover::PM_off |
double | _delay = 0.2 |
bool | _accept_clock_skew = true |
double | _max_position_age = 0.25 |
double | _reset_velocity_age = 0.3 |
for smoothing the apparent movement of remote avatars, whose positions are sent via occasional telemetry updates.
It can operate in any of three modes: off, in which it does not smooth any motion but provides the last position it was told; smoothing only, in which it smooths motion information but never tries to anticipate where the avatar might be going; or full prediction, in which it smooths motion as well as tries to predict the avatar's position in lead of the last position update. The assumption is that all SmoothMovers in the world will be operating in the same mode together.
Definition at line 68 of file smoothMover.h.
|
Definition at line 189 of file smoothMover.h. |
|
Definition at line 199 of file smoothMover.h. |
|
Definition at line 127 of file smoothMover.h. |
|
Definition at line 121 of file smoothMover.h. |
|
Definition at line 42 of file smoothMover.cxx. References _computed_smooth_mat, _last_heard_from, _last_point_after, _last_point_before, _net_timestamp_delay, _smooth_forward_velocity, _smooth_hpr, _smooth_mat, _smooth_pos, _smooth_position_changed, _smooth_position_known, _smooth_rotational_velocity, _smooth_timestamp, and _timestamp_delays. |
|
Definition at line 79 of file smoothMover.cxx. References decompose_matrix(), set_hpr(), set_pos(), and set_scale(). |
|
Erases all the old position reports. This should be done, for instance, prior to teleporting the avatar to a new position; otherwise, the smoother might try to lerp the avatar there. If reset_velocity is true, the velocity is also reset to 0. Definition at line 188 of file smoothMover.cxx. References _points, _reset_velocity_age, _smooth_forward_velocity, _smooth_position_changed, _smooth_rotational_velocity, and _smooth_timestamp. |
|
Computes the smooth_mat based on smooth_pos and smooth_hpr.
Definition at line 482 of file smoothMover.cxx. References _smooth_forward_velocity, _smooth_hpr, _smooth_rotational_velocity, and compose_matrix(). Referenced by set_p(). |
|
Computes the smoothed position (and orientation) of the mover at the indicated point in time, based on the previous position reports. After this call has been made, get_smooth_pos() etc. may be called to retrieve the smoothed position. The return value is true if the value has changed (or might have changed) since the last call to compute_smooth_position(), or false if it remains the same. Definition at line 229 of file smoothMover.cxx. References _points. |
|
Computes the smoothed position (and orientation) of the mover at the indicated point in time, based on the previous position reports. After this call has been made, get_smooth_pos() etc. may be called to retrieve the smoothed position. With no parameter, the function uses ClockObject::get_frame_time() as the default time. Definition at line 396 of file smoothMover.I. |
|
Computes the forward and rotational velocities of the moving object.
Definition at line 559 of file smoothMover.cxx. Referenced by set_mat(). |
|
Returns the current state of the 'accept clock skew' flag. Definition at line 642 of file smoothMover.I. |
|
Returns the average delay observed in the last n timestamps received from this client, in seconds. This number represents the combination of the network lag from this client, as well as the client's clock skew relative to our clock. It could be negative if the client's clock is running faster than our clock. Definition at line 739 of file smoothMover.I. |
|
Returns the amount of time, in seconds, to delay the computed position of a SmoothMover. See set_delay(). Definition at line 592 of file smoothMover.I. |
|
Updates the smooth_pos (and smooth_hpr, etc.) members to reflect the absolute latest position known for this avatar. This may result in a pop to the most recent position. Returns true if the latest position is known, false otherwise. Definition at line 405 of file smoothMover.cxx. References _computed_smooth_mat, _smooth_position_changed, and _smooth_position_known. |
|
Returns the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.
Definition at line 676 of file smoothMover.I. |
|
Returns the predictioning mode of all SmoothMovers in the world. Definition at line 552 of file smoothMover.I. |
|
Returns the amount of time that should elapse after the last position report before the velocity is reset to 0. Definition at line 716 of file smoothMover.I. |
|
Returns the speed at which the avatar is moving, in feet per second, along its own forward axis (after applying the avatar's hpr). This will be a positive number if the avatar is moving forward, and a negative number if it is moving backward. Definition at line 467 of file smoothMover.I. References _max_position_age, and INLINE. |
|
Returns the smoothed orientation as computed by a previous call to compute_smooth_position().
Definition at line 426 of file smoothMover.I. References _accept_clock_skew, and INLINE. |
|
Returns the complete smoothed transformation matrix as computed by a previous call to compute_smooth_position().
Definition at line 443 of file smoothMover.I. References _accept_clock_skew, and INLINE. |
|
Returns the smoothing mode of all SmoothMovers in the world. See set_smooth_mode(). Definition at line 520 of file smoothMover.I. |
|
Returns the smoothed position as computed by a previous call to compute_smooth_position().
Definition at line 411 of file smoothMover.I. |
|
Returns the speed at which the avatar is rotating in the horizontal plane (i.e. heading), in degrees per second. This may be positive or negative, according to the direction of rotation. Definition at line 486 of file smoothMover.I. References _reset_velocity_age, and INLINE. |
|
Interpolates the smooth position linearly between the two bracketing position reports.
Definition at line 498 of file smoothMover.cxx. |
|
Stores the position, orientation, and timestamp (if relevant) indicated by previous calls to set_pos(), set_hpr(), and set_timestamp() in a new position report. When compute_smooth_position() is called, it uses these stored position reports to base its computation of the known position. Definition at line 126 of file smoothMover.cxx. References _sample. |
|
Definition at line 427 of file smoothMover.cxx. References _last_point_after, _last_point_before, _points, SmoothMover::SamplePoint::_timestamp, and t. |
|
Records the delay measured in receiving this particular timestamp. The average delay of the last n timestamps will be used to smooth the motion properly. Definition at line 588 of file smoothMover.cxx. Referenced by set_hpr(). |
|
Sets the 'accept clock skew' flag. When this flag is true, clock skew from the other clients will be tolerated by delaying each smooth mover's position an additional amount, on top of that specified by set_delay(), based on the measured average latency for timestamp messages received by the client. In this way, if the other client has significant clock skew with respect to our clock, it will be evident as a large positive or negative average latency for timestamps. By subtracting out this average latency, we compensate for poor clock sync. Definition at line 627 of file smoothMover.I. |
|
Sets the amount of time, in seconds, to delay the computed position of a SmoothMover. This is particularly useful when the prediction mode is off, because it can allow the apparent motion of an avatar to appear smooth without relying on prediction, at the cost of introducing additional lag in the avatar's apparent position. Definition at line 577 of file smoothMover.I. |
|
Sets the heading only. See set_hpr(). Definition at line 299 of file smoothMover.I. References _smooth_hpr, and INLINE. |
|
Specifies the orientation of the SmoothMover at a particular time in the past. When mark_position() is called, this will be recorded (along with hpr and timestamp) in a position report, which will then be used along with all other position reports to determine the smooth position at any particular instant. The return value is true if any parameter has changed since the last call to set_hpr(), or false if they are the same. Definition at line 286 of file smoothMover.I. References _smooth_pos, and INLINE. |
|
Specifies the orientation of the SmoothMover at a particular time in the past. When mark_position() is called, this will be recorded (along with hpr and timestamp) in a position report, which will then be used along with all other position reports to determine the smooth position at any particular instant. The return value is true if any parameter has changed since the last call to set_hpr(), or false if they are the same. Definition at line 253 of file smoothMover.I. References _sample, SmoothMover::SamplePoint::_timestamp, INLINE, and record_timestamp_delay(). Referenced by ~SmoothMover(). |
|
Specifies the scale, hpr, and pos for the SmoothMover at some particular point, based on the matrix.
Definition at line 93 of file smoothMover.cxx. References SmoothMover::SamplePoint::_hpr, _max_position_age, SmoothMover::SamplePoint::_pos, _sample, _smooth_hpr, _smooth_mode, _smooth_pos, _smooth_timestamp, compute_velocity(), ClockObject::get_frame_time(), ClockObject::get_global_clock(), set_smooth_pos(), and SM_off. |
|
Sets the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.
Definition at line 659 of file smoothMover.I. |
|
Sets the pitch only. See set_hpr(). Definition at line 314 of file smoothMover.I. References _computed_smooth_mat, and compose_smooth_mat(). |
|
Lies and specifies that the current position report was received now. This is usually used for very old position reports for which we're not sure of the actual receipt time. Definition at line 350 of file smoothMover.I. References _smooth_mode, and INLINE. |
|
Specifies the position of the SmoothMover at a particular time in the past. When mark_position() is called, this will be recorded (along with hpr and timestamp) in a position report, which will then be used along with all other position reports to determine the smooth position at any particular instant. The return value is true if any parameter has changed since the last call to set_pos(), or false if they are the same. Definition at line 175 of file smoothMover.I. |
|
Specifies the position of the SmoothMover at a particular time in the past. When mark_position() is called, this will be recorded (along with hpr and timestamp) in a position report, which will then be used along with all other position reports to determine the smooth position at any particular instant. The return value is true if any parameter has changed since the last call to set_pos(), or false if they are the same. Definition at line 142 of file smoothMover.I. References SmoothMover::SamplePoint::_pos, _sample, INLINE, and y. Referenced by ~SmoothMover(). |
|
Sets the predictioning mode of all SmoothMovers in the world. If this is PM_off, no prediction will be performed, but smoothing might still be performed. Definition at line 537 of file smoothMover.I. |
|
Sets the roll only. See set_hpr(). Definition at line 329 of file smoothMover.I. References _smooth_forward_velocity, and INLINE. |
|
Sets the amount of time that should elapse after the last position report before the velocity is reset to 0. This is similar to max_position_age, but it is only used to determine the resetting of the reported velocity. It should always be greater than or equal to max_position_age. Definition at line 699 of file smoothMover.I. |
|
Specifies the current scale that should be applied to the transform. This is not smoothed along with pos and hpr, but rather takes effect immediately; it is only here at all so we can return a complete matrix in get_smooth_mat(). Definition at line 61 of file smoothMover.I. References _computed_smooth_mat, _scale, and INLINE. |
|
Specifies the current scale that should be applied to the transform. This is not smoothed along with pos and hpr, but rather takes effect immediately; it is only here at all so we can return a complete matrix in get_smooth_mat(). Definition at line 40 of file smoothMover.I. References INLINE, set_sx(), set_sy(), and set_sz(). Referenced by ~SmoothMover(). |
|
Sets the smoothing mode of all SmoothMovers in the world. If this is SM_off, no smoothing or prediction will be performed, and get_smooth_pos() will simply return the position last set by mark_position(). Definition at line 505 of file smoothMover.I. References _net_timestamp_delay, _timestamp_delays, CircBuffer< int, max_timestamp_delays >::empty(), INLINE, nassertr, and CircBuffer< int, max_timestamp_delays >::size(). |
|
Sets the computed smooth position and orientation for the indicated timestamp.
Definition at line 461 of file smoothMover.cxx. References SmoothMover::SamplePoint::_hpr. Referenced by set_mat(). |
|
Sets the X-axis scale only. See set_scale(). Definition at line 74 of file smoothMover.I. References _computed_smooth_mat, _scale, and INLINE. Referenced by set_scale(). |
|
Sets the Y-axis scale only. See set_scale(). Definition at line 90 of file smoothMover.I. References INLINE, set_x(), set_y(), and set_z(). Referenced by set_scale(). |
|
Sets the Z-axis scale only. See set_scale(). Definition at line 106 of file smoothMover.I. References INLINE, set_x(), set_y(), set_z(), x, and y. Referenced by set_scale(). |
|
Specifies the time that the current position report applies. This should be called, along with set_pos() and set_hpr(), before a call to mark_position(). Definition at line 368 of file smoothMover.I. References _smooth_mode. |
|
Sets the X position only. See set_pos(). Definition at line 188 of file smoothMover.I. |
|
Sets the Y position only. See set_pos(). Definition at line 203 of file smoothMover.I. References SmoothMover::SamplePoint::_hpr, _sample, and INLINE. |
|
Sets the Z position only. See set_pos(). Definition at line 218 of file smoothMover.I. References SmoothMover::SamplePoint::_hpr, _sample, and INLINE. |
|
Definition at line 440 of file smoothMover.cxx. |
|
Definition at line 29 of file smoothMover.cxx. Referenced by get_smooth_hpr(), and get_smooth_mat(). |
|
Definition at line 184 of file smoothMover.h. Referenced by get_latest_position(), set_p(), set_scale(), set_sx(), and SmoothMover(). |
|
Definition at line 28 of file smoothMover.cxx. Referenced by compute_smooth_position(), and get_smooth_pos(). |
|
Definition at line 202 of file smoothMover.h. Referenced by SmoothMover(). |
|
Definition at line 192 of file smoothMover.h. Referenced by output(), and SmoothMover(). |
|
Definition at line 191 of file smoothMover.h. Referenced by output(), and SmoothMover(). |
|
Definition at line 30 of file smoothMover.cxx. Referenced by get_smooth_forward_velocity(), and set_mat(). |
|
Definition at line 201 of file smoothMover.h. Referenced by set_smooth_mode(), and SmoothMover(). |
|
Definition at line 190 of file smoothMover.h. Referenced by clear_positions(), compute_smooth_position(), and output(). |
|
Definition at line 27 of file smoothMover.cxx. |
|
Definition at line 31 of file smoothMover.cxx. Referenced by clear_positions(), and get_smooth_rotational_velocity(). |
|
Definition at line 176 of file smoothMover.h. Referenced by mark_position(), set_hpr(), set_mat(), set_pos(), set_y(), and set_z(). |
|
Definition at line 168 of file smoothMover.h. Referenced by set_scale(), and set_sx(). |
|
Definition at line 186 of file smoothMover.h. Referenced by clear_positions(), compose_smooth_mat(), set_r(), and SmoothMover(). |
|
Definition at line 179 of file smoothMover.h. Referenced by compose_smooth_mat(), set_h(), set_mat(), and SmoothMover(). |
|
Definition at line 180 of file smoothMover.h. Referenced by SmoothMover(). |
|
Definition at line 26 of file smoothMover.cxx. Referenced by set_mat(), set_phony_timestamp(), and set_timestamp(). |
|
Definition at line 178 of file smoothMover.h. Referenced by set_hpr(), set_mat(), and SmoothMover(). |
|
Definition at line 183 of file smoothMover.h. Referenced by clear_positions(), get_latest_position(), and SmoothMover(). |
|
Definition at line 182 of file smoothMover.h. Referenced by get_latest_position(), and SmoothMover(). |
|
Definition at line 187 of file smoothMover.h. Referenced by clear_positions(), compose_smooth_mat(), and SmoothMover(). |
|
Definition at line 181 of file smoothMover.h. Referenced by clear_positions(), set_mat(), and SmoothMover(). |
|
Definition at line 200 of file smoothMover.h. Referenced by set_smooth_mode(), and SmoothMover(). |