net-math overview
Table of contents
- utils
- NetRot (type alias)
- NetVec (type alias)
- avClone
- avLerp
- extrapolationSeconds
- gainFactor
- integrateRotation
- isCoasting
- rClone
- rotationError
- rotationLerp
- vAdd
- vClone
- vLen
- vLerp
- vScale
- vSub
- vZero
utils
NetRot (type alias)
Signature
export type NetRot = number | Point4
NetVec (type alias)
Dimension-agnostic vector/rotation helpers the correction helpers share. A 2D world's positions
are Point2 and rotations plain angles; a 3D world's are Point3 and quaternions - every function
here tells them apart at runtime (z present / rotation is a number) and dispatches to
Pnt2/Pnt3/Qtrn, so one algorithm serves both. Internal to the network helpers, not
re-exported from the package root.
Signature
export type NetVec = Point2 | Point3
avClone
Plain-JSON copy of an angular velocity: a scalar in 2D, a world-space axis*rate vector in 3D.
Signature
export declare function avClone(av: number | Point3): number | Point3
avLerp
Interpolate angular velocity (scalar in 2D, vector in 3D).
Signature
export declare function avLerp(a: number | Point3, b: number | Point3, t: number): number | Point3
extrapolationSeconds
how far (seconds) a snapshot ageMs old is extrapolated: its age, capped at extrapolateMaxMs
Signature
export declare function extrapolationSeconds(ageMs: number, tuning: CorrectionTuning): number
gainFactor
Per-tick blend factor for a per-second gain: 1 - e^(-gain * dt), so blending by it every tick
closes the same part of a gap per second at any frame rate (gain * dt overshoots the
exponential at a low frame rate and reaches 1 at dt = 1 / gain).
Signature
export declare function gainFactor(gainPerSecond: number, dtMs: number): number
integrateRotation
Advance rotation r by angular velocity av (rad/s; scalar in 2D, world-space axis*rate vector in
3D) over seconds.
Signature
export declare function integrateRotation<R extends NetRot>(r: R, av: number | Point3, seconds: number): R
isCoasting
whether a replica whose latest snapshot arrived sinceReceivedMs ago coasts: the stream has been
silent for longer than a snapshot is extrapolated, but not yet for the whole coasting window
Signature
export declare function isCoasting(sinceReceivedMs: number | undefined, tuning: CorrectionTuning): boolean
rClone
Plain-JSON copy of a rotation.
Signature
export declare function rClone<R extends NetRot>(r: R): R
rotationError
Smallest angle (radians, >= 0) between two rotations.
Signature
export declare function rotationError(a: NetRot, b: NetRot): number
rotationLerp
Interpolate rotation a toward b by t along the shortest path.
Signature
export declare function rotationLerp<R extends NetRot>(a: R, b: R, t: number): R
vAdd
Signature
export declare function vAdd<D extends NetVec>(a: D, b: D): D
vClone
Plain-JSON copy of a vector (drops any extra fields a native/adapter vector object might carry).
Signature
export declare function vClone<D extends NetVec>(a: D): D
vLen
Signature
export declare function vLen(a: NetVec): number
vLerp
Signature
export declare function vLerp<D extends NetVec>(a: D, b: D, t: number): D
vScale
Signature
export declare function vScale<D extends NetVec>(a: D, s: number): D
vSub
Signature
export declare function vSub<D extends NetVec>(a: D, b: D): D
vZero
Signature
export declare function vZero<D extends NetVec>(like: D): D