Move GLSL type aliases to vec, mat and quat mods
This commit is contained in:
parent
030af2a842
commit
0a4e19ba1e
12 changed files with 431 additions and 627 deletions
430
src/gltypes.rs
430
src/gltypes.rs
|
@ -1,430 +0,0 @@
|
|||
/***
|
||||
* 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();
|
||||
* ~~~
|
||||
*/
|
||||
|
||||
use core::sys::size_of;
|
||||
|
||||
use vec::{
|
||||
Vec2,
|
||||
Vec3,
|
||||
Vec4,
|
||||
Vector,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
NumericVector,
|
||||
NumericVector2,
|
||||
NumericVector3,
|
||||
NumericVector4,
|
||||
};
|
||||
|
||||
use mat::{Matrix, Mat2, Mat3, Mat4};
|
||||
use quat::Quat;
|
||||
|
||||
use numeric::*;
|
||||
|
||||
|
||||
// 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).
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
// Vector method wrappers
|
||||
|
||||
pub impl vec2 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
||||
}
|
||||
|
||||
pub impl vec3 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
||||
}
|
||||
|
||||
pub impl vec4 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl dvec2 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
||||
}
|
||||
|
||||
pub impl dvec3 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
||||
}
|
||||
|
||||
pub impl dvec4 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl bvec2 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
||||
#[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 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
||||
#[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 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
||||
#[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>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl ivec2 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
||||
}
|
||||
|
||||
pub impl ivec3 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
||||
}
|
||||
|
||||
pub impl ivec4 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl uvec2 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec2>() }
|
||||
}
|
||||
|
||||
pub impl uvec3 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec3>() }
|
||||
}
|
||||
|
||||
pub impl uvec4 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec4>() }
|
||||
}
|
||||
|
||||
|
||||
// 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).
|
||||
|
||||
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
|
||||
|
||||
|
||||
// Matrix method wrappers
|
||||
|
||||
pub impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
-> mat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Mat2::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle(radians: f32) -> mat2 { Mat2::from_angle(radians) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
||||
}
|
||||
|
||||
pub impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
-> mat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Mat3::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { Matrix::zero() }
|
||||
|
||||
#[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) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat3>() }
|
||||
}
|
||||
|
||||
pub impl mat4 {
|
||||
#[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)
|
||||
-> mat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
||||
-> 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) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
-> dmat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Mat2::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat2>() }
|
||||
}
|
||||
|
||||
pub impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
-> dmat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Mat3::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat3>() }
|
||||
}
|
||||
|
||||
pub impl dmat4 {
|
||||
#[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)
|
||||
-> dmat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
||||
-> 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) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat4>() }
|
||||
}
|
||||
|
||||
|
||||
// Quaternion aliases. These are not present in the GLSL specification, but
|
||||
// they follow roughly the same nomenclature.
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
|
||||
// prevents "error: expected item"
|
||||
priv fn hack() {}
|
|
@ -11,7 +11,6 @@
|
|||
extern mod std;
|
||||
extern mod numeric;
|
||||
|
||||
pub mod gltypes;
|
||||
pub mod mat;
|
||||
pub mod mat2;
|
||||
pub mod mat3;
|
||||
|
@ -27,7 +26,6 @@ pub mod projection;
|
|||
|
||||
#[test]
|
||||
mod test {
|
||||
mod test_gltypes;
|
||||
mod test_mat;
|
||||
mod test_quat;
|
||||
mod test_rot;
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::cmp::FuzzyEq;
|
|||
|
||||
use quat::Quat;
|
||||
|
||||
pub use mat2::Mat2;
|
||||
pub use mat3::Mat3;
|
||||
pub use mat4::Mat4;
|
||||
pub use mat2::{Mat2, mat2, dmat2};
|
||||
pub use mat3::{Mat3, mat3, dmat3};
|
||||
pub use mat4::{Mat4, mat4, dmat4};
|
||||
|
||||
/**
|
||||
* The base square matrix trait
|
||||
|
|
49
src/mat2.rs
49
src/mat2.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::Eq;
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::util::swap;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
|
@ -8,7 +9,11 @@ use std::cmp::FuzzyEq;
|
|||
use numeric::*;
|
||||
use numeric::number::Number::{zero,one};
|
||||
|
||||
use vec::Vec2;
|
||||
use vec::{
|
||||
Vec2,
|
||||
vec2,
|
||||
dvec2,
|
||||
};
|
||||
|
||||
use mat::{
|
||||
Mat3,
|
||||
|
@ -375,4 +380,46 @@ pub impl<T:Copy Float> Mat2<T>: FuzzyEq {
|
|||
self[0].fuzzy_eq(&other[0]) &&
|
||||
self[1].fuzzy_eq(&other[1])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type mat2 = Mat2<f32>; /// a 2×2 single-precision floating-point matrix
|
||||
pub type dmat2 = Mat2<f64>; /// a 2×2 double-precision floating-point matrix
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
-> mat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Mat2::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle(radians: f32) -> mat2 { Mat2::from_angle(radians) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
||||
}
|
||||
|
||||
pub impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
-> dmat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Mat2::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat2>() }
|
||||
}
|
57
src/mat3.rs
57
src/mat3.rs
|
@ -2,6 +2,7 @@ use core::cast::transmute;
|
|||
use core::cmp::Eq;
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::util::swap;
|
||||
use core::sys::size_of;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
|
@ -11,7 +12,12 @@ use numeric::number::Number::{zero,one};
|
|||
|
||||
use quat::Quat;
|
||||
use rot::Rotation;
|
||||
use vec::Vec3;
|
||||
|
||||
use vec::{
|
||||
Vec3,
|
||||
vec3,
|
||||
dvec3,
|
||||
};
|
||||
|
||||
use mat::{
|
||||
Mat4,
|
||||
|
@ -584,4 +590,53 @@ pub impl<T:Copy Float> Mat3<T>: FuzzyEq {
|
|||
self[1].fuzzy_eq(&other[1]) &&
|
||||
self[2].fuzzy_eq(&other[2])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type mat3 = Mat3<f32>; /// a 3×3 single-precision floating-point matrix
|
||||
pub type dmat3 = Mat3<f64>; /// a 3×3 double-precision floating-point matrix
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
-> mat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Mat3::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { Matrix::zero() }
|
||||
|
||||
#[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) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat3>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
-> dmat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Mat3::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat3>() }
|
||||
}
|
47
src/mat4.rs
47
src/mat4.rs
|
@ -2,13 +2,18 @@ use core::cast::transmute;
|
|||
use core::cmp::Eq;
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::util::swap;
|
||||
use core::sys::size_of;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
use numeric::*;
|
||||
use numeric::number::Number::{zero,one};
|
||||
|
||||
use vec::Vec4;
|
||||
use vec::{
|
||||
Vec4,
|
||||
vec4,
|
||||
dvec4,
|
||||
};
|
||||
|
||||
use mat::{
|
||||
Mat3,
|
||||
|
@ -514,4 +519,44 @@ pub impl<T:Copy Float> Mat4<T>: FuzzyEq {
|
|||
self[2].fuzzy_eq(&other[2]) &&
|
||||
self[3].fuzzy_eq(&other[3])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type mat4 = Mat4<f32>; /// a 4×4 single-precision floating-point matrix
|
||||
pub type dmat4 = Mat4<f64>; /// a 4×4 double-precision floating-point matrix
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat4 {
|
||||
#[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)
|
||||
-> mat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
||||
-> 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) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
||||
}
|
||||
|
||||
pub impl dmat4 {
|
||||
#[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)
|
||||
-> dmat4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
||||
-> 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) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat4>() }
|
||||
}
|
47
src/quat.rs
47
src/quat.rs
|
@ -19,7 +19,12 @@ use numeric::number::Number;
|
|||
use numeric::number::Number::{zero,one};
|
||||
|
||||
use mat::{Mat3, Mat4};
|
||||
use vec::Vec3;
|
||||
|
||||
use vec::{
|
||||
Vec3,
|
||||
vec3,
|
||||
dvec3,
|
||||
};
|
||||
|
||||
/**
|
||||
* A quaternion in scalar/vector form
|
||||
|
@ -424,3 +429,43 @@ pub impl<T:Copy FuzzyEq> Quat<T>: FuzzyEq {
|
|||
self[3].fuzzy_eq(&other[3])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type aliases for quaternions. These are not present in the GLSL
|
||||
// specification, but they roughly follow the same nomenclature.
|
||||
|
||||
pub type quat = Quat<f32>; /// a single-precision floating-point quaternion
|
||||
pub type dquat = Quat<f64>; /// a double-precision floating-point quaternion
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
use gltypes::*;
|
||||
|
||||
#[test]
|
||||
fn test_vec() {
|
||||
assert vec2::identity() == vec2::from_value(1f32);
|
||||
assert vec3::identity() == vec3::from_value(1f32);
|
||||
assert vec4::identity() == vec4::from_value(1f32);
|
||||
assert vec2::identity() == vec2::new(1f32, 1f32);
|
||||
assert vec3::identity() == vec3::new(1f32, 1f32, 1f32);
|
||||
assert vec4::identity() == vec4::new(1f32, 1f32, 1f32, 1f32);
|
||||
assert vec2::zero() == vec2::new(0f32, 0f32);
|
||||
assert vec3::zero() == vec3::new(0f32, 0f32, 0f32);
|
||||
assert vec4::zero() == vec4::new(0f32, 0f32, 0f32, 0f32);
|
||||
assert vec2::dim() == 2;
|
||||
assert vec3::dim() == 3;
|
||||
assert vec4::dim() == 4;
|
||||
assert vec2::size_of() == vec2::dim() * 4;
|
||||
assert vec3::size_of() == vec3::dim() * 4;
|
||||
assert vec4::size_of() == vec4::dim() * 4;
|
||||
|
||||
assert dvec2::identity() == dvec2::from_value(1f64);
|
||||
assert dvec3::identity() == dvec3::from_value(1f64);
|
||||
assert dvec4::identity() == dvec4::from_value(1f64);
|
||||
assert dvec2::identity() == dvec2::new(1f64, 1f64);
|
||||
assert dvec3::identity() == dvec3::new(1f64, 1f64, 1f64);
|
||||
assert dvec4::identity() == dvec4::new(1f64, 1f64, 1f64, 1f64);
|
||||
assert dvec2::zero() == dvec2::new(0f64, 0f64);
|
||||
assert dvec3::zero() == dvec3::new(0f64, 0f64, 0f64);
|
||||
assert dvec4::zero() == dvec4::new(0f64, 0f64, 0f64, 0f64);
|
||||
assert dvec2::dim() == 2;
|
||||
assert dvec3::dim() == 3;
|
||||
assert dvec4::dim() == 4;
|
||||
assert dvec2::size_of() == dvec2::dim() * 8;
|
||||
assert dvec3::size_of() == dvec3::dim() * 8;
|
||||
assert dvec4::size_of() == dvec4::dim() * 8;
|
||||
|
||||
assert bvec2::dim() == 2;
|
||||
assert bvec3::dim() == 3;
|
||||
assert bvec4::dim() == 4;
|
||||
assert bvec2::size_of() == bvec2::dim() * 1;
|
||||
assert bvec3::size_of() == bvec3::dim() * 1;
|
||||
assert bvec4::size_of() == bvec4::dim() * 1;
|
||||
|
||||
assert ivec2::identity() == ivec2::from_value(1i32);
|
||||
assert ivec3::identity() == ivec3::from_value(1i32);
|
||||
assert ivec4::identity() == ivec4::from_value(1i32);
|
||||
assert ivec2::identity() == ivec2::new(1i32, 1i32);
|
||||
assert ivec2::identity() == ivec2::new(1i32, 1i32);
|
||||
assert ivec3::identity() == ivec3::new(1i32, 1i32, 1i32);
|
||||
assert ivec4::identity() == ivec4::new(1i32, 1i32, 1i32, 1i32);
|
||||
assert ivec2::zero() == ivec2::new(0i32, 0i32);
|
||||
assert ivec3::zero() == ivec3::new(0i32, 0i32, 0i32);
|
||||
assert ivec4::zero() == ivec4::new(0i32, 0i32, 0i32, 0i32);
|
||||
assert ivec2::identity() == ivec2::from_value(1);
|
||||
assert ivec3::identity() == ivec3::from_value(1);
|
||||
assert ivec4::identity() == ivec4::from_value(1);
|
||||
assert ivec2::identity() == ivec2::new(1, 1);
|
||||
assert ivec2::identity() == ivec2::new(1, 1);
|
||||
assert ivec3::identity() == ivec3::new(1, 1, 1);
|
||||
assert ivec4::identity() == ivec4::new(1, 1, 1, 1);
|
||||
assert ivec2::zero() == ivec2::new(0, 0);
|
||||
assert ivec3::zero() == ivec3::new(0, 0, 0);
|
||||
assert ivec4::zero() == ivec4::new(0, 0, 0, 0);
|
||||
assert ivec2::dim() == 2;
|
||||
assert ivec3::dim() == 3;
|
||||
assert ivec4::dim() == 4;
|
||||
assert ivec2::size_of() == ivec2::dim() * 4;
|
||||
assert ivec3::size_of() == ivec3::dim() * 4;
|
||||
assert ivec4::size_of() == ivec4::dim() * 4;
|
||||
|
||||
assert uvec2::identity() == uvec2::from_value(1u32);
|
||||
assert uvec3::identity() == uvec3::from_value(1u32);
|
||||
assert uvec4::identity() == uvec4::from_value(1u32);
|
||||
assert uvec2::identity() == uvec2::new(1u32, 1u32);
|
||||
assert uvec2::identity() == uvec2::new(1u32, 1u32);
|
||||
assert uvec3::identity() == uvec3::new(1u32, 1u32, 1u32);
|
||||
assert uvec4::identity() == uvec4::new(1u32, 1u32, 1u32, 1u32);
|
||||
assert uvec2::zero() == uvec2::new(0u32, 0u32);
|
||||
assert uvec3::zero() == uvec3::new(0u32, 0u32, 0u32);
|
||||
assert uvec4::zero() == uvec4::new(0u32, 0u32, 0u32, 0u32);
|
||||
assert uvec2::identity() == uvec2::from_value(1);
|
||||
assert uvec3::identity() == uvec3::from_value(1);
|
||||
assert uvec4::identity() == uvec4::from_value(1);
|
||||
assert uvec2::identity() == uvec2::new(1, 1);
|
||||
assert uvec2::identity() == uvec2::new(1, 1);
|
||||
assert uvec3::identity() == uvec3::new(1, 1, 1);
|
||||
assert uvec4::identity() == uvec4::new(1, 1, 1, 1);
|
||||
assert uvec2::zero() == uvec2::new(0, 0);
|
||||
assert uvec3::zero() == uvec3::new(0, 0, 0);
|
||||
assert uvec4::zero() == uvec4::new(0, 0, 0, 0);
|
||||
assert uvec2::dim() == 2;
|
||||
assert uvec3::dim() == 3;
|
||||
assert uvec4::dim() == 4;
|
||||
assert uvec2::size_of() == uvec2::dim() * 4;
|
||||
assert uvec3::size_of() == uvec3::dim() * 4;
|
||||
assert uvec4::size_of() == uvec4::dim() * 4;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat() {
|
||||
assert mat2::identity() == mat2::new(1f32, 0f32,
|
||||
0f32, 1f32);
|
||||
assert mat2::identity() == mat2::from_cols(vec2::new(1f32, 0f32),
|
||||
vec2::new(0f32, 1f32));
|
||||
assert mat3::identity() == mat3::new(1f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 1f32);
|
||||
assert mat3::identity() == mat3::from_cols(vec3::new(1f32, 0f32, 0f32),
|
||||
vec3::new(0f32, 1f32, 0f32),
|
||||
vec3::new(0f32, 0f32, 1f32));
|
||||
assert mat4::identity() == mat4::new(1f32, 0f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32, 0f32,
|
||||
0f32, 0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 0f32, 1f32);
|
||||
assert mat4::identity() == mat4::from_cols(vec4::new(1f32, 0f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 1f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 1f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 0f32, 1f32));
|
||||
assert mat2::zero() == mat2::from_cols(vec2::zero(),
|
||||
vec2::zero());
|
||||
assert mat3::zero() == mat3::from_cols(vec3::zero(),
|
||||
vec3::zero(),
|
||||
vec3::zero());
|
||||
assert mat4::zero() == mat4::from_cols(vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero());
|
||||
assert mat2::dim() == 2;
|
||||
assert mat3::dim() == 3;
|
||||
assert mat4::dim() == 4;
|
||||
assert mat2::rows() == 2;
|
||||
assert mat3::rows() == 3;
|
||||
assert mat4::rows() == 4;
|
||||
assert mat2::cols() == 2;
|
||||
assert mat3::cols() == 3;
|
||||
assert mat4::cols() == 4;
|
||||
assert mat2::size_of() == mat2::rows() * mat2::cols() * 4;
|
||||
assert mat3::size_of() == mat3::rows() * mat3::cols() * 4;
|
||||
assert mat4::size_of() == mat4::rows() * mat4::cols() * 4;
|
||||
|
||||
assert dmat2::identity() == dmat2::new(1f64, 0f64,
|
||||
0f64, 1f64);
|
||||
assert dmat2::identity() == dmat2::from_cols(dvec2::new(1f64, 0f64),
|
||||
dvec2::new(0f64, 1f64));
|
||||
assert dmat3::identity() == dmat3::new(1f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 1f64);
|
||||
assert dmat3::identity() == dmat3::from_cols(dvec3::new(1f64, 0f64, 0f64),
|
||||
dvec3::new(0f64, 1f64, 0f64),
|
||||
dvec3::new(0f64, 0f64, 1f64));
|
||||
assert dmat4::identity() == dmat4::new(1f64, 0f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64, 0f64,
|
||||
0f64, 0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 0f64, 1f64);
|
||||
assert dmat4::identity() == dmat4::from_cols(dvec4::new(1f64, 0f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 1f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 1f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 0f64, 1f64));
|
||||
assert dmat2::zero() == dmat2::from_cols(dvec2::zero(),
|
||||
dvec2::zero());
|
||||
assert dmat3::zero() == dmat3::from_cols(dvec3::zero(),
|
||||
dvec3::zero(),
|
||||
dvec3::zero());
|
||||
assert dmat4::zero() == dmat4::from_cols(dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero());
|
||||
assert dmat2::dim() == 2;
|
||||
assert dmat3::dim() == 3;
|
||||
assert dmat4::dim() == 4;
|
||||
assert dmat2::rows() == 2;
|
||||
assert dmat3::rows() == 3;
|
||||
assert dmat4::rows() == 4;
|
||||
assert dmat2::cols() == 2;
|
||||
assert dmat3::cols() == 3;
|
||||
assert dmat4::cols() == 4;
|
||||
assert dmat2::size_of() == dmat2::rows() * dmat2::cols() * 8;
|
||||
assert dmat3::size_of() == dmat3::rows() * dmat3::cols() * 8;
|
||||
assert dmat4::size_of() == dmat4::rows() * dmat4::cols() * 8;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quat() {
|
||||
// TODO: unit tests
|
||||
}
|
|
@ -4,9 +4,9 @@ use std::cmp::FuzzyEq;
|
|||
|
||||
use numeric::Number;
|
||||
|
||||
pub use vec2::Vec2;
|
||||
pub use vec3::Vec3;
|
||||
pub use vec4::Vec4;
|
||||
pub use vec2::{Vec2, vec2, dvec2, bvec2, ivec2, uvec2};
|
||||
pub use vec3::{Vec3, vec3, dvec3, bvec3, ivec3, uvec3};
|
||||
pub use vec4::{Vec4, vec4, dvec4, bvec4, ivec4, uvec4};
|
||||
|
||||
|
||||
/**
|
||||
|
|
72
src/vec2.rs
72
src/vec2.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::{Eq, Ord};
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::util::swap;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
|
@ -352,4 +353,75 @@ pub impl Vec2<bool>: BooleanVector {
|
|||
pure fn not(&self) -> Vec2<bool> {
|
||||
Vec2::new(!self[0], !self[1])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type vec2 = Vec2<f32>; /// a two-component single-precision floating-point vector
|
||||
pub type dvec2 = Vec2<f64>; /// a two-component double-precision floating-point vector
|
||||
pub type bvec2 = Vec2<bool>; /// a two-component Boolean vector
|
||||
pub type ivec2 = Vec2<i32>; /// a two-component signed integer vector
|
||||
pub type uvec2 = Vec2<u32>; /// a two-component unsigned integer vector
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec2 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
||||
}
|
||||
|
||||
pub impl dvec2 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
||||
}
|
||||
|
||||
pub impl bvec2 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
||||
#[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 ivec2 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
||||
}
|
||||
|
||||
pub impl uvec2 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec2>() }
|
||||
}
|
76
src/vec3.rs
76
src/vec3.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::{Eq, Ord};
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::util::swap;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
|
@ -391,4 +392,79 @@ pub impl Vec3<bool>: BooleanVector {
|
|||
pure fn not(&self) -> Vec3<bool> {
|
||||
Vec3::new(!self[0], !self[1], !self[2])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type vec3 = Vec3<f32>; /// a three-component single-precision floating-point vector
|
||||
pub type dvec3 = Vec3<f64>; /// a three-component double-precision floating-point vector
|
||||
pub type bvec3 = Vec3<bool>; /// a three-component Boolean vector
|
||||
pub type ivec3 = Vec3<i32>; /// a three-component signed integer vector
|
||||
pub type uvec3 = Vec3<u32>; /// a three-component unsigned integer vector
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec3 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
||||
}
|
||||
|
||||
pub impl dvec3 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
||||
}
|
||||
|
||||
pub impl bvec3 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
||||
#[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 ivec3 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
||||
}
|
||||
|
||||
pub impl uvec3 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec3 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec3>() }
|
||||
}
|
81
src/vec4.rs
81
src/vec4.rs
|
@ -1,6 +1,7 @@
|
|||
use core::cast::transmute;
|
||||
use core::cmp::{Eq, Ord};
|
||||
use core::ptr::to_unsafe_ptr;
|
||||
use core::sys::size_of;
|
||||
use core::util::swap;
|
||||
use core::vec::raw::buf_as_slice;
|
||||
|
||||
|
@ -397,4 +398,84 @@ pub impl Vec4<bool>: BooleanVector {
|
|||
pure fn not(&self) -> Vec4<bool> {
|
||||
Vec4::new(!self[0], !self[1], !self[2], !self[3])
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL-style type 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).
|
||||
|
||||
pub type vec4 = Vec4<f32>; /// a four-component single-precision floating-point vector
|
||||
pub type dvec4 = Vec4<f64>; /// a four-component double-precision floating-point vector
|
||||
pub type bvec4 = Vec4<bool>; /// a four-component Boolean vector
|
||||
pub type ivec4 = Vec4<i32>; /// a four-component signed integer vector
|
||||
pub type uvec4 = Vec4<u32>; /// a four-component unsigned integer vector
|
||||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec4 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
||||
}
|
||||
|
||||
pub impl dvec4 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl bvec4 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
||||
#[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>() }
|
||||
}
|
||||
|
||||
pub impl ivec4 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
||||
}
|
||||
|
||||
pub impl uvec4 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec4 { NumericVector::zero() }
|
||||
|
||||
#[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() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec4>() }
|
||||
}
|
Loading…
Reference in a new issue