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
impl Mat3
Sourcepub fn identity() -> Mat3
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));
Sourcepub fn transposed(&self) -> Mat3
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());
Sourcepub fn transpose(&mut self)
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());
Sourcepub fn rotation(radians: f32) -> Mat3
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));
Sourcepub fn rotated(&self, radians: f32) -> Mat3
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());
Sourcepub fn rotate(&mut self, radians: f32)
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());
Sourcepub fn scaled(&self, factor: Vec2<f32>) -> Mat3
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());
Sourcepub fn scale(&mut self, factor: Vec2<f32>)
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());
Sourcepub fn translated(&self, translation: Vec2<f32>) -> Mat3
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());
Sourcepub fn translate(&mut self, translation: Vec2<f32>)
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 AddAssign for Mat3
impl AddAssign for Mat3
Source§fn add_assign(&mut self, right: Mat3)
fn add_assign(&mut self, right: Mat3)
+=
operation. Read moreSource§impl MulAssign for Mat3
impl MulAssign for Mat3
Source§fn mul_assign(&mut self, right: Mat3)
fn mul_assign(&mut self, right: Mat3)
*=
operation. Read moreSource§impl SubAssign for Mat3
impl SubAssign for Mat3
Source§fn sub_assign(&mut self, right: Mat3)
fn sub_assign(&mut self, right: Mat3)
-=
operation. Read more