2012-11-26 12:45:55 +00:00
|
|
|
|
/***
|
|
|
|
|
* This module contains various type aliases and method wrappers to make working
|
|
|
|
|
* with OpenGL cleaner and safer than working with the lmath types directly.
|
|
|
|
|
* This is especially important when working with type-sensitive OpenGL functions
|
|
|
|
|
* such as `glVertexAttribPointer` and `glUniformMatrix4fv`) where a simple mistake
|
|
|
|
|
* such writing `Vec3::new(1, 2, 3)` or `Vec3::new(1f, 2f, 3f)` as opposed to
|
|
|
|
|
* `Vec3::new(1f32, 2f32, 3f32)` could cause you an afternoon of pain.
|
|
|
|
|
*
|
|
|
|
|
* To give you an example of how using the wrapper methods can clean up your
|
|
|
|
|
* code and make debugging far easier, instead of writing:
|
|
|
|
|
*
|
|
|
|
|
* ~~~
|
|
|
|
|
* let v: Mat4<f64> = NumericMatrixNxN::identity();
|
|
|
|
|
* ~~~
|
|
|
|
|
*
|
|
|
|
|
* you can write:
|
|
|
|
|
*
|
|
|
|
|
* ~~~
|
|
|
|
|
* let v = dmat4::identity();
|
|
|
|
|
* ~~~
|
|
|
|
|
*/
|
2012-11-21 04:52:16 +00:00
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
use core::sys::size_of;
|
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
use vec::{
|
2013-01-27 23:33:02 +00:00
|
|
|
|
Vec2,
|
|
|
|
|
Vec3,
|
|
|
|
|
Vec4,
|
2013-01-27 22:50:49 +00:00
|
|
|
|
Vector,
|
2013-01-27 23:33:02 +00:00
|
|
|
|
Vector2,
|
|
|
|
|
Vector3,
|
|
|
|
|
Vector4,
|
2013-01-27 22:50:49 +00:00
|
|
|
|
NumericVector,
|
|
|
|
|
NumericVector2,
|
|
|
|
|
NumericVector3,
|
|
|
|
|
NumericVector4,
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
use mat::{Matrix, Mat2, Mat3, Mat4};
|
2013-01-27 23:03:46 +00:00
|
|
|
|
use quat::Quat;
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
2013-01-27 22:22:15 +00:00
|
|
|
|
use numeric::*;
|
|
|
|
|
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
2012-11-26 12:45:55 +00:00
|
|
|
|
// Vector aliases, corresponding to Section 4.1.5 of the [GLSL 4.30.6 specification]
|
|
|
|
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
|
|
|
|
pub type vec2 = Vec2<f32>; /// a two-component single-precision floating-point vector
|
|
|
|
|
pub type vec3 = Vec3<f32>; /// a three-component single-precision floating-point vector
|
|
|
|
|
pub type vec4 = Vec4<f32>; /// a four-component single-precision floating-point vector
|
|
|
|
|
|
|
|
|
|
pub type dvec2 = Vec2<f64>; /// a two-component double-precision floating-point vector
|
|
|
|
|
pub type dvec3 = Vec3<f64>; /// a three-component double-precision floating-point vector
|
|
|
|
|
pub type dvec4 = Vec4<f64>; /// a four-component double-precision floating-point vector
|
|
|
|
|
|
2012-12-03 01:24:24 +00:00
|
|
|
|
pub type bvec2 = Vec2<bool>; /// a two-component Boolean vector
|
|
|
|
|
pub type bvec3 = Vec3<bool>; /// a three-component Boolean vector
|
|
|
|
|
pub type bvec4 = Vec4<bool>; /// a four-component Boolean vector
|
|
|
|
|
|
2012-11-16 06:21:44 +00:00
|
|
|
|
pub type ivec2 = Vec2<i32>; /// a two-component signed integer vector
|
|
|
|
|
pub type ivec3 = Vec3<i32>; /// a three-component signed integer vector
|
|
|
|
|
pub type ivec4 = Vec4<i32>; /// a four-component signed integer vector
|
|
|
|
|
|
|
|
|
|
pub type uvec2 = Vec2<u32>; /// a two-component unsigned integer vector
|
|
|
|
|
pub type uvec3 = Vec3<u32>; /// a three-component unsigned integer vector
|
|
|
|
|
pub type uvec4 = Vec4<u32>; /// a four-component unsigned integer vector
|
|
|
|
|
|
|
|
|
|
|
2012-11-21 05:07:57 +00:00
|
|
|
|
// Vector method wrappers
|
2012-11-20 06:57:32 +00:00
|
|
|
|
|
2012-11-20 07:58:24 +00:00
|
|
|
|
pub impl vec2 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
|
|
|
|
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> vec2 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-20 07:58:24 +00:00
|
|
|
|
pub impl vec3 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
|
|
|
|
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> vec3 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> vec3 { NumericVector3::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> vec3 { NumericVector3::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> vec3 { NumericVector3::unit_z() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-20 07:58:24 +00:00
|
|
|
|
pub impl vec4 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
|
|
|
|
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> vec4 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> vec4 { NumericVector4::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> vec4 { NumericVector4::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> vec4 { NumericVector4::unit_z() }
|
|
|
|
|
#[inline(always)] static pure fn unit_w() -> vec4 { NumericVector4::unit_w() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub impl dvec2 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> dvec2 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl dvec3 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> dvec3 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> dvec3 { NumericVector3::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> dvec3 { NumericVector3::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> dvec3 { NumericVector3::unit_z() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl dvec4 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> dvec4 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> dvec4 { NumericVector4::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> dvec4 { NumericVector4::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> dvec4 { NumericVector4::unit_z() }
|
|
|
|
|
#[inline(always)] static pure fn unit_w() -> dvec4 { NumericVector4::unit_w() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
2012-12-03 01:24:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub impl bvec2 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
2012-12-03 01:24:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: bool) -> bvec2 { Vector::from_value(v) }
|
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec2>() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl bvec3 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
2012-12-03 01:24:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: bool) -> bvec3 { Vector::from_value(v) }
|
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec3>() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl bvec4 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
2012-12-03 01:24:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: bool) -> bvec4 { Vector::from_value(v) }
|
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec4>() }
|
|
|
|
|
}
|
2012-11-20 06:57:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub impl ivec2 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> ivec2 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl ivec3 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> ivec3 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> ivec3 { NumericVector3::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> ivec3 { NumericVector3::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> ivec3 { NumericVector3::unit_z() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl ivec4 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> ivec4 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> ivec4 { NumericVector4::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> ivec4 { NumericVector4::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> ivec4 { NumericVector4::unit_z() }
|
|
|
|
|
#[inline(always)] static pure fn unit_w() -> ivec4 { NumericVector4::unit_w() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub impl uvec2 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> uvec2 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec2>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl uvec3 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> uvec3 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> uvec3 { NumericVector3::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> uvec3 { NumericVector3::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> uvec3 { NumericVector3::unit_z() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec3>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub impl uvec4 {
|
2013-01-27 23:33:02 +00:00
|
|
|
|
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
2012-11-20 07:58:24 +00:00
|
|
|
|
#[inline(always)] static pure fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
2012-11-20 09:09:33 +00:00
|
|
|
|
#[inline(always)] static pure fn zero() -> uvec4 { NumericVector::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-27 22:50:49 +00:00
|
|
|
|
#[inline(always)] static pure fn unit_x() -> uvec4 { NumericVector4::unit_x() }
|
|
|
|
|
#[inline(always)] static pure fn unit_y() -> uvec4 { NumericVector4::unit_y() }
|
|
|
|
|
#[inline(always)] static pure fn unit_z() -> uvec4 { NumericVector4::unit_z() }
|
|
|
|
|
#[inline(always)] static pure fn unit_w() -> uvec4 { NumericVector4::unit_w() }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 12:45:55 +00:00
|
|
|
|
// Matrix aliases, corresponding to Section 4.1.6 of the [GLSL 4.30.6 specification]
|
|
|
|
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
pub type mat2 = Mat2<f32>; /// a 2×2 single-precision floating-point matrix
|
|
|
|
|
pub type mat3 = Mat3<f32>; /// a 3×3 single-precision floating-point matrix
|
|
|
|
|
pub type mat4 = Mat4<f32>; /// a 4×4 single-precision floating-point matrix
|
|
|
|
|
|
|
|
|
|
pub type dmat2 = Mat2<f64>; /// a 2×2 double-precision floating-point matrix
|
|
|
|
|
pub type dmat3 = Mat3<f64>; /// a 3×3 double-precision floating-point matrix
|
|
|
|
|
pub type dmat4 = Mat4<f64>; /// a 4×4 double-precision floating-point matrix
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
|
|
|
|
|
2012-11-21 05:07:57 +00:00
|
|
|
|
// Matrix method wrappers
|
2012-11-20 06:57:32 +00:00
|
|
|
|
|
2012-11-20 09:23:11 +00:00
|
|
|
|
pub impl mat2 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat2 { Mat2::from_cols(move c0, move c1) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Mat2::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> mat2 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-29 00:49:38 +00:00
|
|
|
|
#[inline(always)] static pure fn from_angle(radians: f32) -> mat2 { Mat2::from_angle(radians) }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 2 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
2012-11-20 09:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
pub impl mat3 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Mat3::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> mat3 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
2013-01-29 00:49:38 +00:00
|
|
|
|
#[inline(always)] static pure fn from_angle_x(radians: f32) -> mat3 { Mat3::from_angle_x(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_y(radians: f32) -> mat3 { Mat3::from_angle_y(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_z(radians: f32) -> mat3 { Mat3::from_angle_z(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32) -> mat3 { Mat3::from_angle_xyz(radians_x, radians_y, radians_z) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_axis(radians: f32, axis: &vec3) -> mat3 { Mat3::from_angle_axis(radians, axis) }
|
|
|
|
|
#[inline(always)] static pure fn from_axes(x: vec3, y: vec3, z: vec3) -> mat3 { Mat3::from_axes(x, y, z) }
|
|
|
|
|
#[inline(always)] static pure fn look_at(dir: &vec3, up: &vec3) -> mat3 { Mat3::look_at(dir, up) }
|
|
|
|
|
|
2012-11-25 13:32:52 +00:00
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 3 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat3>() }
|
2012-11-20 09:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
pub impl mat4 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> mat4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f32) -> mat4 { Mat4::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> mat4 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 4 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub impl dmat2 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat2 { Mat2::from_cols(move c0, move c1) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Mat2::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> dmat2 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 2 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 2 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat2>() }
|
2012-11-20 09:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
pub impl dmat3 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Mat3::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> dmat3 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 3 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 3 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat3>() }
|
2012-11-20 09:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-02 22:15:40 +00:00
|
|
|
|
pub impl dmat4 {
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
2012-11-20 12:27:17 +00:00
|
|
|
|
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
2012-12-02 22:15:40 +00:00
|
|
|
|
-> dmat4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
|
|
|
|
#[inline(always)] static pure fn from_value(v: f64) -> dmat4 { Mat4::from_value(v) }
|
2012-12-01 12:49:24 +00:00
|
|
|
|
|
2013-01-27 23:03:46 +00:00
|
|
|
|
#[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> dmat4 { Matrix::zero() }
|
2012-11-25 13:32:52 +00:00
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn dim() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn rows() -> uint { 4 }
|
|
|
|
|
#[inline(always)] static pure fn cols() -> uint { 4 }
|
2012-12-02 22:15:40 +00:00
|
|
|
|
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat4>() }
|
2012-11-20 06:57:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 23:55:51 +00:00
|
|
|
|
// Quaternion aliases. These are not present in the GLSL specification, but
|
|
|
|
|
// they follow roughly the same nomenclature.
|
2012-11-16 06:21:44 +00:00
|
|
|
|
|
2013-01-29 00:49:38 +00:00
|
|
|
|
pub type quat = Quat<f32>; /// a single-precision floating-point quaternion
|
|
|
|
|
pub type dquat = Quat<f64>; /// a double-precision floating-point quaternion
|
|
|
|
|
|
|
|
|
|
pub impl quat {
|
|
|
|
|
#[inline(always)] static pure fn new(w: f32, xi: f32, yj: f32, zk: f32) -> quat { Quat::new(w, xi, yj, zk) }
|
|
|
|
|
#[inline(always)] static pure fn from_sv(s: f32, v: vec3) -> quat { Quat::from_sv(s, v) }
|
|
|
|
|
#[inline(always)] static pure fn identity() -> quat { Quat::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> quat { Quat::zero() }
|
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn from_angle_x(radians: f32) -> quat { Quat::from_angle_x(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_y(radians: f32) -> quat { Quat::from_angle_y(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_z(radians: f32) -> quat { Quat::from_angle_z(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32)
|
|
|
|
|
-> quat { Quat::from_angle_xyz(radians_x, radians_y, radians_z) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_axis(radians: f32, axis: &vec3) -> quat { Quat::from_angle_axis(radians, axis) }
|
|
|
|
|
#[inline(always)] static pure fn from_axes(x: vec3, y: vec3, z: vec3) -> quat { Quat::from_axes(x, y, z) }
|
|
|
|
|
#[inline(always)] static pure fn look_at(dir: &vec3, up: &vec3) -> quat { Quat::look_at(dir, up) }
|
|
|
|
|
}
|
2012-11-30 12:47:40 +00:00
|
|
|
|
|
2013-01-29 00:49:38 +00:00
|
|
|
|
pub impl dquat {
|
|
|
|
|
#[inline(always)] static pure fn new(w: f64, xi: f64, yj: f64, zk: f64) -> dquat { Quat::new(w, xi, yj, zk) }
|
|
|
|
|
#[inline(always)] static pure fn from_sv(s: f64, v: dvec3) -> dquat { Quat::from_sv(s, v) }
|
|
|
|
|
#[inline(always)] static pure fn identity() -> dquat { Quat::identity() }
|
|
|
|
|
#[inline(always)] static pure fn zero() -> dquat { Quat::zero() }
|
|
|
|
|
|
|
|
|
|
#[inline(always)] static pure fn from_angle_x(radians: f64) -> dquat { Quat::from_angle_x(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_y(radians: f64) -> dquat { Quat::from_angle_y(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_z(radians: f64) -> dquat { Quat::from_angle_z(radians) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_xyz(radians_x: f64, radians_y: f64, radians_z: f64)
|
|
|
|
|
-> dquat { Quat::from_angle_xyz(radians_x, radians_y, radians_z) }
|
|
|
|
|
#[inline(always)] static pure fn from_angle_axis(radians: f64, axis: &dvec3) -> dquat { Quat::from_angle_axis(radians, axis) }
|
|
|
|
|
#[inline(always)] static pure fn from_axes(x: dvec3, y: dvec3, z: dvec3) -> dquat { Quat::from_axes(x, y, z) }
|
|
|
|
|
#[inline(always)] static pure fn look_at(dir: &dvec3, up: &dvec3) -> dquat { Quat::look_at(dir, up) }
|
|
|
|
|
}
|
2012-11-30 12:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
2012-11-16 06:53:53 +00:00
|
|
|
|
// prevents "error: expected item"
|
|
|
|
|
priv fn hack() {}
|