Struct ludomath::vec2d::Transform
[−]
[src]
pub struct Transform { pub mat: [[f32; 2]; 2], pub vec: Vector, }
Represents an affine transformation of the plane.
Can represent any linear transformation, plus translation. Equivalent in layout to a GLSL (column-major) 3x2 matrix, where the rightmost column contains the translation vector.
Fields
mat: [[f32; 2]; 2]
The 2x2 linear transformation matrix.
Stored in column-major order as a 2D array.
vec: Vector
The translation vector.
Methods
impl Transform
[src]
pub fn new(translation: Vector, rotation: Rotation, scale: Vector) -> Transform
[src]
Constructs a new Transform
from translation, rotation and scale.
pub fn new_rad(translation: Vector, angle: f32, scale: Vector) -> Transform
[src]
Constructs a new Transform
from position, rotation and scale.
Rotation is given as an angle in radians.
pub fn new_deg(translation: Vector, angle: f32, scale: Vector) -> Transform
[src]
Constructs a new Transform
from position, rotation and scale.
Rotation is given as an angle in degrees.
pub fn new_matrix(
mat1_1: f32,
mat2_1: f32,
mat1_2: f32,
mat2_2: f32
) -> Transform
[src]
mat1_1: f32,
mat2_1: f32,
mat1_2: f32,
mat2_2: f32
) -> Transform
Constructs a Transform
from a 2x2 linear tranformation matrix.
The order of the arguments is their order in memory - column-major.
pub fn new_scaling(scale: Vector) -> Transform
[src]
Constructs a scaling Transform
.
pub fn new_rotation(rotation: Rotation) -> Transform
[src]
Constructs a rotating Transform
from a Rotation
.
pub fn new_rotation_rad(angle: f32) -> Transform
[src]
Constructs a rotating Transform
from an angle in radians.
pub fn new_rotation_deg(angle: f32) -> Transform
[src]
Constructs a rotating Transform
from an angle in degrees.
pub fn new_translation(offset: Vector) -> Transform
[src]
Constructs a translating Transform
from an offset.
pub fn translate(self, offset: Vector) -> Transform
[src]
Creates a new Transform
by translating an existing one.
The offset is relative to the global coordinate system.
pub fn translate_mut(&mut self, offset: Vector)
[src]
Translates a Transform
, mutating it.
The offset is relative to the global coordinate system.
pub fn translate_local(self, offset: Vector) -> Transform
[src]
Creates a new Transform
by translating an existing one.
The offset is relative to the local coordinate system defined
by the Transform
.
pub fn translate_local_mut(&mut self, offset: Vector)
[src]
Translates a Transform
, mutating it.
The offset is relative to the local coordinate system defined
by the Transform
.
pub fn rotate(self, rotation: Rotation) -> Transform
[src]
Creates a new Transform
by rotating an existing one.
pub fn rotate_rad(self, angle: f32) -> Transform
[src]
Creates a new Transform
by rotating an existing one
by an angle in radians.
pub fn rotate_deg(self, angle: f32) -> Transform
[src]
Creates a new Transform
by rotating an existing one
by an angle in degrees.
pub fn rotate_mut(&mut self, rotation: Rotation)
[src]
Rotates a Transform
, mutating it.
pub fn rotate_rad_mut(&mut self, angle: f32)
[src]
Rotates a Transform
by an angle in radians, mutating it.
pub fn rotate_deg_mut(&mut self, angle: f32)
[src]
Rotates a Transform
by an angle in degrees, mutating it.
pub fn scale(self, factor: Vector) -> Transform
[src]
Creates a new Transform
by scaling an existing one.
pub fn scale_by_num(self, factor: f32) -> Transform
[src]
Creates a new Transform
by scaling an existing one.
Scales by the same amount in both axes.
pub fn scale_mut(&mut self, factor: Vector)
[src]
Scales a Transform
, mutating it.
pub fn scale_by_num_mut(&mut self, factor: f32)
[src]
Scales a Transform
equally in both axes, mutating it.
pub fn transform_arr<T>(self, arr: &[T]) -> Vec<T> where
Self: Transformation<T>,
T: Copy,
[src]
Self: Transformation<T>,
T: Copy,
Transforms a list of transformable items into a new Vec
.
pub fn transform_arr_mut<T>(self, arr: &mut [T]) where
Self: Transformation<T>,
T: Copy,
[src]
Self: Transformation<T>,
T: Copy,
Transforms a list of transformable items, mutating them.
pub fn from_mat3x2(mat3x2: [[f32; 2]; 3]) -> Transform
[src]
Converts a OpenGL-style mat3x2
to a Transform
.
Optimizes into a simple copy, since the types have the same layout.
pub fn to_mat3x2(self) -> [[f32; 2]; 3]
[src]
Converts a Transform
to a OpenGL-style mat3x2
.
Optimizes into a simple copy, since the types have the same layout.
pub fn to_mat4x4(self) -> [[f32; 4]; 4]
[src]
Converts a Transform
to a OpenGL-style mat4x4
.
The matrix is inserted in the top-left corner, and the translation vector in the top of the rightmost column. The rest of the elements are set to the identity matrix.
pub fn arr_from_mat3x2s(arr: &[[[f32; 4]; 4]]) -> &[Transform]
[src]
Reinterprets a slice of OpenGL-style mat4x4
s as Transform
s.
Does not allocate a new array, only changes the type of the pointer.
pub fn arr_to_mat3x2s(arr: &[Transform]) -> &[[[f32; 4]; 4]]
[src]
Reinterprets a slice of Transform
s as OpenGL-style mat4x4
s.
Does not allocate a new array, only changes the type of the pointer.
Trait Implementations
impl Clone for Transform
[src]
fn clone(&self) -> Transform
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Transform
[src]
impl PartialEq for Transform
[src]
fn eq(&self, __arg_0: &Transform) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Transform) -> bool
[src]
This method tests for !=
.
impl Debug for Transform
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl MaybeInvertible for Transform
[src]
fn is_invertible(self) -> bool
[src]
Returns true
if the object is invertible, false
otherwise.
fn invert(self) -> Self
[src]
Returns the inverse of an object. Read more
fn invert_mut(&mut self)
[src]
Inverts an object, mutating it.
fn invert_checked(self) -> Option<Self>
[src]
Attempts to compute the inverse of a transformation. Read more
impl Transformation<Vector> for Transform
[src]
fn transform(self, vec: Vector) -> Vector
[src]
Returns a transformed copy of an object. Read more
fn inverse_transform(self, vec: Vector) -> Vector
[src]
Transforms an object by the inverse of a transformation. Read more
fn transform_mut(self, operand: &mut T) where
T: Copy,
[src]
T: Copy,
Transforms an object, mutating it.
fn inverse_transform_checked(self, operand: T) -> Option<T>
[src]
Transforms an object by the inverse of a transformation. Read more
impl Transformation<Point> for Transform
[src]
fn transform(self, pt: Point) -> Point
[src]
Returns a transformed copy of an object. Read more
fn inverse_transform(self, pt: Point) -> Point
[src]
Transforms an object by the inverse of a transformation. Read more
fn transform_mut(self, operand: &mut T) where
T: Copy,
[src]
T: Copy,
Transforms an object, mutating it.
fn inverse_transform_checked(self, operand: T) -> Option<T>
[src]
Transforms an object by the inverse of a transformation. Read more
impl Transformation<Transform> for Transform
[src]
fn transform(self, rhs: Transform) -> Transform
[src]
Returns a transformed copy of an object. Read more
fn transform_mut(self, operand: &mut T) where
T: Copy,
[src]
T: Copy,
Transforms an object, mutating it.
fn inverse_transform(self, operand: T) -> T
[src]
Transforms an object by the inverse of a transformation. Read more
fn inverse_transform_checked(self, operand: T) -> Option<T>
[src]
Transforms an object by the inverse of a transformation. Read more