2018-09-22 19:18:59 +08:00
|
|
|
use na::{self, Real, Unit};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
use aliases::Qua;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The conjugate of `q`.
|
2018-09-20 16:50:34 +08:00
|
|
|
pub fn conjugate<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.conjugate()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The inverse of `q`.
|
2018-09-20 16:50:34 +08:00
|
|
|
pub fn inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.try_inverse().unwrap_or(na::zero())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
//pub fn isinf<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
|
|
|
// x.coords.map(|e| e.is_inf())
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
//pub fn isnan<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
|
|
|
// x.coords.map(|e| e.is_nan())
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Interpolate linearly between `x` and `y`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn lerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
|
|
|
x.lerp(y, a)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
//pub fn mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
|
|
|
// x * (N::one() - a) + y * a
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Interpolate spherically between `x` and `y`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
|
|
|
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|