panda3d.direct.SmoothMover

from panda3d.direct import SmoothMover
class SmoothMover

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 diagram

Inheritance diagram of SmoothMover

enum PredictionMode
enumerator PM_off = 0
enumerator PM_on = 1
enum SmoothMode
enumerator SM_off = 0
enumerator SM_on = 1
__init__() → None
__init__(param0: SmoothMover) → None
applySmoothHpr(node: NodePath) → None

Applies the smoothed orientation to the indicated NodePath. This is equivalent to calling node.set_hpr(smooth_mover->:meth:~SmoothMover.getSmoothHpr). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

applySmoothPos(node: NodePath) → None

Applies the smoothed position to the indicated NodePath. This is equivalent to calling node.set_pos(smooth_mover->:meth:~SmoothMover.getSmoothPos). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

applySmoothPosHpr(pos_node: NodePath, hpr_node: NodePath) → None

Applies the smoothed position and orientation to the indicated NodePath. This is equivalent to calling node.set_pos_hpr(smooth_mover->:meth:~SmoothMover.getSmoothPos, smooth_mover->:meth:~SmoothMover.getSmoothHpr). It exists as an optimization only, to avoid the overhead of passing the return value through Python.

clearPositions(reset_velocity: bool) → None

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.

computeAndApplySmoothHpr(hpr_node: NodePath) → None

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.

computeAndApplySmoothPos(node: NodePath) → None

A further optimization to reduce Python calls. This computes the smooth position and applies it to the indicated node in one call.

computeAndApplySmoothPosHpr(pos_node: NodePath, hpr_node: NodePath) → None

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

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, getSmoothPos() etc. may be called to retrieve the smoothed position.

With no parameter, the function uses ClockObject::get_frame_time() as the default time.

computeSmoothPosition(timestamp: float) → bool

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, getSmoothPos() 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 computeSmoothPosition(), or false if it remains the same.

getAcceptClockSkew() → bool

Returns the current state of the ‘accept clock skew’ flag. See setAcceptClockSkew().

getDefaultToStandingStill() → bool

Returns the current state of the ‘default to standing still’ flag. See setDefaultToStandingStill().

getDelay() → float

Returns the amount of time, in seconds, to delay the computed position of a SmoothMover. See setDelay().

getDirectionalVelocity() → bool

Returns the current state of the ‘directional velocity’ flag. See setDirectionalVelocity().

getExpectedBroadcastPeriod() → float

Returns the interval at which we expect the SmoothNodes to broadcast their position, in elapsed seconds. See setExpectedBroadcastPeriod().

getForwardAxis() → LVecBase3

Returns the smoothed position as computed by a previous call to computeSmoothPosition().

Return type

LVecBase3

getLatestPosition() → bool

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() → float

Returns the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.

getMostRecentTimestamp() → float

Returns most recently recorded timestamp

getPredictionMode() → PredictionMode

Returns the predictioning mode of all SmoothMovers in the world. See setPredictionMode().

Return type

PredictionMode

getResetVelocityAge() → float

Returns the amount of time that should elapse after the last position report before the velocity is reset to 0. See setResetVelocityAge().

getSampleHpr() → LVecBase3

Returns the current orientation of the working sample point. This orientation is updated periodically by setH(), setP(), etc., and its current value is copied to the sample point table when markPosition() is called.

Return type

LVecBase3

getSamplePos() → LPoint3

Returns the current position of the working sample point. This position is updated periodically by setX(), setY(), etc., and its current value is copied to the sample point table when markPosition() is called.

Return type

LPoint3

getSmoothForwardVelocity() → float

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() → LVecBase3

Returns the smoothed orientation as computed by a previous call to computeSmoothPosition().

Return type

LVecBase3

getSmoothLateralVelocity() → float

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.

getSmoothMode() → SmoothMode

Returns the smoothing mode of all SmoothMovers in the world. See setSmoothMode().

Return type

SmoothMode

getSmoothPos() → LPoint3

Returns the smoothed position as computed by a previous call to computeSmoothPosition().

Return type

LPoint3

getSmoothRotationalVelocity() → float

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(old_parent: NodePath, new_parent: NodePath) → None

Node is being wrtReparented, update recorded sample positions to reflect new parent

hasMostRecentTimestamp() → bool

Returns true if we have most recently recorded timestamp

markPosition() → None

Stores the position, orientation, and timestamp (if relevant) indicated by previous calls to setPos(), setHpr(), and setTimestamp() in a new position report.

When computeSmoothPosition() is called, it uses these stored position reports to base its computation of the known position.

output(out: ostream) → None
setAcceptClockSkew(flag: bool) → None

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 setDelay(), 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(flag: bool) → None

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(delay: float) → None

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(flag: bool) → None

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(period: float) → None

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(h: float) → bool

Sets the heading only. See setHpr().

setHpr(hpr: LVecBase3) → bool

Specifies the orientation of the SmoothMover at a particular time in the past. When markPosition() 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 setHpr(), or false if they are the same.

setHpr(h: float, p: float, r: float) → bool

Specifies the orientation of the SmoothMover at a particular time in the past. When markPosition() 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 setHpr(), or false if they are the same.

setMaxPositionAge(age: float) → None

Sets the maximum amount of time a position is allowed to remain unchanged before assuming it represents the avatar actually standing still.

setP(p: float) → bool

Sets the pitch only. See setHpr().

setPhonyTimestamp(timestamp: float, period_adjust: bool) → None

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(pos: LVecBase3) → bool

Specifies the position of the SmoothMover at a particular time in the past. When markPosition() 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 setPos(), or false if they are the same.

setPos(x: float, y: float, z: float) → bool

Specifies the position of the SmoothMover at a particular time in the past. When markPosition() 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 setPos(), or false if they are the same.

setPosHpr(pos: LVecBase3, hpr: LVecBase3) → bool

Specifies the position and orientation of the SmoothMover at a particular time in the past. When markPosition() is called, this will be recorded (along with 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 setPosHpr(), or false if they are the same.

setPosHpr(x: float, y: float, z: float, h: float, p: float, r: float) → bool

Specifies the position of the SmoothMover at a particular time in the past. When markPosition() is called, this will be recorded (along with 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 setPosHpr(), or false if they are the same.

setPredictionMode(mode: PredictionMode) → None

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(r: float) → bool

Sets the roll only. See setHpr().

setResetVelocityAge(age: float) → None

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.

setSmoothMode(mode: SmoothMode) → None

Sets the smoothing mode of all SmoothMovers in the world. If this is SM_off, no smoothing or prediction will be performed, and getSmoothPos() will simply return the position last set by markPosition().

setTimestamp(timestamp: float) → None

Specifies the time that the current position report applies. This should be called, along with setPos() and setHpr(), before a call to markPosition().

setX(x: float) → bool

Sets the X position only. See setPos().

setY(y: float) → bool

Sets the Y position only. See setPos().

setZ(z: float) → bool

Sets the Z position only. See setPos().

write(out: ostream) → None