Skip to main content

Transform

Struct Transform 

Source
pub struct Transform {
    pub position: Vec3,
    pub rotation: Quat,
    pub scale: Vec3,
    /* private fields */
}
Expand description

Transform component for scene nodes.

Encapsulates position, rotation, and scale (TRS) along with cached matrices and dirty-checking logic for efficient updates.

§Coordinate System

Uses a right-handed coordinate system:

  • +X: Right
  • +Y: Up
  • +Z: Forward (out of screen)

§Matrix Updates

The transform maintains two cached matrices:

  • local_matrix: Transform relative to parent
  • world_matrix: Transform relative to world origin

These are updated lazily when TRS values change, tracked by dirty checking against previous frame values.

§Example

let mut transform = Transform::new();
transform.position = Vec3::new(1.0, 2.0, 3.0);
transform.rotation = Quat::from_rotation_y(std::f32::consts::FRAC_PI_2);
transform.scale = Vec3::splat(2.0);

Fields§

§position: Vec3

Local position relative to parent.

§rotation: Quat

Local rotation as quaternion.

§scale: Vec3

Local scale factor.

Implementations§

Source§

impl Transform

Source

pub fn new() -> Transform

Creates a new transform with identity values.

Source

pub fn update_local_matrix(&mut self) -> bool

Checks and updates the local matrix if TRS values changed.

Returns true if the matrix was updated, false otherwise. This method is called by the transform system during hierarchy traversal.

Source

pub fn set_rotation_euler(&mut self, x: f32, y: f32, z: f32)

Sets rotation from Euler angles (XYZ order).

§Arguments
  • x - Rotation around X axis in radians
  • y - Rotation around Y axis in radians
  • z - Rotation around Z axis in radians
Source

pub fn rotation_euler(&self) -> Vec3

Returns the rotation as Euler angles (XYZ order) in radians.

Source

pub fn set_rotation_euler_with_order( &mut self, x: f32, y: f32, z: f32, order: EulerRot, )

Sets rotation from Euler angles with a custom rotation order.

Source

pub fn local_matrix(&self) -> &Affine3A

Returns a reference to the cached local matrix.

Source

pub fn world_matrix(&self) -> &Affine3A

Returns a reference to the cached world matrix.

Source

pub fn world_matrix_as_mat4(&self) -> Mat4

Returns the world matrix converted to Mat4.

Source

pub fn set_world_matrix(&mut self, mat: Affine3A)

Sets the world matrix directly.

Source

pub fn set_position(&mut self, pos: Vec3)

Sets position and marks the transform dirty.

Source

pub fn apply_local_matrix(&mut self, mat: Affine3A)

Directly sets the local matrix (e.g. from glTF or a physics engine). Decomposes it into TRS and synchronizes state.

Source

pub fn apply_local_matrix_from_mat4(&mut self, mat: Mat4)

Applies a local matrix from Mat4.

Source

pub fn look_at(&mut self, target: Vec3, up: Vec3)

Orients the transform to face a target point (in parent space).

Source

pub fn mark_dirty(&mut self)

Marks the transform as dirty, forcing a matrix recompute next frame.

Source

pub fn rotation_basis(&self) -> (Vec3, Vec3, Vec3)

Returns the local coordinate axes based on current rotation.

Returns (right, up, forward) vectors in world space.

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Transform

Source§

fn default() -> Transform

Returns the “default value” for a type. Read more
Source§

impl Copy for Transform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,