forked from M-Labs/nalgebra
Add a quat_ perfix to all quaternion functions.
This commit is contained in:
parent
5ebb1fa635
commit
81745b5464
@ -7,4 +7,5 @@
|
|||||||
* Function overload: the vec version is suffixed by _vec
|
* Function overload: the vec version is suffixed by _vec
|
||||||
* Function overload: the methods taking an epsilon as suffixed by _eps
|
* Function overload: the methods taking an epsilon as suffixed by _eps
|
||||||
* L1Norm and L2Norm between two vectors have been renamed: l1_distance, l2_distance
|
* L1Norm and L2Norm between two vectors have been renamed: l1_distance, l2_distance
|
||||||
* Matrix columnwise comparisons suffixed by _columns, e.g., `equal` -> `equal_columns`
|
* Matrix columnwise comparisons suffixed by _columns, e.g., `equal` -> `equal_columns`
|
||||||
|
* All quaternion functions are prefixed by quat_
|
@ -8,6 +8,11 @@ pub use self::scalar_common::*;
|
|||||||
pub use self::scalar_constants::*;
|
pub use self::scalar_constants::*;
|
||||||
pub use self::vector_common::*;
|
pub use self::vector_common::*;
|
||||||
pub use self::vector_relational::*;
|
pub use self::vector_relational::*;
|
||||||
|
pub use self::quaternion_common::*;
|
||||||
|
pub use self::quaternion_geometric::*;
|
||||||
|
pub use self::quaternion_relational::*;
|
||||||
|
pub use self::quaternion_transform::*;
|
||||||
|
pub use self::quaternion_trigonometric::*;
|
||||||
|
|
||||||
|
|
||||||
mod matrix_clip_space;
|
mod matrix_clip_space;
|
||||||
@ -17,4 +22,9 @@ mod matrix_transform;
|
|||||||
mod scalar_common;
|
mod scalar_common;
|
||||||
mod scalar_constants;
|
mod scalar_constants;
|
||||||
mod vector_common;
|
mod vector_common;
|
||||||
mod vector_relational;
|
mod vector_relational;
|
||||||
|
mod quaternion_common;
|
||||||
|
mod quaternion_geometric;
|
||||||
|
mod quaternion_relational;
|
||||||
|
mod quaternion_transform;
|
||||||
|
mod quaternion_trigonometric;
|
@ -3,33 +3,33 @@ use na::{self, Real, Unit};
|
|||||||
use aliases::Qua;
|
use aliases::Qua;
|
||||||
|
|
||||||
/// The conjugate of `q`.
|
/// The conjugate of `q`.
|
||||||
pub fn conjugate<N: Real>(q: &Qua<N>) -> Qua<N> {
|
pub fn quat_conjugate<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
q.conjugate()
|
q.conjugate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The inverse of `q`.
|
/// The inverse of `q`.
|
||||||
pub fn inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
|
pub fn quat_inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
q.try_inverse().unwrap_or(na::zero())
|
q.try_inverse().unwrap_or(na::zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn isinf<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
//pub fn quat_isinf<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
||||||
// x.coords.map(|e| e.is_inf())
|
// x.coords.map(|e| e.is_inf())
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//pub fn isnan<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
//pub fn quat_isnan<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
||||||
// x.coords.map(|e| e.is_nan())
|
// x.coords.map(|e| e.is_nan())
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// Interpolate linearly between `x` and `y`.
|
/// Interpolate linearly between `x` and `y`.
|
||||||
pub fn lerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_lerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
x.lerp(y, a)
|
x.lerp(y, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
//pub fn quat_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
// x * (N::one() - a) + y * a
|
// x * (N::one() - a) + y * a
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// Interpolate spherically between `x` and `y`.
|
/// Interpolate spherically between `x` and `y`.
|
||||||
pub fn slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
||||||
}
|
}
|
@ -3,26 +3,26 @@ use na::Real;
|
|||||||
use aliases::Qua;
|
use aliases::Qua;
|
||||||
|
|
||||||
/// Multiplies two quaternions.
|
/// Multiplies two quaternions.
|
||||||
pub fn cross<N: Real>(q1: &Qua<N>, q2: &Qua<N>) -> Qua<N> {
|
pub fn quat_cross<N: Real>(q1: &Qua<N>, q2: &Qua<N>) -> Qua<N> {
|
||||||
q1 * q2
|
q1 * q2
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The scalar product of two quaternions.
|
/// The scalar product of two quaternions.
|
||||||
pub fn dot<N: Real>(x: &Qua<N>, y: &Qua<N>) -> N {
|
pub fn quat_dot<N: Real>(x: &Qua<N>, y: &Qua<N>) -> N {
|
||||||
x.dot(y)
|
x.dot(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The magnitude of the quaternion `q`.
|
/// The magnitude of the quaternion `q`.
|
||||||
pub fn length<N: Real>(q: &Qua<N>) -> N {
|
pub fn quat_length<N: Real>(q: &Qua<N>) -> N {
|
||||||
q.norm()
|
q.norm()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The magnitude of the quaternion `q`.
|
/// The magnitude of the quaternion `q`.
|
||||||
pub fn magnitude<N: Real>(q: &Qua<N>) -> N {
|
pub fn quat_magnitude<N: Real>(q: &Qua<N>) -> N {
|
||||||
q.norm()
|
q.norm()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Normalizes the quaternion `q`.
|
/// Normalizes the quaternion `q`.
|
||||||
pub fn normalize<N: Real>(q: &Qua<N>) -> Qua<N> {
|
pub fn quat_normalize<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
q.normalize()
|
q.normalize()
|
||||||
}
|
}
|
@ -4,21 +4,21 @@ use na::{Real, U4};
|
|||||||
use aliases::{Qua, Vec};
|
use aliases::{Qua, Vec};
|
||||||
|
|
||||||
/// Component-wise equality comparison between two quaternions.
|
/// Component-wise equality comparison between two quaternions.
|
||||||
pub fn equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::equal(&x.coords, &y.coords)
|
::equal(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise approximate equality comparison between two quaternions.
|
/// Component-wise approximate equality comparison between two quaternions.
|
||||||
pub fn equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
pub fn quat_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
||||||
::equal_eps(&x.coords, &y.coords, epsilon)
|
::equal_eps(&x.coords, &y.coords, epsilon)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise non-equality comparison between two quaternions.
|
/// Component-wise non-equality comparison between two quaternions.
|
||||||
pub fn not_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_not_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::not_equal(&x.coords, &y.coords)
|
::not_equal(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise approximate non-equality comparison between two quaternions.
|
/// Component-wise approximate non-equality comparison between two quaternions.
|
||||||
pub fn not_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
pub fn quat_not_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
||||||
::not_equal_eps(&x.coords, &y.coords, epsilon)
|
::not_equal_eps(&x.coords, &y.coords, epsilon)
|
||||||
}
|
}
|
@ -3,25 +3,25 @@ use na::{Real, U3, UnitQuaternion, Unit};
|
|||||||
use aliases::{Vec, Qua};
|
use aliases::{Vec, Qua};
|
||||||
|
|
||||||
/// Computes the quaternion exponential.
|
/// Computes the quaternion exponential.
|
||||||
pub fn exp<N: Real>(q: &Qua<N>) -> Qua<N> {
|
pub fn quat_exp<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
q.exp()
|
q.exp()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the quaternion logarithm.
|
/// Computes the quaternion logarithm.
|
||||||
pub fn log<N: Real>(q: &Qua<N>) -> Qua<N> {
|
pub fn quat_log<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
q.ln()
|
q.ln()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Raises the quaternion `q` to the power `y`.
|
/// Raises the quaternion `q` to the power `y`.
|
||||||
pub fn pow<N: Real>(q: &Qua<N>, y: N) -> Qua<N> {
|
pub fn quat_pow<N: Real>(q: &Qua<N>, y: N) -> Qua<N> {
|
||||||
q.powf(y)
|
q.powf(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
|
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
|
||||||
pub fn rotate<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
pub fn quat_rotate<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
||||||
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn sqrt<N: Real>(q: &Qua<N>) -> Qua<N> {
|
//pub fn quat_sqrt<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||||
// unimplemented!()
|
// unimplemented!()
|
||||||
//}
|
//}
|
@ -3,17 +3,17 @@ use na::{Real, U3, Unit, UnitQuaternion, Vector3};
|
|||||||
use aliases::{Vec, Qua};
|
use aliases::{Vec, Qua};
|
||||||
|
|
||||||
/// The rotation angle of this quaternion assumed to be normalized.
|
/// The rotation angle of this quaternion assumed to be normalized.
|
||||||
pub fn angle<N: Real>(x: &Qua<N>) -> N {
|
pub fn quat_angle<N: Real>(x: &Qua<N>) -> N {
|
||||||
UnitQuaternion::from_quaternion(*x).angle()
|
UnitQuaternion::from_quaternion(*x).angle()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a quaternion from an axis and an angle.
|
/// Creates a quaternion from an axis and an angle.
|
||||||
pub fn angle_axis<N: Real>(angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
pub fn quat_angle_axis<N: Real>(angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
||||||
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rotation axis of a quaternion assumed to be normalized.
|
/// The rotation axis of a quaternion assumed to be normalized.
|
||||||
pub fn axis<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
|
pub fn quat_axis<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
|
||||||
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
|
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
|
||||||
a.unwrap()
|
a.unwrap()
|
||||||
} else {
|
} else {
|
@ -11,6 +11,7 @@ pub use self::matrix_inverse::*;
|
|||||||
//pub use self::round::*;
|
//pub use self::round::*;
|
||||||
pub use self::type_ptr::*;
|
pub use self::type_ptr::*;
|
||||||
//pub use self::ulp::*;
|
//pub use self::ulp::*;
|
||||||
|
pub use self::quaternion::*;
|
||||||
|
|
||||||
|
|
||||||
//mod bitfield;
|
//mod bitfield;
|
||||||
@ -23,4 +24,5 @@ mod matrix_inverse;
|
|||||||
//mod reciprocal;
|
//mod reciprocal;
|
||||||
//mod round;
|
//mod round;
|
||||||
mod type_ptr;
|
mod type_ptr;
|
||||||
//mod ulp;
|
//mod ulp;
|
||||||
|
mod quaternion;
|
@ -4,41 +4,41 @@ use aliases::{Qua, Vec, Mat};
|
|||||||
|
|
||||||
|
|
||||||
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
||||||
pub fn euler_angles<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
|
pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
|
||||||
let q = UnitQuaternion::new_unchecked(*x);
|
let q = UnitQuaternion::new_unchecked(*x);
|
||||||
let a = q.to_euler_angles();
|
let a = q.to_euler_angles();
|
||||||
Vector3::new(a.2, a.1, a.0)
|
Vector3::new(a.2, a.1, a.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise `>` comparison between two quaternions.
|
/// Component-wise `>` comparison between two quaternions.
|
||||||
pub fn greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::greater_than(&x.coords, &y.coords)
|
::greater_than(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise `>=` comparison between two quaternions.
|
/// Component-wise `>=` comparison between two quaternions.
|
||||||
pub fn greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::greater_than_equal(&x.coords, &y.coords)
|
::greater_than_equal(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise `<` comparison between two quaternions.
|
/// Component-wise `<` comparison between two quaternions.
|
||||||
pub fn less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::less_than(&x.coords, &y.coords)
|
::less_than(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise `<=` comparison between two quaternions.
|
/// Component-wise `<=` comparison between two quaternions.
|
||||||
pub fn less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||||
::less_than_equal(&x.coords, &y.coords)
|
::less_than_equal(&x.coords, &y.coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Convert a quaternion to a rotation matrix.
|
/// Convert a quaternion to a rotation matrix.
|
||||||
pub fn mat3_cast<N: Real>(x: Qua<N>) -> Mat<N, U3, U3> {
|
pub fn quat_mat3_cast<N: Real>(x: Qua<N>) -> Mat<N, U3, U3> {
|
||||||
let q = UnitQuaternion::new_unchecked(x);
|
let q = UnitQuaternion::new_unchecked(x);
|
||||||
q.to_rotation_matrix().unwrap()
|
q.to_rotation_matrix().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a quaternion to a rotation matrix in homogeneous coordinates.
|
/// Convert a quaternion to a rotation matrix in homogeneous coordinates.
|
||||||
pub fn mat4_cast<N: Real>(x: Qua<N>) -> Mat<N, U4, U4> {
|
pub fn quat_mat4_cast<N: Real>(x: Qua<N>) -> Mat<N, U4, U4> {
|
||||||
let q = UnitQuaternion::new_unchecked(x);
|
let q = UnitQuaternion::new_unchecked(x);
|
||||||
q.to_homogeneous()
|
q.to_homogeneous()
|
||||||
}
|
}
|
||||||
@ -70,19 +70,19 @@ pub fn quat_look_at_rh<N: Real>(direction: &Vec<N, U3>, up: &Vec<N, U3>) -> Qua<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The "roll" euler angle of the quaternion `x` assumed to be normalized.
|
/// The "roll" euler angle of the quaternion `x` assumed to be normalized.
|
||||||
pub fn roll<N: Real>(x: &Qua<N>) -> N {
|
pub fn quat_roll<N: Real>(x: &Qua<N>) -> N {
|
||||||
// FIXME: optimize this.
|
// FIXME: optimize this.
|
||||||
euler_angles(x).z
|
quat_euler_angles(x).z
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The "yaw" euler angle of the quaternion `x` assumed to be normalized.
|
/// The "yaw" euler angle of the quaternion `x` assumed to be normalized.
|
||||||
pub fn yaw<N: Real>(x: &Qua<N>) -> N {
|
pub fn quat_yaw<N: Real>(x: &Qua<N>) -> N {
|
||||||
// FIXME: optimize this.
|
// FIXME: optimize this.
|
||||||
euler_angles(x).y
|
quat_euler_angles(x).y
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The "pitch" euler angle of the quaternion `x` assumed to be normalized.
|
/// The "pitch" euler angle of the quaternion `x` assumed to be normalized.
|
||||||
pub fn pitch<N: Real>(x: &Qua<N>) -> N {
|
pub fn quat_pitch<N: Real>(x: &Qua<N>) -> N {
|
||||||
// FIXME: optimize this.
|
// FIXME: optimize this.
|
||||||
euler_angles(x).x
|
quat_euler_angles(x).x
|
||||||
}
|
}
|
@ -17,6 +17,7 @@ pub use self::transform2::*;
|
|||||||
pub use self::transform2d::*;
|
pub use self::transform2d::*;
|
||||||
pub use self::vector_angle::*;
|
pub use self::vector_angle::*;
|
||||||
pub use self::vector_query::*;
|
pub use self::vector_query::*;
|
||||||
|
pub use self::quaternion::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -35,4 +36,5 @@ mod transform;
|
|||||||
mod transform2;
|
mod transform2;
|
||||||
mod transform2d;
|
mod transform2d;
|
||||||
mod vector_angle;
|
mod vector_angle;
|
||||||
mod vector_query;
|
mod vector_query;
|
||||||
|
mod quaternion;
|
@ -3,77 +3,77 @@ use na::{Real, Unit, Rotation3, Vector4, UnitQuaternion, U3, U4};
|
|||||||
use aliases::{Qua, Vec, Mat};
|
use aliases::{Qua, Vec, Mat};
|
||||||
|
|
||||||
/// Rotate the vector `v` by the quaternion `q` assumed to be normalized.
|
/// Rotate the vector `v` by the quaternion `q` assumed to be normalized.
|
||||||
pub fn cross<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
|
pub fn quat_cross<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
|
||||||
UnitQuaternion::new_unchecked(*q) * v
|
UnitQuaternion::new_unchecked(*q) * v
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized.
|
/// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized.
|
||||||
pub fn cross2<N: Real>(v: &Vec<N, U3>, q: &Qua<N>) -> Vec<N, U3> {
|
pub fn quat_cross2<N: Real>(v: &Vec<N, U3>, q: &Qua<N>) -> Vec<N, U3> {
|
||||||
UnitQuaternion::new_unchecked(*q).inverse() * v
|
UnitQuaternion::new_unchecked(*q).inverse() * v
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The quaternion `w` component.
|
/// The quaternion `w` component.
|
||||||
pub fn extract_real_component<N: Real>(q: &Qua<N>) -> N {
|
pub fn quat_extract_real_component<N: Real>(q: &Qua<N>) -> N {
|
||||||
q.w
|
q.w
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Normalized linear interpolation between two quaternions.
|
/// Normalized linear interpolation between two quaternions.
|
||||||
pub fn fast_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_fast_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_unchecked(*x).nlerp(&Unit::new_unchecked(*y), a).unwrap()
|
Unit::new_unchecked(*x).nlerp(&Unit::new_unchecked(*y), a).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn intermediate<N: Real>(prev: &Qua<N>, curr: &Qua<N>, next: &Qua<N>) -> Qua<N> {
|
//pub fn quat_intermediate<N: Real>(prev: &Qua<N>, curr: &Qua<N>, next: &Qua<N>) -> Qua<N> {
|
||||||
// unimplemented!()
|
// unimplemented!()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// The squared magnitude of a quaternion `q`.
|
/// The squared magnitude of a quaternion `q`.
|
||||||
pub fn length2<N: Real>(q: &Qua<N>) -> N {
|
pub fn quat_length2<N: Real>(q: &Qua<N>) -> N {
|
||||||
q.norm_squared()
|
q.norm_squared()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The squared magnitude of a quaternion `q`.
|
/// The squared magnitude of a quaternion `q`.
|
||||||
pub fn magnitude2<N: Real>(q: &Qua<N>) -> N {
|
pub fn quat_magnitude2<N: Real>(q: &Qua<N>) -> N {
|
||||||
q.norm_squared()
|
q.norm_squared()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The quaternion representing the identity rotation.
|
/// The quaternion representing the identity rotation.
|
||||||
pub fn quat_identity<N: Real>() -> Qua<N> {
|
pub fn quat_quat_identity<N: Real>() -> Qua<N> {
|
||||||
UnitQuaternion::identity().unwrap()
|
UnitQuaternion::identity().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotates a vector by a quaternion assumed to be normalized.
|
/// Rotates a vector by a quaternion assumed to be normalized.
|
||||||
pub fn rotate<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
|
pub fn quat_rotate<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
|
||||||
UnitQuaternion::new_unchecked(*q) * v
|
UnitQuaternion::new_unchecked(*q) * v
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized.
|
/// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized.
|
||||||
pub fn rotate2<N: Real>(q: &Qua<N>, v: &Vec<N, U4>) -> Vec<N, U4> {
|
pub fn quat_rotate2<N: Real>(q: &Qua<N>, v: &Vec<N, U4>) -> Vec<N, U4> {
|
||||||
// UnitQuaternion::new_unchecked(*q) * v
|
// UnitQuaternion::new_unchecked(*q) * v
|
||||||
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0);
|
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0);
|
||||||
Vector4::new(rotated.x, rotated.y, rotated.z, v.w)
|
Vector4::new(rotated.x, rotated.y, rotated.z, v.w)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rotation required to align `orig` to `dest`.
|
/// The rotation required to align `orig` to `dest`.
|
||||||
pub fn rotation<N: Real>(orig: &Vec<N, U3>, dest: &Vec<N, U3>) -> Qua<N> {
|
pub fn quat_rotation<N: Real>(orig: &Vec<N, U3>, dest: &Vec<N, U3>) -> Qua<N> {
|
||||||
UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap()
|
UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The spherical linear interpolation between two quaternions.
|
/// The spherical linear interpolation between two quaternions.
|
||||||
pub fn short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn squad<N: Real>(q1: &Qua<N>, q2: &Qua<N>, s1: &Qua<N>, s2: &Qua<N>, h: N) -> Qua<N> {
|
//pub fn quat_squad<N: Real>(q1: &Qua<N>, q2: &Qua<N>, s1: &Qua<N>, s2: &Qua<N>, h: N) -> Qua<N> {
|
||||||
// unimplemented!()
|
// unimplemented!()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// Converts a quaternion to a rotation matrix.
|
/// Converts a quaternion to a rotation matrix.
|
||||||
pub fn to_mat3<N: Real>(x: &Qua<N>) -> Mat<N, U3, U3> {
|
pub fn quat_to_mat3<N: Real>(x: &Qua<N>) -> Mat<N, U3, U3> {
|
||||||
UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap()
|
UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a quaternion to a rotation matrix in homogenous coordinates.
|
/// Converts a quaternion to a rotation matrix in homogenous coordinates.
|
||||||
pub fn to_mat4<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> {
|
pub fn quat_to_mat4<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> {
|
||||||
UnitQuaternion::new_unchecked(*x).to_homogeneous()
|
UnitQuaternion::new_unchecked(*x).to_homogeneous()
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
use na::{Real, Rotation3, Unit, U3, U4};
|
use na::{Real, Rotation3, Unit, UnitQuaternion, U3, U4};
|
||||||
|
|
||||||
use aliases::{Vec, Mat};
|
use aliases::{Vec, Mat, Qua};
|
||||||
|
|
||||||
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
|
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
|
||||||
///
|
///
|
||||||
@ -10,4 +10,14 @@ use aliases::{Vec, Mat};
|
|||||||
/// * `axis` - Rotation axis, must be normalized.
|
/// * `axis` - Rotation axis, must be normalized.
|
||||||
pub fn rotate_normalized_axis<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
pub fn rotate_normalized_axis<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
||||||
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
|
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
|
||||||
|
///
|
||||||
|
/// # Parameters
|
||||||
|
/// * `q` - Source orientation
|
||||||
|
/// * `angle` - Angle expressed in radians.
|
||||||
|
/// * `axis` - Normalized axis of the rotation, must be normalized.
|
||||||
|
pub fn quat_rotate_normalized_axis<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
||||||
|
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap()
|
||||||
}
|
}
|
@ -37,5 +37,4 @@ mod exponential;
|
|||||||
|
|
||||||
pub mod ext;
|
pub mod ext;
|
||||||
pub mod gtc;
|
pub mod gtc;
|
||||||
pub mod gtx;
|
pub mod gtx;
|
||||||
pub mod quat;
|
|
@ -1,13 +0,0 @@
|
|||||||
use na::{Real, Unit, UnitQuaternion, U3};
|
|
||||||
|
|
||||||
use aliases::{Vec, Qua};
|
|
||||||
|
|
||||||
/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
|
|
||||||
///
|
|
||||||
/// # Parameters
|
|
||||||
/// * `q` - Source orientation
|
|
||||||
/// * `angle` - Angle expressed in radians.
|
|
||||||
/// * `axis` - Normalized axis of the rotation, must be normalized.
|
|
||||||
pub fn rotate_normalized_axis<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> Qua<N> {
|
|
||||||
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap()
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
//! Definition and operations on quaternions.
|
|
||||||
|
|
||||||
pub use self::gtc_quaternion::*;
|
|
||||||
pub use self::gtx_quaternion::*;
|
|
||||||
pub use self::gtx_rotate_normalized_axis::*;
|
|
||||||
pub use self::quaternion_common::*;
|
|
||||||
pub use self::quaternion_geometric::*;
|
|
||||||
pub use self::quaternion_relational::*;
|
|
||||||
pub use self::quaternion_transform::*;
|
|
||||||
pub use self::quaternion_trigonometric::*;
|
|
||||||
|
|
||||||
mod gtc_quaternion;
|
|
||||||
mod gtx_quaternion;
|
|
||||||
mod gtx_rotate_normalized_axis;
|
|
||||||
mod quaternion_common;
|
|
||||||
mod quaternion_geometric;
|
|
||||||
mod quaternion_relational;
|
|
||||||
mod quaternion_transform;
|
|
||||||
mod quaternion_trigonometric;
|
|
Loading…
Reference in New Issue
Block a user