[][src]Struct hektor::mat4::Mat4

#[repr(C)]
pub struct Mat4(pub [[f32; 4]; 4]);

A 4x4 Matrix.

  • Row Major: index via m[row][col] when picking a location.

Methods

impl Mat4[src]

pub const fn zero() -> Self[src]

Const function for Mat4 with 0.0 in all positions.

use hektor::Mat4;
const MAT4_ZERO: Mat4 = Mat4::zero();
assert_eq!(MAT4_ZERO, Mat4([
   [0.0, 0.0, 0.0, 0.0],
   [0.0, 0.0, 0.0, 0.0],
   [0.0, 0.0, 0.0, 0.0],
   [0.0, 0.0, 0.0, 0.0],
 ]));

pub const fn identity() -> Self[src]

Const function for the identity Mat4.

use hektor::Mat4;
const MAT4_IDENTITY: Mat4 = Mat4::identity();
assert_eq!(MAT4_IDENTITY, Mat4([
   [1.0, 0.0, 0.0, 0.0],
   [0.0, 1.0, 0.0, 0.0],
   [0.0, 0.0, 1.0, 0.0],
   [0.0, 0.0, 0.0, 1.0],
 ]));

pub const fn scale_xyz(x: f32, y: f32, z: f32) -> Mat4[src]

Const function for a Mat4 to scale a Vec4 in 3D space.

use hektor::Mat4;
const MAT4_SCALE: Mat4 = Mat4::scale_xyz(2.0, 3.0, 4.0);
assert_eq!(MAT4_SCALE, Mat4([
   [2.0, 0.0, 0.0, 0.0],
   [0.0, 3.0, 0.0, 0.0],
   [0.0, 0.0, 4.0, 0.0],
   [0.0, 0.0, 0.0, 1.0],
 ]));

pub const fn translate_xyz(x: f32, y: f32, z: f32) -> Mat4[src]

Const function for a Mat4 to translate a Vec4 in 3D space.

use hektor::Mat4;
const MAT4_SCALE: Mat4 = Mat4::translate_xyz(2.0, 3.0, 4.0);
assert_eq!(MAT4_SCALE, Mat4([
   [1.0, 0.0, 0.0, 2.0],
   [0.0, 1.0, 0.0, 3.0],
   [0.0, 0.0, 1.0, 4.0],
   [0.0, 0.0, 0.0, 1.0],
 ]));

Trait Implementations

impl DerefMut for Mat4[src]

fn deref_mut(&mut self) -> &mut Self::Target[src]

DerefMut to the inner 4 element array of 4 element arrays

impl Deref for Mat4[src]

type Target = [[f32; 4]; 4]

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Deref to the inner 4 element array of 4 element arrays

impl Clone for Mat4[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Mat4[src]

impl PartialEq<Mat4> for Mat4[src]

fn eq(&self, other: &Self) -> bool[src]

use hektor::Mat4;
assert_eq!(Mat4::identity(), Mat4::identity());

fn ne(&self, other: &Self) -> bool[src]

use hektor::Mat4;
assert_ne!(Mat4::zero(), Mat4::identity());

impl From<[[f32; 4]; 4]> for Mat4[src]

fn from(array: [[f32; 4]; 4]) -> Self[src]

Directly wraps the given array.

impl From<Mat4> for [[f32; 4]; 4][src]

fn from(mat: Mat4) -> Self[src]

Directly unwraps the given array.

impl Copy for Mat4[src]

impl Add<Mat4> for Mat4[src]

type Output = Mat4

The resulting type after applying the + operator.

fn add(self, rhs: Mat4) -> Self::Output[src]

Element-wise addition between two Mat4.

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = Mat4([
  [0.6, 0.0, 6.2, 4.0],
  [5.0, 6.0, 7.0, 0.2],
  [4.0, 1.2, 7.0, 0.3],
  [0.8, 6.0, -9.0, 1.0],
]);
let expected = Mat4([
  [1.6, 2.0, 9.2, 8.0],
  [10.0, 12.0, 14.0, 8.2],
  [13.0, 2.2, 9.0, 3.3],
  [4.8, 11.0, -3.0, 8.0],
]);
assert_eq!(a + b, expected);

impl Add<f32> for Mat4[src]

type Output = Mat4

The resulting type after applying the + operator.

fn add(self, rhs: f32) -> Self::Output[src]

Adds the f32 to each element of the Mat4 (float on the right).

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 30.0;
let expected = Mat4([
  [31.0, 32.0, 33.0, 34.0],
  [35.0, 36.0, 37.0, 38.0],
  [39.0, 31.0, 32.0, 33.0],
  [34.0, 35.0, 36.0, 37.0],
]);
assert_eq!(a + b, expected);

impl Add<Mat4> for f32[src]

type Output = Mat4

The resulting type after applying the + operator.

fn add(self, rhs: Mat4) -> Self::Output[src]

Adds the f32 to each element of the Mat4 (float on the left).

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 30.0;
let expected = Mat4([
  [31.0, 32.0, 33.0, 34.0],
  [35.0, 36.0, 37.0, 38.0],
  [39.0, 31.0, 32.0, 33.0],
  [34.0, 35.0, 36.0, 37.0],
]);
assert_eq!(b + a, expected);

impl Sub<Mat4> for Mat4[src]

type Output = Mat4

The resulting type after applying the - operator.

fn sub(self, rhs: Mat4) -> Self::Output[src]

Element-wise subtraction between two Mat4.

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = Mat4([
  [0.5, 0.0, 6.0, 4.0],
  [5.0, 6.0, 7.0, 0.2],
  [4.0, 1.5, 7.0, 0.3],
  [0.8, 6.0, -9.0, 1.0],
]);
let expected = Mat4([
  [0.5, 2.0, -3.0, 0.0],
  [0.0, 0.0, 0.0, 7.8],
  [5.0, -0.5, -5.0, 2.7],
  [3.2, -1.0, 15.0, 6.0],
]);
assert_eq!(a - b, expected);

impl Sub<f32> for Mat4[src]

type Output = Mat4

The resulting type after applying the - operator.

fn sub(self, rhs: f32) -> Self::Output[src]

Subs the f32 from each element of the Mat4 (float on the right).

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 1.0;
let expected = Mat4([
  [0.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
  [8.0, 0.0, 1.0, 2.0],
  [3.0, 4.0, 5.0, 6.0],
]);
assert_eq!(a - b, expected);

impl Mul<Mat4> for f32[src]

type Output = Mat4

The resulting type after applying the * operator.

fn mul(self, rhs: Mat4) -> Self::Output[src]

Multiplies the f32 by each element of the Mat4 (float on the left).

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 10.0;
let expected = Mat4([
  [10.0, 20.0, 30.0, 40.0],
  [50.0, 60.0, 70.0, 80.0],
  [90.0, 10.0, 20.0, 30.0],
  [40.0, 50.0, 60.0, 70.0],
]);
assert_eq!(b * a, expected);

impl Mul<Mat4> for Mat4[src]

type Output = Mat4

The resulting type after applying the * operator.

fn mul(self, rhs: Mat4) -> Self::Output[src]

Multiply this Mat4 by the other Mat4 on the right.

use hektor::Mat4;
let i = Mat4::identity();
assert_eq!(i * i, i);
let a = Mat4([
  [3.0, 5.0, 7.0, 8.0],
  [1.0, 2.0, 8.0, 7.0],
  [4.0, 5.0, 3.0, -2.0],
  [1.0, 6.0, 7.0, 9.0],
]);
let b = Mat4([
  [2.0, 8.0, 6.0, 9.0],
  [3.0, -5.0, 6.0, 7.0],
  [1.0, 4.0, 9.0, -3.0],
  [10.0, -2.0, 5.0, 2.0],
]);
let expected = Mat4([
  [108.0, 11.0, 151.0, 57.0],
  [86.0, 16.0, 125.0, 13.0],
  [6.0, 23.0, 71.0, 58.0],
  [117.0, -12.0, 150.0, 48.0],
]);
assert_eq!(a * b, expected);

impl Mul<f32> for Mat4[src]

type Output = Mat4

The resulting type after applying the * operator.

fn mul(self, rhs: f32) -> Self::Output[src]

Multiplies the f32 by each element of the Mat4 (float on the right).

use hektor::Mat4;
let a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 10.0;
let expected = Mat4([
  [10.0, 20.0, 30.0, 40.0],
  [50.0, 60.0, 70.0, 80.0],
  [90.0, 10.0, 20.0, 30.0],
  [40.0, 50.0, 60.0, 70.0],
]);
assert_eq!(a * b, expected);

impl Mul<Vec4> for Mat4[src]

type Output = Vec4

The resulting type after applying the * operator.

fn mul(self, rhs: Vec4) -> Self::Output[src]

Multiply this Mat4 and a Vec4 on the right.

use hektor::{Mat4, Vec4};
let v = Vec4([1.0, 2.0, 3.0, 4.0]);
assert_eq!(Mat4::identity() * v, v);
assert_eq!(Mat4::zero() * v, Vec4::zero());

impl AddAssign<Mat4> for Mat4[src]

fn add_assign(&mut self, rhs: Mat4)[src]

Element-wise addition into the Mat4 on the left.

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = Mat4([
  [0.6, 0.0, 6.2, 4.0],
  [5.0, 6.0, 7.0, 0.2],
  [4.0, 1.2, 7.0, 0.3],
  [0.8, 6.0, -9.0, 1.0],
]);
let expected = Mat4([
  [1.6, 2.0, 9.2, 8.0],
  [10.0, 12.0, 14.0, 8.2],
  [13.0, 2.2, 9.0, 3.3],
  [4.8, 11.0, -3.0, 8.0],
]);
a += b;
assert_eq!(a, expected);

impl AddAssign<f32> for Mat4[src]

fn add_assign(&mut self, rhs: f32)[src]

Adds the f32 into each element of the Mat4.

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 30.0;
let expected = Mat4([
  [31.0, 32.0, 33.0, 34.0],
  [35.0, 36.0, 37.0, 38.0],
  [39.0, 31.0, 32.0, 33.0],
  [34.0, 35.0, 36.0, 37.0],
]);
a += b;
assert_eq!(a, expected);

impl SubAssign<Mat4> for Mat4[src]

fn sub_assign(&mut self, rhs: Mat4)[src]

Element-wise subtraction by the Mat4 on the left.

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = Mat4([
  [0.5, 0.0, 6.0, 4.0],
  [5.0, 6.0, 7.0, 0.2],
  [4.0, 1.5, 7.0, 0.3],
  [0.8, 6.0, -9.0, 1.0],
]);
let expected = Mat4([
  [0.5, 2.0, -3.0, 0.0],
  [0.0, 0.0, 0.0, 7.8],
  [5.0, -0.5, -5.0, 2.7],
  [3.2, -1.0, 15.0, 6.0],
]);
a -= b;
assert_eq!(a, expected);

impl SubAssign<f32> for Mat4[src]

fn sub_assign(&mut self, rhs: f32)[src]

Subs the f32 from each element of the Mat4.

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 1.0;
let expected = Mat4([
  [0.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
  [8.0, 0.0, 1.0, 2.0],
  [3.0, 4.0, 5.0, 6.0],
]);
a -= b;
assert_eq!(a, expected);

impl MulAssign<Mat4> for Mat4[src]

fn mul_assign(&mut self, rhs: Mat4)[src]

Multiply into this Mat4 using the other Mat4 on the right.

use hektor::Mat4;
let mut a = Mat4([
  [3.0, 5.0, 7.0, 8.0],
  [1.0, 2.0, 8.0, 7.0],
  [4.0, 5.0, 3.0, -2.0],
  [1.0, 6.0, 7.0, 9.0],
]);
let b = Mat4([
  [2.0, 8.0, 6.0, 9.0],
  [3.0, -5.0, 6.0, 7.0],
  [1.0, 4.0, 9.0, -3.0],
  [10.0, -2.0, 5.0, 2.0],
]);
let expected = Mat4([
  [108.0, 11.0, 151.0, 57.0],
  [86.0, 16.0, 125.0, 13.0],
  [6.0, 23.0, 71.0, 58.0],
  [117.0, -12.0, 150.0, 48.0],
]);
a *= b;
assert_eq!(a, expected);

impl MulAssign<f32> for Mat4[src]

fn mul_assign(&mut self, rhs: f32)[src]

Multiplies the f32 into each element of the Mat4.

use hektor::Mat4;
let mut a = Mat4([
  [1.0, 2.0, 3.0, 4.0],
  [5.0, 6.0, 7.0, 8.0],
  [9.0, 1.0, 2.0, 3.0],
  [4.0, 5.0, 6.0, 7.0],
]);
let b = 10.0;
let expected = Mat4([
  [10.0, 20.0, 30.0, 40.0],
  [50.0, 60.0, 70.0, 80.0],
  [90.0, 10.0, 20.0, 30.0],
  [40.0, 50.0, 60.0, 70.0],
]);
a *= b;
assert_eq!(a, expected);

impl Index<usize> for Mat4[src]

type Output = [f32; 4]

The returned type after indexing.

fn index(&self, i: usize) -> &Self::Output[src]

Index a row

impl Index<(usize, usize)> for Mat4[src]

type Output = f32

The returned type after indexing.

fn index(&self, (row, col): (usize, usize)) -> &Self::Output[src]

Index a (row,col)

impl IndexMut<usize> for Mat4[src]

fn index_mut(&mut self, i: usize) -> &mut Self::Output[src]

IndexMut a row

impl IndexMut<(usize, usize)> for Mat4[src]

fn index_mut(&mut self, (row, col): (usize, usize)) -> &mut Self::Output[src]

IndexMut a (row,col)

impl Default for Mat4[src]

Auto Trait Implementations

impl Send for Mat4

impl Sync for Mat4

Blanket Implementations

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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