use na::{DefaultAllocator, Real, Unit, Rotation3, Point3}; use traits::{Dimension, Number, Alloc}; use aliases::{TMat, TVec, TVec3, TMat4}; /// The identity matrix. pub fn identity() -> TMat where DefaultAllocator: Alloc { TMat::::identity() } /// Build a look at view matrix based on the right handedness. /// /// # Parameters /// * `eye` − Position of the camera /// * `center` − Position where the camera is looking at /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// /// # See also: /// /// * [`look_at_lh`](fn.look_at_lh.html) /// * [`look_at_rh`](fn.look_at_rh.html) pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { look_at_rh(eye, center, up) } /// Build a left handed look at view matrix. /// /// # Parameters /// * `eye` − Position of the camera /// * `center` − Position where the camera is looking at /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// /// # See also: /// /// * [`look_at`](fn.look_at.html) /// * [`look_at_rh`](fn.look_at_rh.html) pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) } /// Build a right handed look at view matrix. /// /// # Parameters /// * `eye` − Position of the camera /// * `center` − Position where the camera is looking at /// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)` /// /// # See also: /// /// * [`look_at`](fn.look_at.html) /// * [`look_at_lh`](fn.look_at_lh.html) pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) } /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this rotation matrix. /// * `angle` − Rotation angle expressed in radians. /// * `axis` − Rotation axis, recommended to be normalized. /// /// # See also: /// /// * [`rotate_x`](fn.rotate_x.html) /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) pub fn rotate(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous() } /// Builds a rotation 4 * 4 matrix around the X axis and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this rotation matrix. /// * `angle` − Rotation angle expressed in radians. /// /// # See also: /// /// * [`rotate`](fn.rotate.html) /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) pub fn rotate_x(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &TVec::x()) } /// Builds a rotation 4 * 4 matrix around the Y axis and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this rotation matrix. /// * `angle` − Rotation angle expressed in radians. /// /// # See also: /// /// * [`rotate`](fn.rotate.html) /// * [`rotate_x`](fn.rotate_x.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) pub fn rotate_y(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &TVec::y()) } /// Builds a rotation 4 * 4 matrix around the Z axis and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this rotation matrix. /// * `angle` − Rotation angle expressed in radians. /// /// # See also: /// /// * [`rotate`](fn.rotate.html) /// * [`rotate_x`](fn.rotate_x.html) /// * [`rotate_y`](fn.rotate_y.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) pub fn rotate_z(m: &TMat4, angle: N) -> TMat4 { rotate(m, angle, &TVec::z()) } /// Builds a scale 4 * 4 matrix created from 3 scalars and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this scale matrix. /// * `v` − Ratio of scaling for each axis. /// /// # See also: /// /// * [`rotate`](fn.rotate.html) /// * [`rotate_x`](fn.rotate_x.html) /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`translate`](fn.translate.html) pub fn scale(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_nonuniform_scaling(v) } /// Builds a translation 4 * 4 matrix created from a vector of 3 components and right-multiply it to `m`. /// /// # Parameters /// * `m` − Input matrix multiplied by this translation matrix. /// * `v` − Coordinates of a translation vector. /// /// # See also: /// /// * [`rotate`](fn.rotate.html) /// * [`rotate_x`](fn.rotate_x.html) /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) pub fn translate(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_translation(v) }