Struct Mat4

Source
#[repr(C)]
pub struct Mat4<T>(/* private fields */);
Expand description

4x4 matrix

Implementations§

Source§

impl<T> Mat4<T>
where T: Copy,

Source

pub fn transpose(self) -> Mat4<T>

Get transposed matrix.

§Examples
use batbox::*;
let matrix = Mat4::translate(vec3(1, 2, 3));
let matrix_transposed = matrix.transpose();
for i in 0..4 {
    for j in 0..4 {
        assert_eq!(matrix[(i, j)], matrix_transposed[(j, i)]);
    }
}
Source§

impl<T> Mat4<T>
where T: Num,

Source

pub fn from_orts(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> Mat4<T>

Source§

impl<T> Mat4<T>
where T: Float,

Source

pub fn inverse(self) -> Mat4<T>

Get inverse matrix.

§Examples
use batbox::*;
let matrix = Mat4::<f64>::rotate_x(0.123);
let matrix_inv = matrix.inverse();
let mult = matrix * matrix_inv;
for i in 0..4 {
    for j in 0..4 {
        assert!((mult[(i, j)] - if i == j { 1.0 } else { 0.0 }).abs() < 1e-5);
    }
}
Source§

impl<T> Mat4<T>
where T: Float,

Source

pub fn perspective(fov: T, aspect: T, near: T, far: T) -> Mat4<T>

Construct prespective projection matrix.

Source

pub fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T>

Construct frustum projection matrix.

Source§

impl<T> Mat4<T>
where T: Num + Copy,

Source

pub fn scale_uniform(factor: T) -> Mat4<T>

Construct a uniform scale matrix.

§Examples
use batbox::*;
let matrix = Mat4::scale_uniform(2);
assert_eq!(matrix * vec4(1, 2, 3, 1), vec4(2, 4, 6, 1));
Source

pub fn scale(factor: Vec3<T>) -> Mat4<T>

Construct a scale matrix.

§Examples
use batbox::*;
let matrix = Mat4::scale(vec3(1, 2, 3));
assert_eq!(matrix * vec4(1, 2, 3, 1), vec4(1, 4, 9, 1));
Source

pub fn translate(dv: Vec3<T>) -> Mat4<T>

Construct a translation matrix.

§Examples
use batbox::*;
let matrix = Mat4::translate(vec3(3, 2, 1));
assert_eq!(matrix * vec4(1, 2, 3, 1), vec4(4, 4, 4, 1));
Source§

impl<T> Mat4<T>
where T: Float,

Source

pub fn rotate_x(angle: T) -> Mat4<T>

Construct matrix rotating around x axis.

Source

pub fn rotate_y(angle: T) -> Mat4<T>

Construct matrix rotating around y axis.

Source

pub fn rotate_z(angle: T) -> Mat4<T>

Construct matrix rotating around z axis.

Source

pub fn rotate(v: Vec3<T>, angle: T) -> Mat4<T>
where T: SubAssign + AddAssign,

Source§

impl<T> Mat4<T>

Source

pub fn map<U, F>(self, f: F) -> Mat4<U>
where F: Fn(T) -> U,

Source§

impl<T> Mat4<T>
where T: Copy,

Source

pub fn new(values: [[T; 4]; 4]) -> Mat4<T>

Construct a matrix.

§Examples
use batbox::*;
let matrix = Mat4::new([
    [1, 2, 3, 4],
    [3, 4, 5, 6],
    [5, 6, 7, 8],
    [0, 5, 2, 9],
]);
Source

pub fn row(&self, row_index: usize) -> Vec4<T>

Source§

impl<T> Mat4<T>

Source

pub fn as_flat_array(&self) -> &[T; 16]

Source

pub fn as_flat_array_mut(&mut self) -> &mut [T; 16]

Source§

impl<T> Mat4<T>
where T: Num + Copy,

Source

pub fn zero() -> Mat4<T>

Construct zero matrix.

§Examples
use batbox::*;
let matrix = Mat4::<i32>::zero();
for i in 0..4 {
    for j in 0..4 {
        assert_eq!(matrix[(i, j)], 0);
    }
}
Source

pub fn identity() -> Mat4<T>

Construct identity matrix.

§Examples
use batbox::*;
let matrix = Mat4::<i32>::identity();
for i in 0..4 {
    for j in 0..4 {
        assert_eq!(matrix[(i, j)], if i == j { 1 } else { 0 });
    }
}

Trait Implementations§

Source§

impl<T> Add for Mat4<T>
where T: Num + Copy,

Source§

type Output = Mat4<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Mat4<T>) -> Mat4<T>

Performs the + operation. Read more
Source§

impl<T> AddAssign for Mat4<T>
where T: Num + Copy + AddAssign,

Source§

fn add_assign(&mut self, rhs: Mat4<T>)

Performs the += operation. Read more
Source§

impl<T> ApproxEq for Mat4<T>
where T: Float,

Source§

fn approx_distance_to(&self, other: &Mat4<T>) -> f32

Source§

fn approx_eq(&self, other: &Self) -> bool

Source§

fn approx_eq_eps(&self, other: &Self, eps: f32) -> bool

Source§

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

Source§

fn clone(&self) -> Mat4<T>

Returns a duplicate 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<T> Debug for Mat4<T>
where T: Debug,

Source§

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

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

impl<'de, T> Deserialize<'de> for Mat4<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Mat4<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Div<T> for Mat4<T>
where T: Num + Copy,

Source§

type Output = Mat4<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Mat4<T>

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Mat4<T>
where T: Num + Copy + DivAssign,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T> From<Quat<T>> for Mat4<T>
where T: Float,

Source§

fn from(quat: Quat<T>) -> Mat4<T>

Converts to this type from the input type.
Source§

impl<T> Index<(usize, usize)> for Mat4<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, _: (usize, usize)) -> &T

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

impl<T> IndexMut<(usize, usize)> for Mat4<T>

Source§

fn index_mut(&mut self, _: (usize, usize)) -> &mut T

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

impl<T> Mul<T> for Mat4<T>
where T: Num + Copy,

Source§

type Output = Mat4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Mat4<T>

Performs the * operation. Read more
Source§

impl<T> Mul<Vec4<T>> for Mat4<T>
where T: Num + Copy,

Source§

type Output = Vec4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec4<T>) -> Vec4<T>

Performs the * operation. Read more
Source§

impl<T> Mul for Mat4<T>
where T: Num + Copy + AddAssign,

Source§

type Output = Mat4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat4<T>) -> Mat4<T>

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Mat4<T>
where T: Num + Copy + MulAssign,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign for Mat4<T>
where T: Num + Copy + AddAssign,

Source§

fn mul_assign(&mut self, rhs: Mat4<T>)

Performs the *= operation. Read more
Source§

impl<T> Neg for Mat4<T>
where T: Num<Output = T> + Copy + Neg,

Source§

type Output = Mat4<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Mat4<T>

Performs the unary - operation. Read more
Source§

impl<T> Serialize for Mat4<T>
where T: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub for Mat4<T>
where T: Num + Copy,

Source§

type Output = Mat4<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Mat4<T>) -> Mat4<T>

Performs the - operation. Read more
Source§

impl<T> SubAssign for Mat4<T>
where T: Num + Copy + SubAssign,

Source§

fn sub_assign(&mut self, rhs: Mat4<T>)

Performs the -= operation. Read more
Source§

impl Uniform for Mat4<f32>

Source§

fn apply(&self, gl: &Context, info: &UniformInfo)

Source§

impl<T> Copy for Mat4<T>
where T: Copy,

Auto Trait Implementations§

§

impl<T> Freeze for Mat4<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Mat4<T>
where T: RefUnwindSafe,

§

impl<T> Send for Mat4<T>
where T: Send,

§

impl<T> Sync for Mat4<T>
where T: Sync,

§

impl<T> Unpin for Mat4<T>
where T: Unpin,

§

impl<T> UnwindSafe for Mat4<T>
where T: 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,