2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, U4, UnitQuaternion};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-23 20:41:56 +08:00
|
|
|
use aliases::{Qua, Vec, TVec3, TMat4};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> TVec3<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
let q = UnitQuaternion::new_unchecked(*x);
|
|
|
|
let a = q.to_euler_angles();
|
2018-09-23 20:41:56 +08:00
|
|
|
TVec3::new(a.2, a.1, a.0)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `>` comparison between two quaternions.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
::greater_than(&x.coords, &y.coords)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `>=` comparison between two quaternions.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
::greater_than_equal(&x.coords, &y.coords)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `<` comparison between two quaternions.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
::less_than(&x.coords, &y.coords)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `<=` comparison between two quaternions.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
::less_than_equal(&x.coords, &y.coords)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Convert a quaternion to a rotation matrix in homogeneous coordinates.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_cast<N: Real>(x: &Qua<N>) -> TMat4<N> {
|
2018-09-22 23:36:08 +08:00
|
|
|
::quat_to_mat4(x)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_look_at<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
quat_look_at_rh(direction, up)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix).
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_look_at_lh<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
UnitQuaternion::look_at_lh(direction, up).unwrap()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_look_at_rh<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
UnitQuaternion::look_at_rh(direction, up).unwrap()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The "roll" euler angle of the quaternion `x` assumed to be normalized.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_roll<N: Real>(x: &Qua<N>) -> N {
|
2018-09-20 20:23:31 +08:00
|
|
|
// FIXME: optimize this.
|
2018-09-22 22:40:58 +08:00
|
|
|
quat_euler_angles(x).z
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The "yaw" euler angle of the quaternion `x` assumed to be normalized.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_yaw<N: Real>(x: &Qua<N>) -> N {
|
2018-09-20 20:23:31 +08:00
|
|
|
// FIXME: optimize this.
|
2018-09-22 22:40:58 +08:00
|
|
|
quat_euler_angles(x).y
|
2018-09-20 20:23:31 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The "pitch" euler angle of the quaternion `x` assumed to be normalized.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_pitch<N: Real>(x: &Qua<N>) -> N {
|
2018-09-20 20:23:31 +08:00
|
|
|
// FIXME: optimize this.
|
2018-09-22 22:40:58 +08:00
|
|
|
quat_euler_angles(x).x
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|