forked from M-Labs/nalgebra
Add more see also content.
This commit is contained in:
parent
8b0918ff1f
commit
e7610196b6
@ -26,6 +26,14 @@ pub fn pick_matrix<N: Real>(center: &TVec2<N>, delta: &TVec2<N>, viewport: &TVec
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project_no`](fn.project_no.html)
|
||||
/// * [`project_zo`](fn.project_zo.html)
|
||||
/// * [`unproject`](fn.unproject.html)
|
||||
/// * [`unproject_no`](fn.unproject_no.html)
|
||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||
pub fn project<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
project_no(obj, model, proj, viewport)
|
||||
}
|
||||
@ -39,6 +47,14 @@ pub fn project<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewp
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project`](fn.project.html)
|
||||
/// * [`project_zo`](fn.project_zo.html)
|
||||
/// * [`unproject`](fn.unproject.html)
|
||||
/// * [`unproject_no`](fn.unproject_no.html)
|
||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||
pub fn project_no<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
let proj = project_zo(obj, model, proj, viewport);
|
||||
TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
|
||||
@ -53,6 +69,14 @@ pub fn project_no<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vi
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project`](fn.project.html)
|
||||
/// * [`project_no`](fn.project_no.html)
|
||||
/// * [`unproject`](fn.unproject.html)
|
||||
/// * [`unproject_no`](fn.unproject_no.html)
|
||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||
pub fn project_zo<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
|
||||
let scale = N::one() / normalized.w;
|
||||
@ -71,6 +95,14 @@ pub fn project_zo<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vi
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project`](fn.project.html)
|
||||
/// * [`project_no`](fn.project_no.html)
|
||||
/// * [`project_zo`](fn.project_zo.html)
|
||||
/// * [`unproject_no`](fn.unproject_no.html)
|
||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||
pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
unproject_no(win, model, proj, viewport)
|
||||
}
|
||||
@ -84,6 +116,14 @@ pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vie
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project`](fn.project.html)
|
||||
/// * [`project_no`](fn.project_no.html)
|
||||
/// * [`project_zo`](fn.project_zo.html)
|
||||
/// * [`unproject`](fn.unproject.html)
|
||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||
pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
let _2: N = na::convert(2.0);
|
||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||
@ -107,6 +147,14 @@ pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>,
|
||||
/// * `model` - Specifies the current modelview matrix.
|
||||
/// * `proj` - Specifies the current projection matrix.
|
||||
/// * `viewport` - Specifies the current viewport.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`project`](fn.project.html)
|
||||
/// * [`project_no`](fn.project_no.html)
|
||||
/// * [`project_zo`](fn.project_zo.html)
|
||||
/// * [`unproject`](fn.unproject.html)
|
||||
/// * [`unproject_no`](fn.unproject_no.html)
|
||||
pub fn unproject_zo<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
||||
let _2: N = na::convert(2.0);
|
||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||
|
@ -15,6 +15,11 @@ pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
|
||||
/// * `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<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||
look_at_rh(eye, center, up)
|
||||
}
|
||||
@ -25,6 +30,11 @@ pub fn look_at<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMa
|
||||
/// * `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<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||
TMat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
|
||||
}
|
||||
@ -35,6 +45,11 @@ pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) ->
|
||||
/// * `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<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||
TMat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
|
||||
}
|
||||
@ -45,6 +60,14 @@ pub fn look_at_rh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) ->
|
||||
/// * `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<N: Real>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
|
||||
m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous()
|
||||
}
|
||||
@ -54,6 +77,14 @@ pub fn rotate<N: Real>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
|
||||
/// # 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<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &TVec::x())
|
||||
}
|
||||
@ -63,6 +94,14 @@ pub fn rotate_x<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
/// # 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<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &TVec::y())
|
||||
}
|
||||
@ -72,6 +111,14 @@ pub fn rotate_y<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
/// # 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<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &TVec::z())
|
||||
}
|
||||
@ -81,6 +128,14 @@ pub fn rotate_z<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
/// # 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<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
|
||||
m.prepend_nonuniform_scaling(v)
|
||||
}
|
||||
@ -90,6 +145,14 @@ pub fn scale<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
|
||||
/// # 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<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
|
||||
m.prepend_translation(v)
|
||||
}
|
||||
|
@ -4,24 +4,48 @@ use traits::{Alloc, Number, Dimension};
|
||||
use aliases::TVec;
|
||||
|
||||
/// Component-wise approximate equality of two vectors, using a scalar epsilon.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||
pub fn equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Component-wise approximate equality of two vectors, using a per-component epsilon.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`equal_eps`](fn.equal_eps.html)
|
||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||
pub fn equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps))
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality of two vectors, using a scalar epsilon.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`equal_eps`](fn.equal_eps.html)
|
||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||
pub fn not_equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality of two vectors, using a per-component epsilon.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`equal_eps`](fn.equal_eps.html)
|
||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||
pub fn not_equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_ne!(x, y, epsilon = eps))
|
||||
|
@ -2,11 +2,19 @@ use traits::Number;
|
||||
use aliases::TVec3;
|
||||
|
||||
/// Returns `true` if `{a, b, c}` forms a left-handed trihedron.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`right_handed`](fn.right_handed.html)
|
||||
pub fn left_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
|
||||
a.cross(b).dot(c) < N::zero()
|
||||
}
|
||||
|
||||
/// Returns `true` if `{a, b, c}` forms a right-handed trihedron.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`left_handed`](fn.left_handed.html)
|
||||
pub fn right_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
|
||||
a.cross(b).dot(c) > N::zero()
|
||||
}
|
||||
|
@ -3,11 +3,19 @@ use na::Real;
|
||||
use aliases::{TMat3, TMat4, TVec3};
|
||||
|
||||
/// Builds a 3x3 matrix `m` such that for any `v`: `m * v == cross(x, v)`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`matrix_cross`](fn.matrix_cross.html)
|
||||
pub fn matrix_cross3<N: Real>(x: &TVec3<N>) -> TMat3<N> {
|
||||
x.cross_matrix()
|
||||
}
|
||||
|
||||
/// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`matrix_cross3`](fn.matrix_cross3.html)
|
||||
pub fn matrix_cross<N: Real>(x: &TVec3<N>) -> TMat4<N> {
|
||||
::mat3_to_mat4(&x.cross_matrix())
|
||||
}
|
||||
|
@ -2,46 +2,145 @@ use traits::Number;
|
||||
use aliases::{TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3};
|
||||
|
||||
/// Builds a 2x2 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal2x2<N: Number>(v: &TVec2<N>) -> TMat2<N> {
|
||||
TMat2::from_diagonal(v)
|
||||
}
|
||||
|
||||
/// Builds a 2x3 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal2x3<N: Number>(v: &TVec2<N>) -> TMat2x3<N> {
|
||||
TMat2x3::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 2x4 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal2x4<N: Number>(v: &TVec2<N>) -> TMat2x4<N> {
|
||||
TMat2x4::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 3x2 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal3x2<N: Number>(v: &TVec2<N>) -> TMat3x2<N> {
|
||||
TMat3x2::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 3x3 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal3x3<N: Number>(v: &TVec3<N>) -> TMat3<N> {
|
||||
TMat3::from_diagonal(v)
|
||||
}
|
||||
|
||||
/// Builds a 3x4 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal3x4<N: Number>(v: &TVec3<N>) -> TMat3x4<N> {
|
||||
TMat3x4::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 4x2 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal4x2<N: Number>(v: &TVec2<N>) -> TMat4x2<N> {
|
||||
TMat4x2::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 4x3 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x4`](fn.diagonal4x4.html)
|
||||
pub fn diagonal4x3<N: Number>(v: &TVec3<N>) -> TMat4x3<N> {
|
||||
TMat4x3::from_partial_diagonal(v.as_slice())
|
||||
}
|
||||
|
||||
/// Builds a 4x4 diagonal matrix.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`diagonal2x2`](fn.diagonal2x2.html)
|
||||
/// * [`diagonal2x3`](fn.diagonal2x3.html)
|
||||
/// * [`diagonal2x4`](fn.diagonal2x4.html)
|
||||
/// * [`diagonal3x2`](fn.diagonal3x2.html)
|
||||
/// * [`diagonal3x3`](fn.diagonal3x3.html)
|
||||
/// * [`diagonal3x4`](fn.diagonal3x4.html)
|
||||
/// * [`diagonal4x2`](fn.diagonal4x2.html)
|
||||
/// * [`diagonal4x3`](fn.diagonal4x3.html)
|
||||
pub fn diagonal4x4<N: Number>(v: &TVec4<N>) -> TMat4<N> {
|
||||
TMat4::from_diagonal(v)
|
||||
}
|
||||
|
@ -4,6 +4,12 @@ use traits::{Dimension, Alloc};
|
||||
use aliases::TVec;
|
||||
|
||||
/// The dot product of the normalized version of `x` and `y`.
|
||||
///
|
||||
/// This is currently the same as [`normalize_dot`](fn.normalize_dot.html).
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`normalize_dot`](fn.normalize_dot.html`)
|
||||
pub fn fast_normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
@ -11,8 +17,12 @@ pub fn fast_normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>)
|
||||
}
|
||||
|
||||
/// The dot product of the normalized version of `x` and `y`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`)
|
||||
pub fn normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
x.normalize().dot(&y.normalize())
|
||||
}
|
||||
}
|
||||
|
@ -4,32 +4,80 @@ use traits::Number;
|
||||
use aliases::{TVec3, TVec2, TMat3, TMat4};
|
||||
|
||||
/// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`scaling`](fn.scaling.html)
|
||||
/// * [`translation`](fn.translation.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn rotation<N: Real>(angle: N, v: &TVec3<N>) -> TMat4<N> {
|
||||
Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous()
|
||||
}
|
||||
|
||||
/// A 4 * 4 scale matrix created from a vector of 3 components.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation`](fn.rotation.html)
|
||||
/// * [`translation`](fn.translation.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn scaling<N: Number>(v: &TVec3<N>) -> TMat4<N> {
|
||||
TMat4::new_nonuniform_scaling(v)
|
||||
}
|
||||
|
||||
/// A 4 * 4 translation matrix created from the scaling factor on each axis.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation`](fn.rotation.html)
|
||||
/// * [`scaling`](fn.scaling.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
|
||||
TMat4::new_translation(v)
|
||||
}
|
||||
|
||||
|
||||
/// A rotation 3 * 3 matrix created from an angle expressed in radians.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation`](fn.rotation.html)
|
||||
/// * [`scaling`](fn.scaling.html)
|
||||
/// * [`translation`](fn.translation.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn rotation2d<N: Real>(angle: N) -> TMat3<N> {
|
||||
Rotation2::new(angle).to_homogeneous()
|
||||
}
|
||||
|
||||
/// A 3 * 3 scale matrix created from a vector of 2 components.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation`](fn.rotation.html)
|
||||
/// * [`scaling`](fn.scaling.html)
|
||||
/// * [`translation`](fn.translation.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn scaling2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
|
||||
TMat3::new_nonuniform_scaling(v)
|
||||
}
|
||||
|
||||
/// A 3 * 3 translation matrix created from the scaling factor on each axis.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation`](fn.rotation.html)
|
||||
/// * [`scaling`](fn.scaling.html)
|
||||
/// * [`translation`](fn.translation.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
pub fn translation2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
|
||||
TMat3::new_translation(v)
|
||||
}
|
||||
|
@ -4,16 +4,40 @@ use traits::Number;
|
||||
use aliases::{TMat3, TVec2};
|
||||
|
||||
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scale2d`](fn.scale2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translate2d`](fn.translate2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn rotate2d<N: Real>(m: &TMat3<N>, angle: N) -> TMat3<N> {
|
||||
m * UnitComplex::new(angle).to_homogeneous()
|
||||
}
|
||||
|
||||
/// Builds a 2D scaling matrix and right-multiply it to `m`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotate2d`](fn.rotate2d.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translate2d`](fn.translate2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn scale2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
|
||||
m.prepend_nonuniform_scaling(v)
|
||||
}
|
||||
|
||||
/// Builds a translation matrix and right-multiply it to `m`.
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`rotate2d`](fn.rotate2d.html)
|
||||
/// * [`rotation2d`](fn.rotation2d.html)
|
||||
/// * [`scale2d`](fn.scale2d.html)
|
||||
/// * [`scaling2d`](fn.scaling2d.html)
|
||||
/// * [`translation2d`](fn.translation2d.html)
|
||||
pub fn translate2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
|
||||
m.prepend_translation(v)
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,19 @@ use traits::{Number, Dimension, Alloc};
|
||||
use aliases::{TVec, TVec2, TVec3};
|
||||
|
||||
/// Returns `true` if two vectors are collinear (up to an epsilon).
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`are_collinear2d`](fn.are_collinear2d.html)
|
||||
pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> bool {
|
||||
is_null(&v0.cross(v1), epsilon)
|
||||
}
|
||||
|
||||
/// Returns `true` if two 2D vectors are collinear (up to an epsilon).
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`are_collinear`](fn.are_collinear.html)
|
||||
pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> bool {
|
||||
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user