pub struct Transform2D { /* private fields */ }Expand description
A 2D transform with position, rotation, scale, layer, and aspect ratio.
The position is expressed in normalized coordinates (0–1 across the screen). The aspect ratio corrects the horizontal component so that a square sprite appears square regardless of the viewport dimensions.
Call calc_matrix after mutating to recompute
the 4×4 matrix used for rendering.
§Coordinate system
- Position — normalized space:
(0, 0)is bottom-left,(1, 1)is top-right. - Rotation — degrees around the Z axis (counter-clockwise).
- Layer — draw order: higher values are rendered on top.
§Operations
| Category | Methods |
|---|---|
| Position — getter | pos |
| Position — absolute setter | set_pos_all, set_pos_x, set_pos_y |
| Position — relative move | move_all, move_x, move_y |
| Rotation — getter/setter | rot, set_rot, rotate |
| Scale — getter | scale |
| Scale — absolute setter | set_scale_all, set_scale_same, set_scale_x, set_scale_y |
| Scale — relative add | scale_all, scale_same, scale_x, scale_y |
| Layer | layer, set_layer |
| Aspect | aspect, set_aspect |
| Matrix | matrix, calc_matrix |
Implementations§
Source§impl Transform2D
impl Transform2D
Sourcepub fn calc_matrix(&mut self)
pub fn calc_matrix(&mut self)
Recomputes the transformation matrix from the current pos/rot/scale.
Sourcepub fn set_aspect(&mut self, aspect: f32)
pub fn set_aspect(&mut self, aspect: f32)
Sets the aspect ratio.
Sourcepub fn set_pos_all(&mut self, x: f32, y: f32)
pub fn set_pos_all(&mut self, x: f32, y: f32)
Sets the position to (x, y).
Sourcepub fn scale_same(&mut self, xy: f32)
pub fn scale_same(&mut self, xy: f32)
Adds xy to both scale components.
Sourcepub fn set_scale_all(&mut self, x: f32, y: f32)
pub fn set_scale_all(&mut self, x: f32, y: f32)
Sets the scale to (x, y).
Sourcepub fn set_scale_same(&mut self, xy: f32)
pub fn set_scale_same(&mut self, xy: f32)
Sets both scale components to xy.
Sourcepub fn set_scale_x(&mut self, x: f32)
pub fn set_scale_x(&mut self, x: f32)
Sets the scale X component.
Sourcepub fn set_scale_y(&mut self, y: f32)
pub fn set_scale_y(&mut self, y: f32)
Sets the scale Y component.
Trait Implementations§
Source§impl Clone for Transform2D
impl Clone for Transform2D
Source§fn clone(&self) -> Transform2D
fn clone(&self) -> Transform2D
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Transform2D
impl Debug for Transform2D
Auto Trait Implementations§
impl Freeze for Transform2D
impl RefUnwindSafe for Transform2D
impl Send for Transform2D
impl Sync for Transform2D
impl Unpin for Transform2D
impl UnsafeUnpin for Transform2D
impl UnwindSafe for Transform2D
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().