pub struct Transform {
pub position: DVec3,
pub rotation: DQuat,
}Expand description
World-space transform for a physics entity.
This is the authoritative position used by the server simulation. The renderer receives a camera-relative transform derived from this.
Fields§
§position: DVec3World-space position in metres.
rotation: DQuatWorld-space orientation (unit quaternion).
Implementations§
Source§impl Transform
impl Transform
Sourcepub const ENCODED_LEN: usize
pub const ENCODED_LEN: usize
Byte length of the replication encoding written by Self::encode.
The encoding is position (3 × f64 LE) followed by rotation quaternion (4 × f64 LE, x/y/z/w) — 56 bytes.
Sourcepub const WIRE_POSITION_EXTENT: f64 = 4096.0
pub const WIRE_POSITION_EXTENT: f64 = 4096.0
Half the width of the range a replicated position axis is quantized over, in metres, centred on the sector’s origin.
Wire positions are sector-local, and today every snapshot is
crcbl_net::SectorId::ZERO with physics never rebasing, so sector-local
is world space. The range is bounded by the scenes that replicate, not
by crcbl_core::SECTOR_SIZE: a whole sector at
Self::WIRE_POSITION_BITS would be a sixteenth of a metre per step,
too coarse to watch a crate settle. A body outside it replicates
exactly (see Self::encode_wire).
Sourcepub const WIRE_POSITION_BITS: u32 = 24
pub const WIRE_POSITION_BITS: u32 = 24
Bits per replicated position axis.
Sourcepub const WIRE_POSITION: Fixed
pub const WIRE_POSITION: Fixed
A replicated position axis: Self::WIRE_POSITION_BITS of fixed point
over ±Self::WIRE_POSITION_EXTENT. The width is a power of two, so
the quantum is too (asserted in the tests) and a position on that grid
replicates exactly.
Sourcepub const WIRE_ROTATION_BITS: u32 = 18
pub const WIRE_ROTATION_BITS: u32 = 18
Bits per sent component of a replicated rotation. With the index bits
and the three position axes it fills Self::QUANTIZED_LEN with no
padding (asserted below the impl), so the precision costs nothing the
payload’s last byte was not already spending.
Sourcepub const WIRE_ROTATION: SmallestThree
pub const WIRE_ROTATION: SmallestThree
A replicated rotation: smallest-three at Self::WIRE_ROTATION_BITS.
Sourcepub const WIRE_SCHEMA: &'static [Field]
pub const WIRE_SCHEMA: &'static [Field]
The quantized replication schema: each position axis as
Self::WIRE_POSITION fixed point, the rotation as
Self::WIRE_ROTATION.
Sourcepub const QUANTIZED_LEN: usize
pub const QUANTIZED_LEN: usize
Byte length of the quantized form Self::encode_wire writes.
Sourcepub fn new(position: DVec3, rotation: DQuat) -> Self
pub fn new(position: DVec3, rotation: DQuat) -> Self
Create a transform at position with the given rotation.
Sourcepub fn from_position(position: DVec3) -> Self
pub fn from_position(position: DVec3) -> Self
Create a transform at position with identity rotation.
Sourcepub fn forward(&self) -> DVec3
pub fn forward(&self) -> DVec3
The forward direction (local -Z in right-handed coordinates, or local +Z depending on convention; matches glam’s default).
Sourcepub const fn encoded_len(&self) -> usize
pub const fn encoded_len(&self) -> usize
Byte length of the replication encoding written by Self::encode.
Always Self::ENCODED_LEN — the encoding is fixed-width, so this
does not depend on self. It takes a receiver only so call sites can
write transform.encoded_len() next to transform.encode(..).
Sourcepub fn encode(&self, out: &mut Vec<u8>)
pub fn encode(&self, out: &mut Vec<u8>)
Append the replication encoding to out (little-endian, platform-
and run-deterministic).
Sourcepub fn decode(data: &[u8]) -> Option<Self>
pub fn decode(data: &[u8]) -> Option<Self>
Decode a transform from the encoding written by Self::encode.
Returns None if data is not exactly Self::ENCODED_LEN bytes, if
any component is not finite, or if the rotation is not (near enough) a
unit quaternion.
This runs on bytes a peer sent us. A NaN or infinite position poisons
every AABB it reaches and, through them, the whole BVH; a degenerate
quaternion turns Self::forward / Self::right / Self::up
into garbage. Neither is representable by Self::encode, so
rejecting them here costs a well-behaved peer nothing.
Sourcepub fn encode_wire(&self, out: &mut Vec<u8>)
pub fn encode_wire(&self, out: &mut Vec<u8>)
Append the replicated form to out: Self::WIRE_SCHEMA’s
Self::QUANTIZED_LEN bytes when the position is inside
Self::WIRE_POSITION, otherwise the exact Self::encode form.
The fallback is what keeps an entity outside the declared range where
it is: clamping it to the range’s edge would move it on every client
and say nothing. The two lengths differ, which is how
Self::decode_wire tells them apart.
Sourcepub fn decode_wire(data: &[u8]) -> Option<Self>
pub fn decode_wire(data: &[u8]) -> Option<Self>
Decode either form Self::encode_wire writes, telling them apart by
length.
Returns None for any other length, and for what Self::decode
refuses. A quantized payload always holds a unit quaternion and a
finite position; one with a padding bit or a code the encoder never
writes is refused.
Sourcepub fn lerp(&self, other: &Self, alpha: f64) -> Self
pub fn lerp(&self, other: &Self, alpha: f64) -> Self
Linearly interpolate between self and other at alpha ∈ [0, 1].
Position is lerped; rotation is glam’s nlerp (shortest-path corrected, renormalised). This is presentation-only smoothing for the client render path — simulation state is never interpolated.
Trait Implementations§
impl Copy for Transform
Source§impl Quantized for Transform
The quantized wire form Transform::encode_wire prefers.
impl Quantized for Transform
The quantized wire form Transform::encode_wire prefers.