# SmoothMover

from pandac.PandaModules import SmoothMover

Class : SmoothMover
Description : This class handles smoothing of sampled motion points over time, e.g. 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.

## Inheritance:

SmoothMover:

## Methods of SmoothMover:

applySmoothHpr
applySmoothMat
applySmoothPos
clearPositions
computeAndApplySmoothMat
computeAndApplySmoothPos
computeAndApplySmoothPosHpr
computeSmoothPosition
getAcceptClockSkew
getDefaultToStandingStill
getDelay
getDirectionalVelocity
getExpectedBroadcastPeriod
getForwardAxis
getLatestPosition
getMaxPositionAge
getPredictionMode
getResetVelocityAge
getSampleHpr
getSamplePos
getSmoothForwardVelocity
getSmoothHpr
getSmoothLateralVelocity
getSmoothMat
getSmoothMode
getSmoothPos
getSmoothRotationalVelocity
handleWrtReparent
markPosition
output
setAcceptClockSkew
setDefaultToStandingStill
setDelay
setDirectionalVelocity
setExpectedBroadcastPeriod
setH
setHpr
setMat
setMaxPositionAge
setP
setPhonyTimestamp
setPos
setPredictionMode
setR
setResetVelocityAge
setScale
setSmoothMode
setSx
setSy
setSz
setTimestamp
setX
setY
setZ
write

## Constants in SmoothMover:

SMOff | (SmoothMode)
SMOn | (SmoothMode)
PMOff | (PredictionMode)
PMOn | (PredictionMode)

applySmoothHpr void SmoothMover::apply_smooth_hpr(NodePath &node) const; Description: Applies the smoothed orientation to the indicated NodePath. This is equivalent to calling node.set_hpr(smooth_mover->get_smooth_hpr()). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

applySmoothMat void SmoothMover::apply_smooth_mat(NodePath &node); Description: Applies the smoothed transform to the indicated NodePath. This is equivalent to calling node.set_mat(smooth_mover->get_smooth_mat()). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

applySmoothPos void SmoothMover::apply_smooth_pos(NodePath &node) const; Description: Applies the smoothed position to the indicated NodePath. This is equivalent to calling node.set_pos(smooth_mover->get_smooth_pos()). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

clearPositions void SmoothMover::clear_positions(bool reset_velocity); Description: 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.

computeAndApplySmoothMat void SmoothMover::compute_and_apply_smooth_mat(NodePath &node); Description: A further optimization to reduce Python calls. This computes the smooth position and applies it to the indicated node in one call.

computeAndApplySmoothPos void SmoothMover::compute_and_apply_smooth_pos(NodePath &node); Description: A further optimization to reduce Python calls. This computes the smooth position and applies it to the indicated node in one call.

computeAndApplySmoothPosHpr void SmoothMover::compute_and_apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node); Description: A further optimization to reduce Python calls. This computes the smooth position and applies it to the indicated node or nodes in one call. The pos_node and hpr_node might be the same NodePath.

computeSmoothPosition bool SmoothMover::compute_smooth_position(void); Description: 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. 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.

getAcceptClockSkew bool SmoothMover::get_accept_clock_skew(void); Description: Returns the current state of the 'accept clock skew' flag. See set_accept_clock_skew().

getDefaultToStandingStill bool SmoothMover::get_default_to_standing_still(void); Description: Returns the current state of the 'default to standing still' flag. See set_default_to_standing_still().

getDelay double SmoothMover::get_delay(void); Description: Returns the amount of time, in seconds, to delay the computed position of a SmoothMover. See set_delay().

getDirectionalVelocity bool SmoothMover::get_directional_velocity(void); Description: Returns the current state of the 'directional velocity' flag. See set_directional_velocity().

getExpectedBroadcastPeriod double SmoothMover::get_expected_broadcast_period(void); Description: Returns the interval at which we expect the SmoothNodes to broadcast their position, in elapsed seconds. See set_expected_broadcast_period().

getForwardAxis LVecBase3f const &SmoothMover::get_forward_axis(void) const; Description: Returns the smoothed position as computed by a previous call to compute_smooth_position().

getLatestPosition bool SmoothMover::get_latest_position(void); Description: 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.

getMaxPositionAge double SmoothMover::get_max_position_age(void); Description: Returns the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.

getPredictionMode SmoothMover::PredictionMode SmoothMover::get_prediction_mode(void); Description: Returns the predictioning mode of all SmoothMovers in the world. See set_prediction_mode().

getResetVelocityAge double SmoothMover::get_reset_velocity_age(void); Description: Returns the amount of time that should elapse after the last position report before the velocity is reset to 0. See set_reset_velocity_age().

getSampleHpr LVecBase3f const &SmoothMover::get_sample_hpr(void) const; Description: Returns the current orientation of the working sample point. This orientation is updated periodically by set_h(), set_p(), etc., and its current value is copied to the sample point table when mark_position() is called.

getSamplePos LPoint3f const &SmoothMover::get_sample_pos(void) const; Description: Returns the current position of the working sample point. This position is updated periodically by set_x(), set_y(), etc., and its current value is copied to the sample point table when mark_position() is called.

getSmoothForwardVelocity float SmoothMover::get_smooth_forward_velocity(void) const; Description: 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.

getSmoothHpr LVecBase3f const &SmoothMover::get_smooth_hpr(void) const; Description: Returns the smoothed orientation as computed by a previous call to compute_smooth_position().

getSmoothLateralVelocity float SmoothMover::get_smooth_lateral_velocity(void) const; Description: Returns the speed at which the avatar is moving, in feet per second, along its own lateral axis (after applying the avatar's hpr). This will be a positive number if the avatar is moving right, and a negative number if it is moving left.

getSmoothMat LMatrix4f const &SmoothMover::get_smooth_mat(void); Description: Returns the complete smoothed transformation matrix as computed by a previous call to compute_smooth_position().

getSmoothMode SmoothMover::SmoothMode SmoothMover::get_smooth_mode(void); Description: Returns the smoothing mode of all SmoothMovers in the world. See set_smooth_mode().

getSmoothPos LPoint3f const &SmoothMover::get_smooth_pos(void) const; Description: Returns the smoothed position as computed by a previous call to compute_smooth_position().

getSmoothRotationalVelocity float SmoothMover::get_smooth_rotational_velocity(void) const; Description: 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.

handleWrtReparent void SmoothMover::handle_wrt_reparent(NodePath &old_parent, NodePath &new_parent); Description: Node is being wrtReparented, update recorded sample positions to reflect new parent

markPosition void SmoothMover::mark_position(void); Description: 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.

output void SmoothMover::output(ostream &out) const; Description:

setAcceptClockSkew void SmoothMover::set_accept_clock_skew(bool flag); Description: 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.

setDefaultToStandingStill void SmoothMover::set_default_to_standing_still(bool flag); Description: Sets the flag that indicates whether to assume that the node stopped moving during periods when we don't get enough position updates. If true, the object will stand still momentarily. If false, the object will continuously lerp between the position updates that we did get.

setDelay void SmoothMover::set_delay(double delay); Description: 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.

setDirectionalVelocity void SmoothMover::set_directional_velocity(bool flag); Description: Sets the flag that indicates whether the avatar's direction is considered in computing the velocity. When this is true, velocity is automatically decomposed into a forward and a lateral velocity (and both may be positive or negative); when it is false, all velocity is always returned as forward velocity (and it is always positive).

setExpectedBroadcastPeriod void SmoothMover::set_expected_broadcast_period(double period); Description: Sets the interval at which we expect the SmoothNodes to broadcast their position, in elapsed seconds. This controls the length of time we assume the object has truly stopped, when we receive a long sequence of no updates.

setH bool SmoothMover::set_h(float h); Description: Sets the heading only. See set_hpr().

setHpr bool SmoothMover::set_hpr(LVecBase3f const &hpr); Description: 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.

setMat bool SmoothMover::set_mat(LMatrix4f const &mat); Description: Specifies the scale, hpr, and pos for the SmoothMover at some particular point, based on the matrix.

setMaxPositionAge void SmoothMover::set_max_position_age(double age); Description: Sets the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.

setP bool SmoothMover::set_p(float p); Description: Sets the pitch only. See set_hpr().

setPhonyTimestamp void SmoothMover::set_phony_timestamp(void); Description: 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.

setPos bool SmoothMover::set_pos(LVecBase3f const &pos); These methods are used to specify each position update. Call the appropriate set_* function(s), as needed, and then call mark_position(). The return value of each function is true if the parameter value has changed, or false if it remains the same as last time. Description: 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.

setPredictionMode void SmoothMover::set_prediction_mode(SmoothMover::PredictionMode mode); Description: 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.

setR bool SmoothMover::set_r(float r); Description: Sets the roll only. See set_hpr().

setResetVelocityAge void SmoothMover::set_reset_velocity_age(double age); Description: 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.

setScale bool SmoothMover::set_scale(LVecBase3f const &scale); This method is just used to specify a scale which is only used when composing the matrix for return by get_smooth_mat(). It might change from time to time, but it is not smoothed. Filename: smoothMover.I Created by: drose (19Oct01) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . Description: 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().

setSmoothMode void SmoothMover::set_smooth_mode(SmoothMover::SmoothMode mode); Description: 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().

setSx bool SmoothMover::set_sx(float sx); Description: Sets the X-axis scale only. See set_scale().

setSy bool SmoothMover::set_sy(float sy); Description: Sets the Y-axis scale only. See set_scale().

setSz bool SmoothMover::set_sz(float sz); Description: Sets the Z-axis scale only. See set_scale().

setTimestamp void SmoothMover::set_timestamp(double timestamp); Description: 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().

setX bool SmoothMover::set_x(float x); Description: Sets the X position only. See set_pos().

setY bool SmoothMover::set_y(float y); Description: Sets the Y position only. See set_pos().

setZ bool SmoothMover::set_z(float z); Description: Sets the Z position only. See set_pos().

write void SmoothMover::write(ostream &out) const; Description: