[][src]Struct duku::Matrix4

#[repr(C)]pub struct Matrix4 {
    pub x: Vector4,
    pub y: Vector4,
    pub z: Vector4,
    pub w: Vector4,
}

4x4 Matrix.

Used for transforming vectors

Note: column-major

Example

This example is not tested
let vector = Vector3::new(2.0, 0.0, 0.0);
let matrix = Matrix4::scale([5.0, 1.0, 1.0]);
assert_eq!(matrix * vector, Vector3::new(10.0, 0.0, 0.0));

Fields

x: Vector4

the X column

y: Vector4

the Y column

z: Vector4

the Z column

w: Vector4

the W column

Implementations

impl Matrix4[src]

pub fn columns(
    x: impl Into<Vector4>,
    y: impl Into<Vector4>,
    z: impl Into<Vector4>,
    w: impl Into<Vector4>
) -> Self
[src]

Create matrix from column vectors

pub fn rows(
    x: impl Into<Vector4>,
    y: impl Into<Vector4>,
    z: impl Into<Vector4>,
    w: impl Into<Vector4>
) -> Self
[src]

Create matrix from row vectors

pub fn identity() -> Self[src]

Create identity matrix

pub fn translation(vector: impl Into<Vector3>) -> Self[src]

Create translation matrix

Translation matrix moves vectors around

Example

This example is not tested
let vector = Vector3::new(2.0, 0.0, 0.0);
let matrix = Matrix4::translation([5.0, 1.0, 1.0]);
assert_eq!(matrix * vector, Vector3::new(7.0, 1.0, 1.0));

pub fn scale(vector: impl Into<Vector3>) -> Self[src]

Create scale matrix

Scale matrix scales vectors

Example

This example is not tested
let vector = Vector3::new(2.0, 0.0, 0.0);
let matrix = Matrix4::scale([5.0, 1.0, 1.0]);
assert_eq!(matrix * vector, Vector3::new(10.0, 0.0, 0.0));

pub fn euler_rotation(x: f32, y: f32, z: f32) -> Self[src]

Create rotation matrix with euler angles

This rotation's yaw, pitch and roll are z, y and x

pub fn axis_rotation(axis: impl Into<Vector3>, angle: f32) -> Self[src]

Create rotation matrix around axis

This rotates vectors around axis by the angle

pub fn look_rotation(
    forward: impl Into<Vector3>,
    up: impl Into<Vector3>
) -> Self
[src]

Create rotation matrix to rotate towards direction

Note: up is used as a guide to try aligning to

pub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) -> Self[src]

Create perspective projection matrix

Note: this is a left-handed matrix with Z in range of [0; 1]

pub fn orthographic(width: f32, height: f32, near: f32, far: f32) -> Self[src]

Create orthographic projection matrix

Note: this is a left-handed matrix with Z in range of [0; 1]

pub fn inverse(&self) -> Option<Self>[src]

Calculate the inverse of the matrix

pub const fn rx(&self) -> Vector4[src]

Access the X row of the matrix

pub const fn ry(&self) -> Vector4[src]

Access the Y row of the matrix

pub const fn rz(&self) -> Vector4[src]

Access the Z row of the matrix

pub const fn rw(&self) -> Vector4[src]

Access the W row of the matrix

Trait Implementations

impl Clone for Matrix4[src]

impl Copy for Matrix4[src]

impl Debug for Matrix4[src]

impl From<[f32; 16]> for Matrix4[src]

impl From<Matrix4> for Quaternion[src]

impl From<Matrix4> for Transform[src]

impl From<Quaternion> for Matrix4[src]

impl From<Transform> for Matrix4[src]

impl Index<usize> for Matrix4[src]

type Output = Vector4

The returned type after indexing.

impl IndexMut<usize> for Matrix4[src]

impl Into<[f32; 16]> for Matrix4[src]

impl Mul<Matrix4> for Matrix4[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<Vector3> for Matrix4[src]

type Output = Vector3

The resulting type after applying the * operator.

impl Mul<Vector4> for Matrix4[src]

type Output = Vector4

The resulting type after applying the * operator.

impl Mul<f32> for Matrix4[src]

type Output = Matrix4

The resulting type after applying the * operator.

impl MulAssign<Matrix4> for Matrix4[src]

impl PartialEq<Matrix4> for Matrix4[src]

impl StructuralPartialEq for Matrix4[src]

Auto Trait Implementations

impl RefUnwindSafe for Matrix4

impl Send for Matrix4

impl Sync for Matrix4

impl Unpin for Matrix4

impl UnwindSafe for Matrix4

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.