nalgebra/nalgebra-glm/src/ext/quaternion_common.rs

39 lines
998 B
Rust
Raw Normal View History

2021-08-08 18:59:40 +08:00
use na::{self, Unit};
2019-03-23 21:29:07 +08:00
use crate::aliases::Qua;
2021-08-08 18:59:40 +08:00
use crate::RealNumber;
/// The conjugate of `q`.
2021-08-08 18:59:40 +08:00
pub fn quat_conjugate<T: RealNumber>(q: &Qua<T>) -> Qua<T> {
q.conjugate()
}
/// The inverse of `q`.
2021-08-08 18:59:40 +08:00
pub fn quat_inverse<T: RealNumber>(q: &Qua<T>) -> Qua<T> {
q.try_inverse().unwrap_or_else(na::zero)
}
2021-08-08 18:59:40 +08:00
//pub fn quat_isinf<T: RealNumber>(x: &Qua<T>) -> TVec<bool, U4> {
// x.coords.map(|e| e.is_inf())
//}
2021-08-08 18:59:40 +08:00
//pub fn quat_isnan<T: RealNumber>(x: &Qua<T>) -> TVec<bool, U4> {
// x.coords.map(|e| e.is_nan())
//}
/// Interpolate linearly between `x` and `y`.
2021-08-08 18:59:40 +08:00
pub fn quat_lerp<T: RealNumber>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
x.lerp(y, a)
}
2021-08-08 18:59:40 +08:00
//pub fn quat_mix<T: RealNumber>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
2021-04-11 17:00:38 +08:00
// x * (T::one() - a) + y * a
//}
/// Interpolate spherically between `x` and `y`.
2021-08-08 18:59:40 +08:00
pub fn quat_slerp<T: RealNumber>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
2018-10-22 04:11:27 +08:00
Unit::new_normalize(*x)
.slerp(&Unit::new_normalize(*y), a)
2018-12-29 19:12:56 +08:00
.into_inner()
}