Skip to main content

Matrix4

Struct Matrix4 

Source
pub struct Matrix4<F: Float> { /* private fields */ }

Implementations§

Source§

impl<F: Float> Matrix4<F>

Source

pub fn new( m00: F, m01: F, m02: F, m03: F, m10: F, m11: F, m12: F, m13: F, m20: F, m21: F, m22: F, m23: F, m30: F, m31: F, m32: F, m33: F, ) -> Matrix4<F>

New 4x4 matrix from 16 values.

use math3d::matrices::Matrix4;

let m = Matrix4::new(
	1.0, 2.0, 3.0, 4.0,
	5.0, 6.0, 7.0, 8.0,
	9.0, 10.0, 11.0, 12.0,
	13.0, 14.0, 15.0, 16.0);

assert!(m.m[0][0] == 1.0);
assert!(m.m[3][3] == 16.0);
Source

pub fn identity() -> Matrix4<F>

New 4x4 identity matrix.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

assert!(m.m[0][0] == 1.0);
assert!(m.m[3][3] == 1.0);
Source

pub fn zero() -> Matrix4<F>

New 4x4 zero matrix.

use math3d::matrices::Matrix4;

let m = Matrix4::zero();

assert!(m.m[0][0] == 0.0);
assert!(m.m[3][3] == 0.0);
Source

pub fn from_vectors( v0: Vector4<F>, v1: Vector4<F>, v2: Vector4<F>, v3: Vector4<F>, ) -> Matrix4<F>

New 4x4 matrix from array of 4 vectors.

use math3d::matrices::Matrix4;

let m = Matrix4::from_vectors(
	Vector4::new(1.0, 2.0, 3.0, 4.0),
	Vector4::new(5.0, 6.0, 7.0, 8.0),
	Vector4::new(9.0, 10.0, 11.0, 12.0),
	Vector4::new(13.0, 14.0, 15.0, 16.0));

assert!(m.m[0][0] == 1.0);
assert!(m.m[3][3] == 16.0);
Source

pub fn from_array(m: [F; 16]) -> Matrix4<F>

New 4x4 matrix from array of 16 values.

use math3d::matrices::Matrix4;

let m = Matrix4::from_array([
	1.0, 2.0, 3.0, 4.0,
	5.0, 6.0, 7.0, 8.0,
	9.0, 10.0, 11.0, 12.0,
	13.0, 14.0, 15.0, 16.0]);

assert!(m.m[0][0] == 1.0);
assert!(m.m[3][3] == 16.0);
Source

pub fn index(&self, index: usize) -> &F

Index into matrix.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

assert!(m[0][0] == 1.0);
assert!(m[3][3] == 1.0);
Source

pub fn to_array_f32(&self) -> [f32; 16]

To array f32.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

let af32 = m.to_array_f32();

assert!(af32[0] == 1.0);
assert!(af32[15] == 1.0);
Source

pub fn to_array_f64(&self) -> [f64; 16]

To array f64

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

let af64 = m.to_array_f64();

assert!(af64[0] == 1.0);
assert!(af64[15] == 1.0);
Source

pub fn to_array_vectors(&self) -> [Vector4<F>; 4]

To array of vectors.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

let av = m.to_array_vectors();

assert!(av[0][0] == 1.0);
assert!(av[3][3] == 1.0);
Source

pub fn product(&self, other: Matrix4<F>) -> Matrix4<F>

Multiply 4x4 matrix by 4x4 matrix.

use math3d::matrices::Matrix4;

let m1 = Matrix4::identity();
let m2 = Matrix4::identity();

let m3 = m1 * m2;

assert!(m3 == m2);
Source

pub fn product_vector(&self, other: Vector4<F>) -> Vector4<F>

Multiply 4x4 matrix by 4x1 vector.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

let v = m * Vector4::new(1.0, 2.0, 3.0, 4.0);

assert!(v == Vector4::new(1.0, 2.0, 3.0, 4.0));
Source

pub fn transpose(&self) -> Matrix4<F>

Transpose 4x4 matrix.

use math3d::matrices::Matrix4;

let m = Matrix4::identity();

let m_t = m.transpose();

assert!(m_t == m);

Trait Implementations§

Source§

impl<F: Clone + Float> Clone for Matrix4<F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F: Copy + Float> Copy for Matrix4<F>

Source§

impl<F: Debug + Float> Debug for Matrix4<F>

Source§

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

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

impl<F: Float> Display for Matrix4<F>

Source§

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

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

impl<F: Float> Div for Matrix4<F>

Source§

type Output = Matrix4<F>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Matrix4<F>) -> Matrix4<F>

Performs the / operation. Read more
Source§

impl<F: Float> Div<F> for Matrix4<F>

Source§

type Output = Matrix4<F>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: F) -> Matrix4<F>

Performs the / operation. Read more
Source§

impl<F: Float> Index<usize> for Matrix4<F>

Source§

type Output = Vector4<F>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<F: Float> IndexMut<usize> for Matrix4<F>

Source§

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

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

impl<F: Float> Mul for Matrix4<F>

Source§

type Output = Matrix4<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix4<F>) -> Matrix4<F>

Performs the * operation. Read more
Source§

impl<F: Float> Mul<F> for Matrix4<F>

Source§

type Output = Matrix4<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: F) -> Matrix4<F>

Performs the * operation. Read more
Source§

impl<F: Float> Mul<Matrix4<F>> for Vector4<F>

Source§

type Output = Vector4<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Matrix4<F>) -> Vector4<F>

Performs the * operation. Read more
Source§

impl<F: Float> PartialEq for Matrix4<F>

Source§

fn eq(&self, other: &Matrix4<F>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<F> Freeze for Matrix4<F>
where [Vector4<F>; 4]: Freeze,

§

impl<F> RefUnwindSafe for Matrix4<F>
where [Vector4<F>; 4]: RefUnwindSafe,

§

impl<F> Send for Matrix4<F>
where [Vector4<F>; 4]: Send,

§

impl<F> Sync for Matrix4<F>
where [Vector4<F>; 4]: Sync,

§

impl<F> Unpin for Matrix4<F>
where [Vector4<F>; 4]: Unpin,

§

impl<F> UnsafeUnpin for Matrix4<F>
where [Vector4<F>; 4]: UnsafeUnpin,

§

impl<F> UnwindSafe for Matrix4<F>
where [Vector4<F>; 4]: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.