nalgebra/nalgebra-glm/src/constructors.rs

185 lines
4.5 KiB
Rust
Raw Normal View History

use crate::aliases::{
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
TVec2, TVec3, TVec4,
};
2021-08-08 18:59:40 +08:00
use crate::RealNumber;
use na::Scalar;
/// Creates a new 1D vector.
///
/// # Examples:
///
/// Construct a vector of `bool`s:
///
/// ```
/// # use nalgebra_glm as glm;
/// let v = glm::vec1(true);
/// ```
2021-04-11 17:00:38 +08:00
pub fn vec1<T: Scalar>(x: T) -> TVec1<T> {
2018-09-23 20:41:56 +08:00
TVec1::new(x)
}
/// Creates a new 2D vector.
2021-04-11 17:00:38 +08:00
pub fn vec2<T: Scalar>(x: T, y: T) -> TVec2<T> {
2018-09-23 20:41:56 +08:00
TVec2::new(x, y)
}
/// Creates a new 3D vector.
2021-04-11 17:00:38 +08:00
pub fn vec3<T: Scalar>(x: T, y: T, z: T) -> TVec3<T> {
2018-09-23 20:41:56 +08:00
TVec3::new(x, y, z)
}
/// Creates a new 4D vector.
2021-04-11 17:00:38 +08:00
pub fn vec4<T: Scalar>(x: T, y: T, z: T, w: T) -> TVec4<T> {
2018-09-23 20:41:56 +08:00
TVec4::new(x, y, z, w)
}
/// Create a new 2x2 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T) -> TMat2<T> {
TMat::<T, 2, 2>::new(
m11, m12,
m21, m22,
)
}
/// Create a new 2x2 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat2x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T) -> TMat2<T> {
TMat::<T, 2, 2>::new(
m11, m12,
m21, m22,
)
}
/// Create a new 2x3 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat2x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T) -> TMat2x3<T> {
TMat::<T, 2, 3>::new(
m11, m12, m13,
m21, m22, m23,
)
}
/// Create a new 2x4 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat2x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T) -> TMat2x4<T> {
TMat::<T, 2, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
)
}
/// Create a new 3x3 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T) -> TMat3<T> {
TMat::<T, 3, 3>::new(
m11, m12, m13,
m21, m22, m23,
m31, m32, m33,
)
}
/// Create a new 3x2 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat3x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T,
m31: T, m32: T) -> TMat3x2<T> {
TMat::<T, 3, 2>::new(
m11, m12,
m21, m22,
m31, m32,
)
}
/// Create a new 3x3 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat3x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T) -> TMat3<T> {
TMat::<T, 3, 3>::new(
m11, m12, m13,
m31, m32, m33,
m21, m22, m23,
)
}
/// Create a new 3x4 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat3x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T) -> TMat3x4<T> {
TMat::<T, 3, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
)
}
/// Create a new 4x2 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat4x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T,
m31: T, m32: T,
m41: T, m42: T) -> TMat4x2<T> {
TMat::<T, 4, 2>::new(
m11, m12,
m21, m22,
m31, m32,
m41, m42,
)
}
/// Create a new 4x3 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat4x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T,
m41: T, m42: T, m43: T) -> TMat4x3<T> {
TMat::<T, 4, 3>::new(
m11, m12, m13,
m21, m22, m23,
m31, m32, m33,
m41, m42, m43,
)
}
/// Create a new 4x4 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat4x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) -> TMat4<T> {
TMat::<T, 4, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44,
)
}
/// Create a new 4x4 matrix.
#[rustfmt::skip]
2021-04-11 17:00:38 +08:00
pub fn mat4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) -> TMat4<T> {
TMat::<T, 4, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44,
)
}
/// Creates a new quaternion.
2021-08-08 18:59:40 +08:00
pub fn quat<T: RealNumber>(x: T, y: T, z: T, w: T) -> Qua<T> {
2018-09-23 21:59:24 +08:00
Qua::new(w, x, y, z)
}