alloy::model::projection

Struct Projection

source
pub struct Projection { /* private fields */ }
Expand description

Representation of a projection matrix.

Projection matrices may be identity projections, which are normalized device coordinates, perspective projections, or orthographic projections.

Implementations§

source§

impl Projection

source

pub const fn identity() -> Self

Creates a new projection matrix.

source

pub fn orthographic(space: ClipSpace) -> Self

Computes an orthographic projection from the specified clip-space information.

§Parameters
  • space - The clip-space information.
source

pub fn perspective<A: Angle>(fov: A, aspect_ratio: f32, depth: Depth) -> Self

Computes a perspective projection from the specified angle, aspect ratio, and depth.

§Parameters
  • angle - The field of view angle.
  • aspect_ratio - The aspect ratio.
  • depth - The depth range.
source§

impl Projection

source

pub const fn as_matrix(&self) -> &Matrix4

Returns the projection matrix.

source

pub const fn as_mat4(&self) -> &Mat4

Returns the inverse of the projection matrix.

source

pub const fn as_ptr(&self) -> *const f32

Returns a pointer to the projection matrix.

Methods from Deref<Target = Mat4>§

source

pub const COLS: usize = 4usize

source

pub const ROWS: usize = 4usize

source

pub fn as_slice(&self) -> &[f32]

Returns this Mat4 as a slice of f32.

source

pub fn as_ptr(&self) -> *const f32

Returns this vector as a ptr of f32.

source

pub fn as_array_slice(&self) -> &[[f32; 4]]

Returns this Mat4 as a slice of 4-component arrays of f32.

source

pub fn as_array_ref(&self) -> &[[f32; 4]; 4]

Returns this Mat4 as a reference to a 4x4 array of f32.

source

pub fn to_matrix4(&self) -> Matrix4

Returns this Mat4 as a Matrix4.

This function is const, unlike the equivalent From or ToOwned implementations.

source

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

Returns the row at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the row to return.
source

pub unsafe fn row_unchecked(&self, index: usize) -> &Vec4

Returns the row at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the row to return.
source

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

Returns the column at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the column to return.
source

pub unsafe fn col_unchecked(&self, index: usize) -> &Col4

Returns the column at the given index without performing bounds checking.

Note: Unlike Mat4::row_unchecked, this function returns an owning Vector4 instead of a reference of Vec4.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the column to return.
source

pub fn get(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row.

This function will panic if the given index is out of bounds.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub unsafe fn get_unchecked(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

source

pub fn trace(&self) -> f32

Returns the trace of the matrix.

source

pub fn transposed(&self) -> Matrix4

Returns the transpose of the matrix.

source

pub fn inverted(&self) -> Matrix4

Returns the inverse of the matrix.

source

pub fn mul_mat4(&self, other: &Mat4) -> Matrix4

Combines this matrix with another matrix by performing matrix multiplication.

§Parameters
  • other - The matrix to combine with.
source

pub fn mul_col_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a column vector, returning the resultant vector.

This implements matrix-vector of:

| a b c d |   | x |   | ax + by + cz + dw |
| e f g h | * | y | = | ex + fy + gz + hw |
| i j k l |   | z |   | ix + jy + kz + lw |
| m n o p |   | w |   | mx + ny + oz + pw |
§Parameters
  • vec - The vector to combine with.
source

pub fn mul_row_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a row vector, returning the resultant vector.

This implements vector-matrix multiplication of:

| x y z w |   | a b c d |   | ax + ey + iz + mw |
            * | e f g h | = | bx + fy + jz + nw |
              | i j k l |   | cx + gy + kz + ow |
              | m n o p |   | dx + hy + lz + pw |

Trait Implementations§

source§

impl AsRef<Mat4> for Projection

source§

fn as_ref(&self) -> &Mat4

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Default for Projection

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Deref for Projection

source§

type Target = Mat4

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

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> 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, 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.