Struct Mat3

Source
pub struct Mat3 {
    pub rows: [Vec3<f32>; 3],
}
Expand description

A 3x3-component Euclidean matrix useful for linear algebra computation in game development and 2D rendering.

Fields§

§rows: [Vec3<f32>; 3]

The three rows of the matrix, represented by an array of three Vec3<f32> objects.

Implementations§

Source§

impl Mat3

Source

pub fn identity() -> Mat3

Constructs a 3x3 identity matrix.

§Examples
use gamemath::{Mat3, Vec3};

let m = Mat3::identity();

assert_eq!(m[0], Vec3::new(1.0, 0.0, 0.0));
assert_eq!(m[1], Vec3::new(0.0, 1.0, 0.0));
assert_eq!(m[2], Vec3::new(0.0, 0.0, 1.0));
Source

pub fn transposed(&self) -> Mat3

Extracts and returns a transposed representation of the calling Mat3 object.

§Examples
use gamemath::Mat3;

let m: Mat3 = ((0.0, 1.0, 2.0),
               (3.0, 4.0, 5.0),
               (6.0, 7.0, 8.0)).into();

assert_eq!(m.transposed(), ((0.0, 3.0, 6.0),
                            (1.0, 4.0, 7.0),
                            (2.0, 5.0, 8.0)).into());
Source

pub fn transpose(&mut self)

Performs a transpose operation on the calling Mat3 object.

§Examples
use gamemath::Mat3;

let mut m: Mat3 = ((0.0, 1.0, 2.0),
                   (3.0, 4.0, 5.0),
                   (6.0, 7.0, 8.0)).into();

m.transpose();

assert_eq!(m, ((0.0, 3.0, 6.0),
               (1.0, 4.0, 7.0),
               (2.0, 5.0, 8.0)).into());
Source

pub fn rotation(radians: f32) -> Mat3

Constructs a 3x3 rotation matrix from a radians value.

§Examples
use gamemath::{Mat3, Vec3};

let m = Mat3::rotation(1.0);

assert_eq!(m[0], Vec3::new(0.5403023,  -0.84147096, 0.0));
assert_eq!(m[1], Vec3::new(0.84147096,  0.5403023,  0.0));
assert_eq!(m[2], Vec3::new(0.0,         0.0,        1.0));
Source

pub fn rotated(&self, radians: f32) -> Mat3

Calculates and returns a Mat4 object representing the calling Mat3 object rotated by a radians value.

§Examples
use gamemath::Mat3;

let m = Mat3::identity().rotated(1.0);

assert_eq!(m, ((0.5403023,  -0.84147096, 0.0),
               (0.84147096,  0.5403023,  0.0),
               (0.0,         0.0,        1.0)).into());
Source

pub fn rotate(&mut self, radians: f32)

Rotates the calling Mat3 object by a radians value.

§Examples
use gamemath::Mat3;

let mut m = Mat3::identity();

m.rotate(1.0);

assert_eq!(m, ((0.5403023,  -0.84147096, 0.0),
               (0.84147096,  0.5403023,  0.0),
               (0.0,         0.0,        1.0)).into());
Source

pub fn scaled(&self, factor: Vec2<f32>) -> Mat3

Calculates and returns a Mat3 object representing the calling Mat3 object scaled by a Vec2<f32>.

§Examples
use gamemath::{Mat3, Vec2};

let m = Mat3::identity();

assert_eq!(m.scaled(Vec2::new(1.0, 2.0)), ((1.0, 0.0, 0.0),
                                           (0.0, 2.0, 0.0),
                                           (0.0, 0.0, 1.0)).into());
Source

pub fn scale(&mut self, factor: Vec2<f32>)

Performs the scale operation on the calling Mat3 object, scaling it by a Vec2<f32>.

§Examples
use gamemath::{Mat3, Vec2};

let mut m = Mat3::identity();

m.scale(Vec2::new(1.0, 2.0));

assert_eq!(m, ((1.0, 0.0, 0.0),
               (0.0, 2.0, 0.0),
               (0.0, 0.0, 1.0)).into());
Source

pub fn translated(&self, translation: Vec2<f32>) -> Mat3

Calculates and returns a Mat3 object representing the calling Mat3 object translated by a Vec2<f32>.

§Examples
use gamemath::{Mat3, Vec2};

let m = Mat3::identity();

assert_eq!(m.translated(Vec2::new(1.0, 2.0)), ((1.0, 0.0, 0.0),
                                               (0.0, 1.0, 0.0),
                                               (1.0, 2.0, 1.0)).into());
Source

pub fn translate(&mut self, translation: Vec2<f32>)

Performs the translate operation on the calling Mat3 object, translating it by a Vec2<f32>.

§Examples
use gamemath::{Mat3, Vec2};

let mut m = Mat3::identity();

m.translate(Vec2::new(1.0, 2.0));

assert_eq!(m, ((1.0, 0.0, 0.0),
               (0.0, 1.0, 0.0),
               (1.0, 2.0, 1.0)).into());

Trait Implementations§

Source§

impl Add for Mat3

Source§

type Output = Mat3

The resulting type after applying the + operator.
Source§

fn add(self, right: Mat3) -> Mat3

Performs the + operation. Read more
Source§

impl AddAssign for Mat3

Source§

fn add_assign(&mut self, right: Mat3)

Performs the += operation. Read more
Source§

impl Clone for Mat3

Source§

fn clone(&self) -> Mat3

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mat3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mat3

Source§

fn default() -> Mat3

Returns the “default value” for a type. Read more
Source§

impl From<[[f32; 3]; 3]> for Mat3

Source§

fn from(slice: [[f32; 3]; 3]) -> Mat3

Converts to this type from the input type.
Source§

impl From<[Vec3<f32>; 3]> for Mat3

Source§

fn from(slice: [Vec3<f32>; 3]) -> Mat3

Converts to this type from the input type.
Source§

impl From<[f32; 9]> for Mat3

Source§

fn from(slice: [f32; 9]) -> Mat3

Converts to this type from the input type.
Source§

impl From<((f32, f32, f32), (f32, f32, f32), (f32, f32, f32))> for Mat3

Source§

fn from(tuple: ((f32, f32, f32), (f32, f32, f32), (f32, f32, f32))) -> Mat3

Converts to this type from the input type.
Source§

impl From<(Vec3<f32>, Vec3<f32>, Vec3<f32>)> for Mat3

Source§

fn from(tuple: (Vec3<f32>, Vec3<f32>, Vec3<f32>)) -> Mat3

Converts to this type from the input type.
Source§

impl From<(f32, f32, f32, f32, f32, f32, f32, f32, f32)> for Mat3

Source§

fn from(tuple: (f32, f32, f32, f32, f32, f32, f32, f32, f32)) -> Mat3

Converts to this type from the input type.
Source§

impl From<f32> for Mat3

Source§

fn from(value: f32) -> Mat3

Converts to this type from the input type.
Source§

impl Index<(usize, usize)> for Mat3

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &f32

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for Mat3

Source§

type Output = Vec3<f32>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Vec3<f32>

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for Mat3

Source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut f32

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Mat3

Source§

fn index_mut(&mut self, index: usize) -> &mut Vec3<f32>

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<Vec3<f32>> for Mat3

Source§

type Output = Vec3<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, vec: Vec3<f32>) -> Vec3<f32>

Performs the * operation. Read more
Source§

impl Mul for Mat3

Source§

type Output = Mat3

The resulting type after applying the * operator.
Source§

fn mul(self, right: Mat3) -> Mat3

Performs the * operation. Read more
Source§

impl MulAssign for Mat3

Source§

fn mul_assign(&mut self, right: Mat3)

Performs the *= operation. Read more
Source§

impl PartialEq for Mat3

Source§

fn eq(&self, other: &Mat3) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Mat3

Source§

type Output = Mat3

The resulting type after applying the - operator.
Source§

fn sub(self, right: Mat3) -> Mat3

Performs the - operation. Read more
Source§

impl SubAssign for Mat3

Source§

fn sub_assign(&mut self, right: Mat3)

Performs the -= operation. Read more
Source§

impl Copy for Mat3

Source§

impl StructuralPartialEq for Mat3

Auto Trait Implementations§

§

impl Freeze for Mat3

§

impl RefUnwindSafe for Mat3

§

impl Send for Mat3

§

impl Sync for Mat3

§

impl Unpin for Mat3

§

impl UnwindSafe for Mat3

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.