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§
Sourcefn transform_mut(&mut self) -> &mut Mat4
fn transform_mut(&mut self) -> &mut Mat4
Mutable access to the model matrix.
Provided Methods§
Sourcefn pivot(&self) -> Vec3
fn pivot(&self) -> Vec3
Local-space point that rotations and scales turn around. Defaults to the local origin.
Sourcefn set_transform(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn set_transform(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
Replaces the model matrix outright, discarding any accumulated transforms.
Sourcefn reset_transform(&mut self) -> &mut Selfwhere
Self: Sized,
fn reset_transform(&mut self) -> &mut Selfwhere
Self: Sized,
Clears the model matrix back to the identity.
Sourcefn apply(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn apply(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
Composes transform onto the current matrix, about the local origin.
Sourcefn apply_about_pivot(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Selfwhere
Self: Sized,
Composes transform onto the current matrix, about Transformable::pivot.
Sourcefn translate(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
fn translate(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
Moves along the local X and Y axes.
Sourcefn translate3(&mut self, offset: Vec3) -> &mut Selfwhere
Self: Sized,
fn translate3(&mut self, offset: Vec3) -> &mut Selfwhere
Self: Sized,
Moves by offset in local space.
Sourcefn rotate(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
fn rotate(&mut self, radians: f32) -> &mut Selfwhere
Self: Sized,
Rotates around the Z axis — the in-plane spin for 2D content.
Sourcefn rotate_degrees(&mut self, degrees: f32) -> &mut Selfwhere
Self: Sized,
fn rotate_degrees(&mut self, degrees: f32) -> &mut Selfwhere
Self: Sized,
Transformable::rotate, taking degrees.
Sourcefn rotate_quat(&mut self, rotation: Quat) -> &mut Selfwhere
Self: Sized,
fn rotate_quat(&mut self, rotation: Quat) -> &mut Selfwhere
Self: Sized,
Applies an arbitrary rotation.
Sourcefn scale(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
fn scale(&mut self, x: f32, y: f32) -> &mut Selfwhere
Self: Sized,
Scales the X and Y axes independently.
Sourcefn scale_uniform(&mut self, factor: f32) -> &mut Selfwhere
Self: Sized,
fn scale_uniform(&mut self, factor: f32) -> &mut Selfwhere
Self: Sized,
Scales every axis by the same factor.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Transformable for Model
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);