nalgebra/nalgebra-glm/src/gtc/quaternion.rs

75 lines
2.4 KiB
Rust
Raw Normal View History

2018-10-22 04:11:27 +08:00
use na::{Real, UnitQuaternion, U4};
2018-10-22 04:11:27 +08:00
use aliases::{Qua, TMat4, TVec, TVec3};
/// 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> {
let q = UnitQuaternion::new_unchecked(*x);
let a = q.euler_angles();
2018-09-23 20:41:56 +08:00
TVec3::new(a.2, a.1, a.0)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `>` comparison between two quaternions.
pub fn quat_greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
::greater_than(&x.coords, &y.coords)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `>=` comparison between two quaternions.
pub fn quat_greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
::greater_than_equal(&x.coords, &y.coords)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `<` comparison between two quaternions.
pub fn quat_less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
::less_than(&x.coords, &y.coords)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `<=` comparison between two quaternions.
pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
::less_than_equal(&x.coords, &y.coords)
}
/// 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-23 21:59:24 +08:00
/// Computes a right hand look-at quaternion
///
/// # Parameters
///
/// * `direction` - Direction vector point at where to look
/// * `up` - Object up vector
///
2018-09-23 20:41:56 +08:00
pub fn quat_look_at<N: Real>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
quat_look_at_rh(direction, up)
}
/// 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-12-29 19:12:56 +08:00
UnitQuaternion::look_at_lh(direction, up).into_inner()
}
/// 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-12-29 19:12:56 +08:00
UnitQuaternion::look_at_rh(direction, up).into_inner()
}
2018-10-16 22:48:31 +08:00
/// The "roll" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_roll<N: Real>(x: &Qua<N>) -> N {
// FIXME: optimize this.
quat_euler_angles(x).z
}
2018-10-16 22:48:31 +08:00
/// The "yaw" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_yaw<N: Real>(x: &Qua<N>) -> N {
// FIXME: optimize this.
quat_euler_angles(x).y
}
2018-10-16 22:48:31 +08:00
/// The "pitch" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_pitch<N: Real>(x: &Qua<N>) -> N {
// FIXME: optimize this.
quat_euler_angles(x).x
}