use na::{self, Real, U3, U4, UnitQuaternion, Vector3, Rotation3}; use aliases::{Qua, Vec, Mat}; /// Euler angles of the quaternion as (pitch, yaw, roll). pub fn euler_angles(x: &Qua) -> Vec { let q = UnitQuaternion::new_unchecked(*x); let a = q.to_euler_angles(); Vector3::new(a.2, a.1, a.0) } pub fn greater_than(x: &Qua, y: &Qua) -> Vec { ::greater_than(&x.coords, &y.coords) } pub fn greater_than_equal(x: &Qua, y: &Qua) -> Vec { ::greater_than_equal(&x.coords, &y.coords) } pub fn less_than(x: &Qua, y: &Qua) -> Vec { ::less_than(&x.coords, &y.coords) } pub fn less_than_equal(x: &Qua, y: &Qua) -> Vec { ::less_than_equal(&x.coords, &y.coords) } pub fn mat3_cast(x: Qua) -> Mat { let q = UnitQuaternion::new_unchecked(x); q.to_rotation_matrix().unwrap() } pub fn mat4_cast(x: Qua) -> Mat { let q = UnitQuaternion::new_unchecked(x); q.to_homogeneous() } pub fn quat_cast(x: Mat) -> Qua { let rot = Rotation3::from_matrix_unchecked(x); UnitQuaternion::from_rotation_matrix(&rot).unwrap() } pub fn quat_cast2(x: Mat) -> Qua { quat_cast(x.fixed_slice::(0, 0).into_owned()) } pub fn quat_look_at(direction: &Vec, up: &Vec) -> Qua { quat_look_at_rh(direction, up) } pub fn quat_look_at_lh(direction: &Vec, up: &Vec) -> Qua { UnitQuaternion::look_at_lh(direction, up).unwrap() } pub fn quat_look_at_rh(direction: &Vec, up: &Vec) -> Qua { UnitQuaternion::look_at_rh(direction, up).unwrap() } pub fn roll(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).z } pub fn yaw(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).y } pub fn pitch(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).x }