Start adding some gtx functions.

This commit is contained in:
sebcrozet 2018-09-20 19:54:12 +02:00 committed by Sébastien Crozet
parent e7edad5ebb
commit a827e2d95f
25 changed files with 609 additions and 219 deletions

View File

@ -4,3 +4,6 @@
* equal overload with epsilon -> equal_epsilon * equal overload with epsilon -> equal_epsilon
* ortho(l, r, b, t) -> infinite_ortho * ortho(l, r, b, t) -> infinite_ortho
* tweaked_infinite_perspective(fovy, aspect, near, ep) -> tweaked_infinite_perspective_ep * tweaked_infinite_perspective(fovy, aspect, near, ep) -> tweaked_infinite_perspective_ep
* Function overload: the vec version is suffixed by _vec
* Function overload: the methods taking an epsilon as suffixed by _eps
* L1Norm and L2Norm between two vectors have been renamed: l1_distance, l2_distance

View File

@ -1,209 +1,202 @@
use na::{Scalar, DefaultAllocator}; use std::mem;
use num::FromPrimitive;
use na::{self, Scalar, Real, DefaultAllocator};
use aliases::Vec; use aliases::{Vec, Mat};
use traits::{Dimension, Alloc}; use traits::{Number, Dimension, Alloc};
pub fn abs<T>(x: T) -> T { pub fn abs<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>) -> Mat<N, R, C>
unimplemented!() where DefaultAllocator: Alloc<N, R, C> {
x.abs()
} }
pub fn abs2<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D> pub fn ceil<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.ceil())
} }
pub fn ceil<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D> pub fn clamp<N: Number>(x: N, minVal: N, maxVal: N) -> N {
na::clamp(x, minVal, maxVal)
}
pub fn clamp2<N: Number, D: Dimension>(x: &Vec<N, D>,minVal: N, maxVal: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| na::clamp(x, minVal, maxVal))
} }
pub fn clamp<T>(x: T, minVal: T, maxVal: T) -> T { pub fn clamp3<N: Number, D: Dimension>(x: &Vec<N, D>, minVal: &Vec<N, D>, maxVal: &Vec<N, D>) -> Vec<N, D>
unimplemented!()
}
pub fn clamp2<N: Scalar, D: Dimension>(x: &Vec<N, D>,minVal: N, maxVal: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() na::clamp(x.clone(), minVal.clone(), maxVal.clone())
} }
pub fn clamp3<N: Scalar, D: Dimension>(x: &Vec<N, D>, minVal: &Vec<N, D>, maxVal: &Vec<N, D>) -> Vec<N, D> pub fn float_bits_to_int(v: f32) -> i32 {
where DefaultAllocator: Alloc<N, D> { unsafe { mem::transmute(v) }
unimplemented!()
} }
pub fn floatBitsToInt(v: f32) -> i32 { pub fn float_bits_to_int_vec<D: Dimension>(v: Vec<f32, D>) -> Vec<i32, D>
unimplemented!()
}
pub fn floatBitsToInt2<D: Dimension>(v: Vec<f32, D>) -> Vec<i32, D>
where DefaultAllocator: Alloc<f32, D> { where DefaultAllocator: Alloc<f32, D> {
unimplemented!() v.map(|v| float_bits_to_int(v))
} }
pub fn floatBitsToUint(v: f32) -> u32 { pub fn float_bits_to_uint(v: f32) -> u32 {
unimplemented!() unsafe { mem::transmute(v) }
} }
pub fn floatBitsToUint2<D: Dimension>(v: &Vec<f32, D>) -> Vec<u32, D> pub fn float_bits_to_uint_vec<D: Dimension>(v: &Vec<f32, D>) -> Vec<u32, D>
where DefaultAllocator: Alloc<f32, D> { where DefaultAllocator: Alloc<f32, D> {
unimplemented!() v.map(|v| float_bits_to_uint(v))
} }
pub fn floor<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
pub fn floor<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.floor())
}
pub fn fma<T>(a: T, b: T, c: T) -> T {
unimplemented!()
} }
pub fn fract<T>(x: T) -> T { // FIXME: should be implemented for Vec/Mat?
unimplemented!() pub fn fma<N: Number>(a: N, b: N, c: N) -> N {
// FIXME: use an actual FMA
a * b + c
} }
pub fn fract2<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D> pub fn fract<N: Real>(x: N) -> N {
x.fract()
}
pub fn fract2<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.fract())
}
//// FIXME: should be implemented for Vec/Mat?
///// Returns the (significant, exponent) of this float number.
//pub fn frexp<N: Real>(x: N, exp: N) -> (N, N) {
// // FIXME: is there a better approach?
// let e = x.log2().ceil();
// (x * (-e).exp2(), e)
//}
pub fn int_bits_to_float(v: i32) -> f32 {
unsafe { mem::transmute(v) }
} }
pub fn frexp<T, I>(x: T, exp: I) -> T { pub fn int_bits_to_float_vec<D: Dimension>(v: &Vec<i32, D>) -> Vec<f32, D>
unimplemented!()
}
pub fn intBitsToFloat<N: Scalar, D: Dimension>(v: i32) -> f32 {
unimplemented!()
}
pub fn intBitsToFloat2<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
where DefaultAllocator: Alloc<f32, D> { where DefaultAllocator: Alloc<f32, D> {
unimplemented!() v.map(|v| int_bits_to_float(v))
} }
pub fn isinf<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D> //pub fn isinf<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D>
// where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
//
//}
//
//pub fn isnan<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D>
// where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
//
//}
///// Returns the (significant, exponent) of this float number.
//pub fn ldexp<N: Real>(x: N, exp: N) -> N {
// // FIXME: is there a better approach?
// x * (exp).exp2()
//}
pub fn max<N: Number>(x: N, y: N) -> N {
na::sup(&x, &y)
}
pub fn max2<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| na::sup(&x, &y))
} }
pub fn isnan<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D> pub fn max3<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() na::sup(x, y)
} }
pub fn ldexp<T, I>(x: T, exp: I) -> T { pub fn min<N: Number>(x: N, y: N) -> N {
unimplemented!() na::inf(&x, &y)
} }
pub fn max<T>(x: T, y: T) -> T { pub fn min2<N: Number, D: Dimension>(x: &Vec<N, D>,y: N) -> Vec<N, D>
unimplemented!()
}
pub fn max2<N: Scalar, D: Dimension>(x: &Vec<N, D>,y: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| na::inf(&x, &y))
} }
pub fn max3<N: Scalar, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
pub fn min3<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() na::inf(x, y)
}
pub fn min<T>(x: T, y: T) -> T {
unimplemented!()
} }
pub fn min2<N: Scalar, D: Dimension>(x: &Vec<N, D>,y: N) -> Vec<N, D> pub fn mix<N: Number>(x: N, y: N, a: N) -> N {
x * (N::one() - a) + y * a
}
pub fn mod_<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.zip_map(y, |x, y| x % y)
} }
pub fn min3<N: Scalar, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
pub fn modf<N: Number>(x: N, i: N) -> N {
x % i
}
pub fn round<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.round())
}
pub fn mix<T>(x: T, y: T, a: T) -> T {
unimplemented!()
} }
pub fn mod_<N: Scalar, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D> //pub fn roundEven<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
// where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
//}
pub fn sign<N: Number, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.signum())
}
pub fn modf<T>(x: T, i: &T) -> T {
unimplemented!()
} }
pub fn round<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D> pub fn smoothstep<N: Number>(edge0: N, edge1: N, x: N) -> N {
let _3: N = FromPrimitive::from_f64(3.0).unwrap();
let _2: N = FromPrimitive::from_f64(2.0).unwrap();
let t = na::clamp((x - edge0) / (edge1 - edge0), N::zero(), N::one());
t * t * (_3 - t * _2)
}
pub fn step<N: Number>(edge: N, x: N) -> N {
if edge > x {
N::zero()
} else {
N::one()
}
}
pub fn step2<N: Number, D: Dimension>(edge: N, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| step(edge, x))
} }
pub fn roundEven<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
pub fn step3<N: Number, D: Dimension>(edge: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() edge.zip_map(x, |edge, x| step(edge, x))
} }
pub fn sign<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
pub fn trunc<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
unimplemented!() x.map(|x| x.trunc())
}
pub fn uint_bits_to_float(v: u32) -> f32 {
unsafe { mem::transmute(v) }
} }
pub fn smoothstep<T>(edge0: T, edge1: T, x: T) -> T { pub fn uint_bits_to_float_vec<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
unimplemented!()
}
pub fn step<T>(edge: T, x: T) -> T {
unimplemented!()
}
pub fn step2<N: Scalar, D: Dimension>(edge: N, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}
pub fn step3<N: Scalar, D: Dimension>(edge: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}
pub fn trunc<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}
pub fn uintBitsToFloat(v: u32) -> f32 {
unimplemented!()
}
pub fn uintBitsToFloat2<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
where DefaultAllocator: Alloc<f32, D> { where DefaultAllocator: Alloc<f32, D> {
unimplemented!() v.map(|v| uint_bits_to_float(v))
} }

View File

@ -1,32 +1,67 @@
use na::{Real, U2, U3, U4}; use na::{self, Real, U2, U3, U4, Vector3, Vector4, Matrix4};
use aliases::{Mat, Vec}; use aliases::{Mat, Vec};
pub fn pickMatrix<N: Real>(center: &Vec<N, U2>, delta: &Vec<N, U2>, viewport: &Vec<N, U4>) -> Mat<N, U4, U4> { pub fn pick_matrix<N: Real>(center: &Vec<N, U2>, delta: &Vec<N, U2>, viewport: &Vec<N, U4>) -> Mat<N, U4, U4> {
unimplemented!() let shift = Vector3::new(
(viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x,
(viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y,
N::zero()
);
let result = Matrix4::new_translation(&shift);
result.prepend_nonuniform_scaling(&Vector3::new(viewport.z / delta.x, viewport.w / delta.y, N::one()))
} }
pub fn project<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() project_no(obj, model, proj, viewport)
} }
pub fn projectNO<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project_no<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() let proj = project_zo(obj, model, proj, viewport);
Vector3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
} }
pub fn projectZO<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn project_zo<N: Real>(obj: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() let mut normalized = proj * model * Vector4::new(obj.x, obj.y, obj.z, N::one());
let scale = N::one() / normalized.w;
Vector3::new(
viewport.x + (viewport.z * (normalized.x * scale + N::one()) * na::convert(0.5)),
viewport.y + (viewport.w * (normalized.y * scale + N::one()) * na::convert(0.5)),
normalized.z * scale,
)
} }
pub fn unProject<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() unproject_no(win, model, proj, viewport)
} }
pub fn unProjectNO<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject_no<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros());
let pt = Vector4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(),
_2 * win.z - N::one(),
N::one(),
);
let result = transform * pt;
result.fixed_rows::<U3>(0) / result.w
} }
pub fn unProjectZO<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> { pub fn unproject_zo<N: Real>(win: &Vec<N, U3>, model: &Mat<N, U4, U4>, proj: &Mat<N, U4, U4>, viewport: Vec<N, U4>) -> Vec<N, U3> {
unimplemented!() let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(Matrix4::zeros());
let pt = Vector4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(),
win.z,
N::one(),
);
let result = transform * pt;
result.fixed_rows::<U3>(0) / result.w
} }

View File

@ -26,9 +26,9 @@ pub fn rotate<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N
} }
pub fn scale<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn scale<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
m.append_nonuniform_scaling(v) m.prepend_nonuniform_scaling(v)
} }
pub fn translate<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> { pub fn translate<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
m.append_translation(v) m.prepend_translation(v)
} }

View File

@ -1,41 +1,19 @@
use na::Scalar; use na;
pub fn fmax<N: Scalar>(a: N, b: N) -> N { use traits::Number;
unimplemented!()
pub fn max3<N: Number>(a: N, b: N, c: N) -> N {
na::sup(&na::sup(&a, &b), &c)
} }
pub fn fmax3<N: Scalar>(a: N, b: N, C: N) -> N { pub fn max4<N: Number>(a: N, b: N, c: N, d: N) -> N {
unimplemented!() na::sup(&na::sup(&a, &b), &na::sup(&c, &d))
} }
pub fn fmax4<N: Scalar>(a: N, b: N, C: N, D: N) -> N { pub fn min3<N: Number>(a: N, b: N, c: N) -> N {
unimplemented!() na::inf(&na::inf(&a, &b), &c)
} }
pub fn fmin<N: Scalar>(a: N, b: N) -> N { pub fn min4<N: Number>(a: N, b: N, c: N, d: N) -> N {
unimplemented!() na::inf(&na::inf(&a, &b), &na::inf(&c, &d))
}
pub fn fmin3<N: Scalar>(a: N, b: N, c: N) -> N {
unimplemented!()
}
pub fn fmin4<N: Scalar>(a: N, b: N, c: N, d: N) -> N {
unimplemented!()
}
pub fn max3<N: Scalar>(a: N, b: N, c: N) -> N {
unimplemented!()
}
pub fn max4<N: Scalar>(a: N, b: N, c: N, d: N) -> N {
unimplemented!()
}
pub fn min3<N: Scalar>(a: N, b: N, c: N) -> N {
unimplemented!()
}
pub fn min4<N: Scalar>(a: N, b: N, c: N, d: N) -> N {
unimplemented!()
} }

View File

@ -1,18 +1,18 @@
use na::{Scalar, DefaultAllocator}; //use na::{Scalar, DefaultAllocator};
//
//use traits::{Alloc, Dimension};
//use aliases::Vec;
use traits::{Alloc, Dimension}; //pub fn iround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<i32, D>
use aliases::Vec; // where DefaultAllocator: Alloc<N, D> {
// x.map(|x| x.round())
pub fn iround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<i64, D> //}
where DefaultAllocator: Alloc<N, D> { //
unimplemented!() //pub fn log2<I>(x: I) -> I {
} // unimplemented!()
//}
pub fn log2<I>(x: I) -> I { //
unimplemented!() //pub fn uround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<u32, D>
} // where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
pub fn uround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<u64, D> //}
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}

View File

@ -0,0 +1,28 @@
use na::{self, Scalar, Real, DefaultAllocator};
use traits::{Number, Alloc, Dimension};
use aliases::Mat;
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::zero(), |x, y| x + *y)
}
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::min_value(), |x, y| na::sup(&x, y))
}
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::max_value(), |x, y| na::inf(&x, y))
}
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::one(), |x, y| x * *y)
}
//pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v)
//pub fn vec< L, T, Q > compScale (vec< L, floatType, Q > const &v)

View File

@ -0,0 +1,41 @@
pub fn mat< 4, 4, T, defaultp > derivedEulerAngleX (T const &angleX, T const &angularVelocityX)
pub fn mat< 4, 4, T, defaultp > derivedEulerAngleY (T const &angleY, T const &angularVelocityY)
pub fn mat< 4, 4, T, defaultp > derivedEulerAngleZ (T const &angleZ, T const &angularVelocityZ)
pub fn mat< 4, 4, T, defaultp > eulerAngleX (T const &angleX)
pub fn mat< 4, 4, T, defaultp > eulerAngleXY (T const &angleX, T const &angleY)
pub fn mat< 4, 4, T, defaultp > eulerAngleXYX (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleXYZ (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleXZ (T const &angleX, T const &angleZ)
pub fn mat< 4, 4, T, defaultp > eulerAngleXZX (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleXZY (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleY (T const &angleY)
pub fn mat< 4, 4, T, defaultp > eulerAngleYX (T const &angleY, T const &angleX)
pub fn mat< 4, 4, T, defaultp > eulerAngleYXY (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleYXZ (T const &yaw, T const &pitch, T const &roll)
pub fn mat< 4, 4, T, defaultp > eulerAngleYZ (T const &angleY, T const &angleZ)
pub fn mat< 4, 4, T, defaultp > eulerAngleYZX (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleYZY (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleZ (T const &angleZ)
pub fn mat< 4, 4, T, defaultp > eulerAngleZX (T const &angle, T const &angleX)
pub fn mat< 4, 4, T, defaultp > eulerAngleZXY (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleZXZ (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleZY (T const &angleZ, T const &angleY)
pub fn mat< 4, 4, T, defaultp > eulerAngleZYX (T const &t1, T const &t2, T const &t3)
pub fn mat< 4, 4, T, defaultp > eulerAngleZYZ (T const &t1, T const &t2, T const &t3)
pub fn void extractEulerAngleXYX (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleXYZ (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleXZX (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleXZY (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleYXY (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleYXZ (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleYZX (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleYZY (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleZXY (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleZXZ (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleZYX (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn void extractEulerAngleZYZ (mat< 4, 4, T, defaultp > const &M, T &t1, T &t2, T &t3)
pub fn mat< 2, 2, T, defaultp > orientate2 (T const &angle)
pub fn mat< 3, 3, T, defaultp > orientate3 (T const &angle)
pub fn mat< 3, 3, T, Q > orientate3 (vec< 3, T, Q > const &angles)
pub fn mat< 4, 4, T, Q > orientate4 (vec< 3, T, Q > const &angles)
pub fn mat< 4, 4, T, defaultp > yawPitchRoll (T const &yaw, T const &pitch, T const &roll)

View File

@ -0,0 +1,8 @@
use na::U2;
use traits::Number;
use aliases::Vec;
pub fn cross<N: Number>(v: &Vec<N, U2>, u: &Vec<N, U2>) -> N {
v.perp(u)
}

View File

@ -0,0 +1,12 @@
use na::U3;
use traits::Number;
use aliases::Vec;
pub fn left_handed<N: Number>(a: &Vec<N, U3>, b: &Vec<N, U3>, c: &Vec<N, U3>) -> bool {
a.cross(b).dot(c) < N::zero()
}
pub fn right_handed<N: Number>(a: &Vec<N, U3>, b: &Vec<N, U3>, c: &Vec<N, U3>) -> bool {
a.cross(b).dot(c) > N::zero()
}

View File

@ -0,0 +1,19 @@
use na::{self, Real, U3, U4, Matrix4};
use aliases::{Vec, Mat};
pub fn matrix_cross3<N: Real>(x: &Vec<N, U3>) -> Mat<N, U3, U3> {
x.cross_matrix()
}
pub fn matrix_cross4<N: Real>(x: &Vec<N, U3>) -> Mat<N, U4, U4> {
let m = x.cross_matrix();
// FIXME: use a dedicated constructor from Matrix3 to Matrix4.
Matrix4::new(
m.m11, m.m12, m.m13, N::zero(),
m.m21, m.m22, m.m23, N::zero(),
m.m31, m.m32, m.m33, N::zero(),
N::zero(), N::zero(), N::zero(), N::one(),
)
}

View File

@ -0,0 +1,42 @@
use na::{Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3,
U2, U3, U4};
use traits::Number;
use aliases::{Vec, Mat};
pub fn diagonal2x2<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U2> {
Matrix2::from_diagonal(v)
}
pub fn diagonal2x3<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U3> {
Matrix2x3::from_partial_diagonal(v.as_slice())
}
pub fn diagonal2x4<N: Number>(v: &Vec<N, U2>) -> Mat<N, U2, U4> {
Matrix2x4::from_partial_diagonal(v.as_slice())
}
pub fn diagonal3x2<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U2> {
Matrix3x2::from_partial_diagonal(v.as_slice())
}
pub fn diagonal3x3<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U3> {
Matrix3::from_diagonal(v)
}
pub fn diagonal3x4<N: Number>(v: &Vec<N, U3>) -> Mat<N, U3, U4> {
Matrix3x4::from_partial_diagonal(v.as_slice())
}
pub fn diagonal4x2<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U2> {
Matrix4x2::from_partial_diagonal(v.as_slice())
}
pub fn diagonal4x3<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U3> {
Matrix4x3::from_partial_diagonal(v.as_slice())
}
pub fn diagonal4x4<N: Number>(v: &Vec<N, U4>) -> Mat<N, U4, U4> {
Matrix4::from_diagonal(v)
}

View File

@ -0,0 +1,44 @@
use na::{Real, DefaultAllocator};
use traits::{Alloc, Dimension};
use aliases::Vec;
pub fn distance2<N: Real, D: Dimension>(p0: &Vec<N, D>, p1: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
(p1 - p0).norm_squared()
}
pub fn l1_distance<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
l1_norm(&(x - y))
}
pub fn l1_norm<N: Real, D: Dimension>(v: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
::comp_add(&v.abs())
}
pub fn l2_distance<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
l2_norm(&(y - x))
}
pub fn l2_norm<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
x.norm()
}
pub fn length2<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
x.norm_squared()
}
//pub fn lxNorm<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, unsigned int Depth) -> N
// where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
//}
//
//pub fn lxNorm<N: Real, D: Dimension>(x: &Vec<N, D>, unsigned int Depth) -> N
// where DefaultAllocator: Alloc<N, D> {
// unimplemented!()
//}

View File

@ -0,0 +1,7 @@
use na::{Real, U3};
use aliases::Vec;
pub fn triangleNormal<N: Real>(p1: &Vec<N, U3>, p2: &Vec<N, U3>, p3: &Vec<N, U3>) -> Vec<N, U3> {
(p2 - p1).cross(&(p3 - p1)).normalize()
}

View File

@ -0,0 +1,17 @@
use na::{Real, DefaultAllocator};
use traits::{Dimension, Alloc};
use aliases::Vec;
pub fn fastNormalizeDot<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
// XXX: improve those.
x.normalize().dot(&y.normalize())
}
pub fn normalizeDot<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
where DefaultAllocator: Alloc<N, D> {
// XXX: improve those.
x.normalize().dot(&y.normalize())
}

View File

@ -0,0 +1,16 @@
pub fn vec< 3, T, Q > cross (qua< T, Q > const &q, vec< 3, T, Q > const &v)
pub fn vec< 3, T, Q > cross (vec< 3, T, Q > const &v, qua< T, Q > const &q)
pub fn T extractRealComponent (qua< T, Q > const &q)
pub fn qua< T, Q > fastMix (qua< T, Q > const &x, qua< T, Q > const &y, T const &a)
pub fn qua< T, Q > intermediate (qua< T, Q > const &prev, qua< T, Q > const &curr, qua< T, Q > const &next)
pub fn T length2 (qua< T, Q > const &q)
pub fn qua< T, Q > quat_identity ()
pub fn vec< 3, T, Q > rotate (qua< T, Q > const &q, vec< 3, T, Q > const &v)
pub fn vec< 4, T, Q > rotate (qua< T, Q > const &q, vec< 4, T, Q > const &v)
pub fn qua< T, Q > rotation (vec< 3, T, Q > const &orig, vec< 3, T, Q > const &dest)
pub fn qua< T, Q > shortMix (qua< T, Q > const &x, qua< T, Q > const &y, T const &a)
pub fn qua< T, Q > squad (qua< T, Q > const &q1, qua< T, Q > const &q2, qua< T, Q > const &s1, qua< T, Q > const &s2, T const &h)
pub fn mat< 3, 3, T, Q > toMat3 (qua< T, Q > const &x)
pub fn mat< 4, 4, T, Q > toMat4 (qua< T, Q > const &x)
pub fn qua< T, Q > toQuat (mat< 3, 3, T, Q > const &x)
pub fn qua< T, Q > toQuat (mat< 4, 4, T, Q > const &x)

View File

@ -0,0 +1,11 @@
use na::{Real, Rotation3, UnitQuaternion, Unit, U3, U4};
use aliases::{Vec, Mat, Qua};
pub fn rotateNormalizedAxis<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N, U4, U4> {
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
}
pub fn rotateNormalizedAxis2<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> {
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap()
}

View File

@ -0,0 +1,45 @@
use na::{Real, U2, U3, U4};
pub fn orientation<N: Real>(Normal: &Vec<N, U3>, Up: &Vec<N, U3>) -> Mat<N, U4, U4> {
unimplemented!()
}
pub fn rotate2<N: Real>(v: &Vec<N, U2>, angle: N) -> Vec<N, U2> {
unimplemented!()
}
pub fn rotate<N: Real>(v: &Vec<N, U3>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U3> {
unimplemented!()
}
pub fn rotate4<N: Real>(v: &Vec<N, U4>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U4> {
unimplemented!()
}
pub fn rotateX<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
unimplemented!()
}
pub fn rotateX4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
unimplemented!()
}
pub fn rotateY<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
unimplemented!()
}
pub fn rotateY4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
unimplemented!()
}
pub fn rotateZ<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
unimplemented!()
}
pub fn rotateZ4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
unimplemented!()
}
pub fn slerp<N: Real>(x: &Vec<N, U3>, y: &Vec<N, U3>, a: N) -> Vec<N, U3> {
unimplemented!()
}

View File

@ -0,0 +1,17 @@
use na::{Real, Unit, Rotation3, Matrix4, U3, U4};
use traits::Number;
use aliases::{Vec, Mat};
pub fn rotate<N: Real>(angle: N, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous()
}
pub fn scale<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
Matrix4::new_nonuniform_scaling(v)
}
pub fn translate<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
Matrix4::new_translation(v)
}

View File

@ -0,0 +1,9 @@
pub fn mat< 3, 3, T, Q > proj2D (mat< 3, 3, T, Q > const &m, vec< 3, T, Q > const &normal)
pub fn mat< 4, 4, T, Q > proj3D (mat< 4, 4, T, Q > const &m, vec< 3, T, Q > const &normal)
pub fn mat< 4, 4, T, Q > scaleBias (T scale, T bias)
pub fn mat< 4, 4, T, Q > scaleBias (mat< 4, 4, T, Q > const &m, T scale, T bias)
pub fn mat< 3, 3, T, Q > shearX2D (mat< 3, 3, T, Q > const &m, T y)
pub fn mat< 4, 4, T, Q > shearX3D (mat< 4, 4, T, Q > const &m, T y, T z)
pub fn mat< 3, 3, T, Q > shearY2D (mat< 3, 3, T, Q > const &m, T x)
pub fn mat< 4, 4, T, Q > shearY3D (mat< 4, 4, T, Q > const &m, T x, T z)
pub fn mat< 4, 4, T, Q > shearZ3D (mat< 4, 4, T, Q > const &m, T x, T y)

View File

@ -0,0 +1,5 @@
pub fn mat< 3, 3, T, Q > rotate (mat< 3, 3, T, Q > const &m, T angle)
pub fn mat< 3, 3, T, Q > scale (mat< 3, 3, T, Q > const &m, vec< 2, T, Q > const &v)
pub fn mat< 3, 3, T, Q > shearX (mat< 3, 3, T, Q > const &m, T y)
pub fn mat< 3, 3, T, Q > shearY (mat< 3, 3, T, Q > const &m, T x)
pub fn mat< 3, 3, T, Q > translate (mat< 3, 3, T, Q > const &m, vec< 2, T, Q > const &v)

View File

@ -0,0 +1,3 @@
pub fn T angle (vec< L, T, Q > const &x, vec< L, T, Q > const &y)
pub fn T orientedAngle (vec< 2, T, Q > const &x, vec< 2, T, Q > const &y)
pub fn T orientedAngle (vec< 3, T, Q > const &x, vec< 3, T, Q > const &y, vec< 3, T, Q > const &ref)

View File

@ -0,0 +1,37 @@
use na::{Real, DefaultAllocator, U2, U3};
use traits::{Number, Dimension, Alloc};
use aliases::Vec;
pub fn are_collinear<N: Number>(v0: &Vec<N, U3>, v1: &Vec<N, U3>, epsilon: N) -> bool {
is_null(&v0.cross(v1), epsilon)
}
pub fn are_collinear2<N: Number>(v0: &Vec<N, U2>, v1: &Vec<N, U2>, epsilon: N) -> bool {
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
}
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &Vec<N, D>, v1: &Vec<N, D>, epsilon: N) -> bool
where DefaultAllocator: Alloc<N, D> {
abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon)
}
pub fn are_orthonormal<N: Number, D: Dimension>(v0: &Vec<N, D>, v1: &Vec<N, D>, epsilon: N) -> bool
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}
pub fn is_comp_null<N: Number, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon))
}
pub fn is_normalized<N: Real, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> bool
where DefaultAllocator: Alloc<N, D> {
abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon)
}
pub fn is_null<N: Number, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> bool
where DefaultAllocator: Alloc<N, D> {
abs_diff_eq!(*v, Vec::<N, D>::zeros(), epsilon = epsilon)
}

View File

@ -15,6 +15,8 @@ pub use exponential::*;
pub use ext_vector_relational::*; pub use ext_vector_relational::*;
pub use gtx_component_wise::*;
mod aliases; mod aliases;
pub mod constructors; pub mod constructors;
mod common; mod common;
@ -39,15 +41,33 @@ pub mod ext_scalar_common;
pub mod ext_scalar_constants; pub mod ext_scalar_constants;
pub mod ext_vector_common; pub mod ext_vector_common;
pub mod ext_vector_relational; pub mod ext_vector_relational;
pub mod gtc_bitfield; //pub mod gtc_bitfield;
pub mod gtc_constants; pub mod gtc_constants;
pub mod gtc_epsilon; pub mod gtc_epsilon;
pub mod gtc_integer; //pub mod gtc_integer;
pub mod gtc_matrix_access; pub mod gtc_matrix_access;
pub mod gtc_matrix_inverse; pub mod gtc_matrix_inverse;
pub mod gtc_packing; //pub mod gtc_packing;
pub mod gtc_quaternion; pub mod gtc_quaternion;
pub mod gtc_reciprocal; //pub mod gtc_reciprocal;
pub mod gtc_round; //pub mod gtc_round;
pub mod gtc_type_ptr; pub mod gtc_type_ptr;
pub mod gtc_ulp; //pub mod gtc_ulp;
pub mod gtx_component_wise;
//pub mod gtx_euler_angles;
pub mod gtx_exterior_product;
pub mod gtx_handed_coordinate_space;
pub mod gtx_matrix_cross_product;
pub mod gtx_matrix_operation;
pub mod gtx_norm;
pub mod gtx_normal;
pub mod gtx_normalize_dot;
//pub mod gtx_quaternion;
pub mod gtx_rotate_normalized_axis;
//pub mod gtx_rotate_vector;
pub mod gtx_transform;
//pub mod gtx_transform2;
//pub mod gtx_transform2d;
//pub mod gtx_vector_angle;
pub mod gtx_vector_query;

View File

@ -1,5 +1,5 @@
use std::cmp::{PartialOrd, PartialEq}; use std::cmp::{PartialOrd, PartialEq};
use num::Signed; use num::{Signed, FromPrimitive, Bounded};
use approx::AbsDiffEq; use approx::AbsDiffEq;
use alga::general::{Ring, Lattice}; use alga::general::{Ring, Lattice};
@ -10,10 +10,10 @@ pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {} impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}
pub trait Number: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed { pub trait Number: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded {
} }
impl<T: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed> Number for T { impl<T: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded> Number for T {
} }
#[doc(hidden)] #[doc(hidden)]