2018-10-22 13:00:10 +08:00
|
|
|
#![cfg_attr(rustfmt, rustfmt_skip)]
|
|
|
|
|
2018-09-23 20:41:56 +08:00
|
|
|
use na::{Scalar, Real, U2, U3, U4};
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
|
2018-09-23 20:41:56 +08:00
|
|
|
TMat4, TMat4x2, TMat4x3};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
|
|
|
|
/// Creates a new 1D vector.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// # Examples:
|
|
|
|
///
|
|
|
|
/// Construct a vector of `bool`s:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// # use nalgebra_glm as glm;
|
|
|
|
/// let v = glm::vec1(true);
|
|
|
|
/// ```
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn vec1<N: Scalar>(x: N) -> TVec1<N> {
|
|
|
|
TVec1::new(x)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Creates a new 2D vector.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn vec2<N: Scalar>(x: N, y: N) -> TVec2<N> {
|
|
|
|
TVec2::new(x, y)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Creates a new 3D vector.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn vec3<N: Scalar>(x: N, y: N, z: N) -> TVec3<N> {
|
|
|
|
TVec3::new(x, y, z)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Creates a new 4D vector.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
|
|
|
|
TVec4::new(x, y, z, w)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 2x2 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat2<N: Scalar>(m11: N, m12: N,
|
|
|
|
m21: N, m22: N) -> TMat2<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U2, U2>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12,
|
|
|
|
m21, m22,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 2x2 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat2x2<N: Scalar>(m11: N, m12: N,
|
|
|
|
m21: N, m22: N) -> TMat2<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U2, U2>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12,
|
|
|
|
m21, m22,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 2x3 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N,
|
|
|
|
m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U2, U3>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13,
|
|
|
|
m21, m22, m23,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 2x4 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
|
|
|
m21: N, m22: N, m23: N, m24: N) -> TMat2x4<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U2, U4>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13, m14,
|
|
|
|
m21, m22, m23, m24,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 3x3 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N,
|
|
|
|
m21: N, m22: N, m23: N,
|
|
|
|
m31: N, m32: N, m33: N) -> TMat3<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U3, U3>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13,
|
|
|
|
m21, m22, m23,
|
|
|
|
m31, m32, m33,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 3x2 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat3x2<N: Scalar>(m11: N, m12: N,
|
|
|
|
m21: N, m22: N,
|
|
|
|
m31: N, m32: N) -> TMat3x2<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U3, U2>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12,
|
|
|
|
m21, m22,
|
|
|
|
m31, m32,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 3x3 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N,
|
|
|
|
m21: N, m22: N, m23: N,
|
|
|
|
m31: N, m32: N, m33: N) -> TMat3<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U3, U3>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13,
|
|
|
|
m31, m32, m33,
|
|
|
|
m21, m22, m23,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 3x4 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
|
|
|
m21: N, m22: N, m23: N, m24: N,
|
|
|
|
m31: N, m32: N, m33: N, m34: N) -> TMat3x4<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U3, U4>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13, m14,
|
|
|
|
m21, m22, m23, m24,
|
|
|
|
m31, m32, m33, m34,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 4x2 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat4x2<N: Scalar>(m11: N, m12: N,
|
|
|
|
m21: N, m22: N,
|
|
|
|
m31: N, m32: N,
|
|
|
|
m41: N, m42: N) -> TMat4x2<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U4, U2>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12,
|
|
|
|
m21, m22,
|
|
|
|
m31, m32,
|
|
|
|
m41, m42,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 4x3 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N,
|
|
|
|
m21: N, m22: N, m23: N,
|
|
|
|
m31: N, m32: N, m33: N,
|
|
|
|
m41: N, m42: N, m43: N) -> TMat4x3<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U4, U3>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13,
|
|
|
|
m21, m22, m23,
|
|
|
|
m31, m32, m33,
|
|
|
|
m41, m42, m43,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 4x4 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
|
|
|
m21: N, m22: N, m23: N, m24: N,
|
|
|
|
m31: N, m32: N, m33: N, m34: N,
|
|
|
|
m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U4, U4>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13, m14,
|
|
|
|
m21, m22, m23, m24,
|
|
|
|
m31, m32, m33, m34,
|
|
|
|
m41, m42, m43, m44,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Create a new 4x4 matrix.
|
2018-10-22 13:00:10 +08:00
|
|
|
pub fn mat4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
|
|
|
m21: N, m22: N, m23: N, m24: N,
|
|
|
|
m31: N, m32: N, m33: N, m34: N,
|
|
|
|
m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
2018-09-23 20:48:45 +08:00
|
|
|
TMat::<N, U4, U4>::new(
|
2018-09-20 16:50:34 +08:00
|
|
|
m11, m12, m13, m14,
|
|
|
|
m21, m22, m23, m24,
|
|
|
|
m31, m32, m33, m34,
|
|
|
|
m41, m42, m43, m44,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Creates a new quaternion.
|
2018-09-20 16:50:34 +08:00
|
|
|
pub fn quat<N: Real>(x: N, y: N, z: N, w: N) -> Qua<N> {
|
2018-09-23 21:59:24 +08:00
|
|
|
Qua::new(w, x, y, z)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|