pub struct Quaternion { /* private fields */ }
Implementations
sourceimpl Quaternion
impl Quaternion
sourcepub fn dot_product(&self, other: &Quaternion) -> f32
pub fn dot_product(&self, other: &Quaternion) -> f32
A Quaternion
sourcepub fn rotation_angle(&self) -> f32
pub fn rotation_angle(&self) -> f32
sourcepub fn rotation_axis(&self) -> f32
pub fn rotation_axis(&self) -> f32
vector3
an allocated 3-float array
sourcepub fn init(&mut self, angle: f32, x: f32, y: f32, z: f32)
pub fn init(&mut self, angle: f32, x: f32, y: f32, z: f32)
Initializes a quaternion that rotates angle
degrees around the
axis vector (x
, y
, z
). The axis vector does not need to be
normalized.
angle
The angle you want to rotate around the given axis
x
The x component of your axis vector about which you want to rotate.
y
The y component of your axis vector about which you want to rotate.
z
The z component of your axis vector about which you want to rotate.
sourcepub fn init_from_array(&mut self, array: &[f32])
pub fn init_from_array(&mut self, array: &[f32])
Initializes a [w (x, y,z)] quaternion directly from an array of 4 floats: w,x,y,z.
array
An array of 4 floats w,(x,y,z)
sourcepub fn init_from_euler(&mut self, euler: &Euler)
pub fn init_from_euler(&mut self, euler: &Euler)
euler
A Euler
with which to initialize the quaternion
sourcepub fn init_from_matrix(&mut self, matrix: &Matrix)
pub fn init_from_matrix(&mut self, matrix: &Matrix)
Initializes a quaternion from a rotation matrix.
matrix
A rotation matrix with which to initialize the quaternion
sourcepub fn init_from_quaternion(&mut self, src: &mut Quaternion)
pub fn init_from_quaternion(&mut self, src: &mut Quaternion)
src
A Quaternion
with which to initialize self
sourcepub fn init_from_x_rotation(&mut self, angle: f32)
pub fn init_from_x_rotation(&mut self, angle: f32)
sourcepub fn init_from_y_rotation(&mut self, angle: f32)
pub fn init_from_y_rotation(&mut self, angle: f32)
angle
The angle to rotate around the y axis
sourcepub fn init_from_z_rotation(&mut self, angle: f32)
pub fn init_from_z_rotation(&mut self, angle: f32)
angle
The angle to rotate around the z axis
sourcepub fn init_identity(&mut self)
pub fn init_identity(&mut self)
Initializes the quaternion with the canonical quaternion identity [1 (0, 0, 0)] which represents no rotation. Multiplying a quaternion with this identity leaves the quaternion unchanged.
You might also want to consider using
get_static_identity_quaternion
.
sourcepub fn multiply(&mut self, left: &Quaternion, right: &Quaternion)
pub fn multiply(&mut self, left: &Quaternion, right: &Quaternion)
This combines the rotations of two quaternions into self
. The
operation is not commutative so the order is important because AxB
!= BxA. follows the standard convention for quaternions here
so the rotations are applied right
to left
. This is similar to the
combining of matrices.
It is possible to multiply the a
quaternion in-place, so
self
can be equal to a
but can’t be equal to b
.
left
The second Quaternion
rotation to apply
right
The first Quaternion
rotation to apply
sourcepub fn nlerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)
pub fn nlerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)
Performs a normalized linear interpolation between two quaternions.
That is it does a linear interpolation of the quaternion components
and then normalizes the result. This will follow the shortest arc
between the two orientations (just like the slerp
function) but
will not progress at a constant speed. Unlike slerp
nlerp is
commutative which is useful if you are blending animations
together. (I.e. nlerp (tmp, a, b) followed by nlerp (result, tmp,
d) is the same as nlerp (tmp, a, d) followed by nlerp (result, tmp,
b)). Finally nlerp is cheaper than slerp so it can be a good choice
if you don’t need the constant speed property of the slerp
function.
Notable properties:
commutative: Yes
constant velocity: No
torque minimal (travels along the surface of the 4-sphere): Yes
faster than Quaternion::slerp
a
The first Quaternion
b
The second Quaternion
t
The factor in the range 0..1 used to interpolate between
quaterion a
and b
.
sourcepub fn slerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)
pub fn slerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)
Performs a spherical linear interpolation between two quaternions.
Noteable properties:
commutative: No
constant velocity: Yes
torque minimal (travels along the surface of the 4-sphere): Yes
more expensive than Quaternion::nlerp
a
The first Quaternion
b
The second Quaternion
t
The factor in the range 0..1 used to interpolate between
quaternion a
and b
.
sourcepub fn squad(
&mut self,
prev: &Quaternion,
a: &Quaternion,
b: &Quaternion,
next: &Quaternion,
t: f32
)
pub fn squad(
&mut self,
prev: &Quaternion,
a: &Quaternion,
b: &Quaternion,
next: &Quaternion,
t: f32
)
Trait Implementations
sourceimpl Debug for Quaternion
impl Debug for Quaternion
sourceimpl PartialEq<Quaternion> for Quaternion
impl PartialEq<Quaternion> for Quaternion
sourceimpl PartialOrd<Quaternion> for Quaternion
impl PartialOrd<Quaternion> for Quaternion
sourcefn partial_cmp(&self, other: &Quaternion) -> Option<Ordering>
fn partial_cmp(&self, other: &Quaternion) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Quaternion
Auto Trait Implementations
impl RefUnwindSafe for Quaternion
impl Send for Quaternion
impl Sync for Quaternion
impl Unpin for Quaternion
impl UnwindSafe for Quaternion
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Clamp<T> for T where
T: PartialOrd<T>,
impl<T> Clamp<T> for T where
T: PartialOrd<T>,
fn clamped(self, min: T, max: T) -> T
sourceimpl<Fr, To> IntoColor<To> for Fr where
To: FromColor<Fr>,
impl<Fr, To> IntoColor<To> for Fr where
To: FromColor<Fr>,
sourcefn into_color(self) -> To
fn into_color(self) -> To
Convert into color
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> SetParameter for T
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
Sets value
as a parameter of self
.