Skip to main content

Transformable

Trait Transformable 

Source
pub trait Transformable {
Show 20 methods // Required methods fn transform(&self) -> Mat4; fn transform_mut(&mut self) -> &mut Mat4; // Provided methods fn pivot(&self) -> Vec3 { ... } fn set_transform(&mut self, transform: Mat4) -> &mut Self where Self: Sized { ... } fn reset_transform(&mut self) -> &mut Self where Self: Sized { ... } fn apply(&mut self, transform: Mat4) -> &mut Self where Self: Sized { ... } fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Self where Self: Sized { ... } fn translate(&mut self, x: f32, y: f32) -> &mut Self where Self: Sized { ... } fn translate3(&mut self, offset: Vec3) -> &mut Self where Self: Sized { ... } fn rotate(&mut self, radians: f32) -> &mut Self where Self: Sized { ... } fn rotate_degrees(&mut self, degrees: f32) -> &mut Self where Self: Sized { ... } fn rotate_x(&mut self, radians: f32) -> &mut Self where Self: Sized { ... } fn rotate_y(&mut self, radians: f32) -> &mut Self where Self: Sized { ... } fn rotate_z(&mut self, radians: f32) -> &mut Self where Self: Sized { ... } fn rotate_quat(&mut self, rotation: Quat) -> &mut Self where Self: Sized { ... } fn scale(&mut self, x: f32, y: f32) -> &mut Self where Self: Sized { ... } fn scale_uniform(&mut self, factor: f32) -> &mut Self where Self: Sized { ... } fn scale3(&mut self, scale: Vec3) -> &mut Self where Self: Sized { ... } fn flip_x(&mut self) -> &mut Self where Self: Sized { ... } fn flip_y(&mut self) -> &mut Self where Self: Sized { ... }
}
Expand description

Basic affine transformations for anything that carries a model matrix.

Implementors only supply Transformable::transform and Transformable::transform_mut (plus, optionally, a Transformable::pivot); every operation below is provided.

§Composition order

Each operation is post-multiplied onto the existing matrix, so it is applied in the object’s local space — the frame established by the transforms already on it. Chaining therefore reads outside-in:

// Rotate a quarter turn, then move 10 units along the *rotated* X axis.
thing.rotate(std::f32::consts::FRAC_PI_2).translate(10.0, 0.0);

Rotations and scales pivot around Transformable::pivot, which defaults to the local origin. Translations are unaffected by the pivot. Use Transformable::set_transform when you want to drive the matrix directly instead of accumulating onto it.

Required Methods§

Source

fn transform(&self) -> Mat4

The current model matrix.

Source

fn transform_mut(&mut self) -> &mut Mat4

Mutable access to the model matrix.

Provided Methods§

Source

fn pivot(&self) -> Vec3

Local-space point that rotations and scales turn around. Defaults to the local origin.

Source

fn set_transform(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Replaces the model matrix outright, discarding any accumulated transforms.

Source

fn reset_transform(&mut self) -> &mut Self
where Self: Sized,

Clears the model matrix back to the identity.

Source

fn apply(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about the local origin.

Source

fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about Transformable::pivot.

Source

fn translate(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Moves along the local X and Y axes.

Source

fn translate3(&mut self, offset: Vec3) -> &mut Self
where Self: Sized,

Moves by offset in local space.

Source

fn rotate(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis — the in-plane spin for 2D content.

Source

fn rotate_degrees(&mut self, degrees: f32) -> &mut Self
where Self: Sized,

Transformable::rotate, taking degrees.

Source

fn rotate_x(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the X axis.

Source

fn rotate_y(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Y axis.

Source

fn rotate_z(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis.

Source

fn rotate_quat(&mut self, rotation: Quat) -> &mut Self
where Self: Sized,

Applies an arbitrary rotation.

Source

fn scale(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Scales the X and Y axes independently.

Source

fn scale_uniform(&mut self, factor: f32) -> &mut Self
where Self: Sized,

Scales every axis by the same factor.

Source

fn scale3(&mut self, scale: Vec3) -> &mut Self
where Self: Sized,

Scales by scale in local space.

Source

fn flip_x(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s vertical axis.

Source

fn flip_y(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s horizontal axis.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Transformable for Model

Source§

impl Transformable for Sprite

Rotations and scales pivot around the middle of the sprite’s quad, so a sprite spins in place rather than swinging around its anchor corner.

sprite.reset_transform().rotate(angle).scale_uniform(2.0);