pub struct Mat2 {
pub rows: [Vec2<f32>; 2],
}
Expand description
A 2x2-component Euclidean matrix useful for linear algebra computation in game development and 2D rendering.
Fields§
§rows: [Vec2<f32>; 2]
The two rows of the matrix, represented by an array of two Vec2<f32>
objects.
Implementations§
source§impl Mat2
impl Mat2
sourcepub fn identity() -> Mat2
pub fn identity() -> Mat2
Constructs a 2x2 identity matrix.
Examples
use gamemath::{Mat2, Vec2};
let m = Mat2::identity();
assert_eq!(m[0], Vec2::new(1.0, 0.0));
assert_eq!(m[1], Vec2::new(0.0, 1.0));
sourcepub fn transposed(&self) -> Mat2
pub fn transposed(&self) -> Mat2
Extracts and returns a transposed representation of the calling Mat2
object.
Examples
use gamemath::Mat2;
let m: Mat2 = ((0.0, 1.0),
(2.0, 3.0)).into();
assert_eq!(m.transposed(), ((0.0, 2.0),
(1.0, 3.0)).into());
sourcepub fn transpose(&mut self)
pub fn transpose(&mut self)
Performs a transpose operation on the calling Mat2
object.
Examples
use gamemath::Mat2;
let mut m: Mat2 = ((0.0, 1.0),
(3.0, 4.0)).into();
m.transpose();
assert_eq!(m, ((0.0, 3.0),
(1.0, 4.0)).into());
sourcepub fn rotation(radians: f32) -> Mat2
pub fn rotation(radians: f32) -> Mat2
Constructs a 2x2 rotation matrix from a radians value.
Examples
use gamemath::{Mat2, Vec2};
let m = Mat2::rotation(1.0);
assert_eq!(m[0], Vec2::new(0.5403023, -0.84147096,));
assert_eq!(m[1], Vec2::new(0.84147096, 0.54030230,));
sourcepub fn rotated(&self, radians: f32) -> Mat2
pub fn rotated(&self, radians: f32) -> Mat2
Calculates and returns a Mat2
object representing the calling Mat2
object rotated
by a radians value.
Examples
use gamemath::Mat2;
let m = Mat2::identity().rotated(1.0);
assert_eq!(m, ((0.5403023, -0.84147096,),
(0.84147096, 0.54030230,)).into());
sourcepub fn rotate(&mut self, radians: f32)
pub fn rotate(&mut self, radians: f32)
Rotates the calling Mat2
object by a radians value.
Examples
use gamemath::Mat2;
let mut m = Mat2::identity();
m.rotate(1.0);
assert_eq!(m, ((0.5403023, -0.84147096,),
(0.84147096, 0.54030230,)).into());
Trait Implementations§
source§impl AddAssign for Mat2
impl AddAssign for Mat2
source§fn add_assign(&mut self, right: Mat2)
fn add_assign(&mut self, right: Mat2)
Performs the
+=
operation. Read moresource§impl MulAssign for Mat2
impl MulAssign for Mat2
source§fn mul_assign(&mut self, right: Mat2)
fn mul_assign(&mut self, right: Mat2)
Performs the
*=
operation. Read moresource§impl PartialEq for Mat2
impl PartialEq for Mat2
source§impl SubAssign for Mat2
impl SubAssign for Mat2
source§fn sub_assign(&mut self, right: Mat2)
fn sub_assign(&mut self, right: Mat2)
Performs the
-=
operation. Read moreimpl Copy for Mat2
impl StructuralPartialEq for Mat2
Auto Trait Implementations§
impl RefUnwindSafe for Mat2
impl Send for Mat2
impl Sync for Mat2
impl Unpin for Mat2
impl UnwindSafe for Mat2
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