Skip to main content

Transform

Struct Transform 

Source
pub struct Transform {
    pub position: Vec2,
    pub rotation: Angle,
    pub scale: Vec2,
    pub parent: Option<usize>,
    /* private fields */
}
Expand description

A 2D transform representing position, rotation, and scale.

Supports parent-child hierarchies so that child transforms inherit their parent’s world-space transform.

Fields§

§position: Vec2

Local position relative to parent.

§rotation: Angle

Local rotation in radians.

§scale: Vec2

Local scale (independent X/Y).

§parent: Option<usize>

Optional parent reference index (used by [SceneNode]).

Implementations§

Source§

impl Transform

Source

pub fn at(x: f32, y: f32) -> Self

Create a transform with the given position.

Source

pub fn new(x: f32, y: f32, rotation_degrees: f32, scale: f32) -> Self

Create a transform with position, rotation (degrees), and uniform scale.

Source

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

Set position and mark dirty.

Source

pub fn set_rotation_degrees(&mut self, degrees: f32)

Set rotation in degrees and mark dirty.

Source

pub fn set_scale(&mut self, s: f32)

Set uniform scale and mark dirty.

Source

pub fn set_scale_vec(&mut self, s: Vec2)

Set non-uniform scale and mark dirty.

Source

pub fn translate(&mut self, offset: Vec2)

Translate by an offset.

Source

pub fn rotate(&mut self, angle: Angle)

Rotate by an angle (radians).

Source

pub fn local_matrix(&self) -> Mat4

Get the local-space 4×4 matrix (TR × S).

Source

pub fn world_matrix(&mut self, parent_world: Option<Mat4>) -> Mat4

Get the world-space matrix, recomputing if dirty.

If a parent index is set, the parent’s world matrix should be passed.

Source

pub fn mark_dirty(&mut self)

Invalidate the world matrix, forcing recomputation next frame.

Source

pub fn world_position(&self) -> Vec2

Extract the world-space position from the world matrix.

Source

pub fn transform_point(&self, local_point: Vec2) -> Vec2

Transform a local point to world space.

Source

pub fn inverse_transform_point(&self, world_point: Vec2) -> Vec2

Inverse-transform a world point to local space.

Source

pub fn lerp_to(&self, other: &Transform, t: f32) -> Transform

Linearly interpolate between two transforms.

Source

pub fn look_at(&mut self, target: Vec2)

Look at a target point (sets rotation to face the target).

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

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

impl Default for Transform

Source§

fn default() -> Self

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

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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.