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 parentworld_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: Vec3Local position relative to parent.
rotation: QuatLocal rotation as quaternion.
scale: Vec3Local scale factor.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn update_local_matrix(&mut self) -> bool
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.
Sourcepub fn set_rotation_euler(&mut self, x: f32, y: f32, z: f32)
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 radiansy- Rotation around Y axis in radiansz- Rotation around Z axis in radians
Sourcepub fn rotation_euler(&self) -> Vec3
pub fn rotation_euler(&self) -> Vec3
Returns the rotation as Euler angles (XYZ order) in radians.
Sourcepub fn set_rotation_euler_with_order(
&mut self,
x: f32,
y: f32,
z: f32,
order: EulerRot,
)
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.
Sourcepub fn local_matrix(&self) -> &Affine3A
pub fn local_matrix(&self) -> &Affine3A
Returns a reference to the cached local matrix.
Sourcepub fn world_matrix(&self) -> &Affine3A
pub fn world_matrix(&self) -> &Affine3A
Returns a reference to the cached world matrix.
Sourcepub fn world_matrix_as_mat4(&self) -> Mat4
pub fn world_matrix_as_mat4(&self) -> Mat4
Returns the world matrix converted to Mat4.
Sourcepub fn set_world_matrix(&mut self, mat: Affine3A)
pub fn set_world_matrix(&mut self, mat: Affine3A)
Sets the world matrix directly.
Sourcepub fn set_position(&mut self, pos: Vec3)
pub fn set_position(&mut self, pos: Vec3)
Sets position and marks the transform dirty.
Sourcepub fn apply_local_matrix(&mut self, mat: Affine3A)
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.
Sourcepub fn apply_local_matrix_from_mat4(&mut self, mat: Mat4)
pub fn apply_local_matrix_from_mat4(&mut self, mat: Mat4)
Applies a local matrix from Mat4.
Sourcepub fn look_at(&mut self, target: Vec3, up: Vec3)
pub fn look_at(&mut self, target: Vec3, up: Vec3)
Orients the transform to face a target point (in parent space).
Sourcepub fn mark_dirty(&mut self)
pub fn mark_dirty(&mut self)
Marks the transform as dirty, forcing a matrix recompute next frame.
Sourcepub fn rotation_basis(&self) -> (Vec3, Vec3, Vec3)
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§
impl Copy for Transform
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnsafeUnpin for Transform
impl UnwindSafe for Transform
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().