pub struct Quaternion(/* private fields */);Expand description
Represents a quaternion in 4D space.
Implementations§
source§impl Quaternion
impl Quaternion
sourcepub const ZERO: Quaternion = _
pub const ZERO: Quaternion = _
The zero quaternion.
sourcepub const UNIT: Quaternion = _
pub const UNIT: Quaternion = _
The identity quaternion.
sourcepub const fn new(w: f32, i: f32, j: f32, k: f32) -> Self
pub const fn new(w: f32, i: f32, j: f32, k: f32) -> Self
Creates a new quaternion with the given components.
§Parameters
w- The real component of the quaternion.i- The i imaginary component of the quaternion.j- The j imaginary component of the quaternion.k- The k imaginary component of the quaternion.
sourcepub const fn from_vector4(vec: Vector4) -> Self
pub const fn from_vector4(vec: Vector4) -> Self
Creates a new quaternion from a 4D vector.
§Parameters
vec- The vector to create the quaternion from.
sourcepub const fn from_vec4(vec: &Vec4) -> Self
pub const fn from_vec4(vec: &Vec4) -> Self
Creates a new quaternion from a 4D vector.
§Parameters
vec- The vector to create the quaternion from.
sourcepub fn from_angle_axis<A: Angle>(angle: A, axis: &Vec3) -> Self
pub fn from_angle_axis<A: Angle>(angle: A, axis: &Vec3) -> Self
Creates a quaternion from an angle (in radians) and an axis vector (x, y, z)
§Parameters
angle- The angle of rotation.axis- The axis of rotation.
sourcepub fn from_pitch<A: Angle>(angle: A) -> Self
pub fn from_pitch<A: Angle>(angle: A) -> Self
sourcepub fn from_euler_angles<A: Angle>(yaw: A, pitch: A, roll: A) -> Self
pub fn from_euler_angles<A: Angle>(yaw: A, pitch: A, roll: A) -> Self
Creates a new quaternion from a set of Euler angles.
§Parameters
yaw- The yaw angle.pitch- The pitch angle.roll- The roll angle.
source§impl Quaternion
impl Quaternion
sourcepub fn as_mut_vec4(&mut self) -> &mut Vec4
pub fn as_mut_vec4(&mut self) -> &mut Vec4
Converts the quaternion to a mutable 4D vector.
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Returns this quaternion as a mutable slice of f32.
sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Returns this vector as a mutable ptr of f32.
sourcepub fn to_matrix4(&self) -> Matrix4
pub fn to_matrix4(&self) -> Matrix4
Returns the rotation matrix representation of the quaternion.
source§impl Quaternion
impl Quaternion
Properties
sourcepub fn normalized(&self) -> Self
pub fn normalized(&self) -> Self
Returns the normalized quaternion.
sourcepub fn euler_angles<A: Angle>(&self) -> (A, A, A)
pub fn euler_angles<A: Angle>(&self) -> (A, A, A)
Returns the euler angles of the quaternion in (yaw, pitch, roll) order.
sourcepub fn angle_axis<A: Angle>(&self) -> (A, Vector3)
pub fn angle_axis<A: Angle>(&self) -> (A, Vector3)
Returns the angle (in radians) and axis (x, y, z) of the quaternion
sourcepub fn w_mut(&mut self) -> &mut f32
pub fn w_mut(&mut self) -> &mut f32
Retrieves a mutable reference to the real component of the quaternion.
sourcepub fn i_mut(&mut self) -> &mut f32
pub fn i_mut(&mut self) -> &mut f32
Retrieves a mutable reference to the i imaginary component of the quaternion.
sourcepub fn j_mut(&mut self) -> &mut f32
pub fn j_mut(&mut self) -> &mut f32
Retrieves a mutable reference to the j imaginary component of the quaternion.
sourcepub fn k_mut(&mut self) -> &mut f32
pub fn k_mut(&mut self) -> &mut f32
Retrieves a mutable reference to the k imaginary component of the quaternion.
sourcepub fn wi_mut(&mut self) -> &mut Vec2
pub fn wi_mut(&mut self) -> &mut Vec2
Returns a mutable reference to the first two components of the quaternion.
sourcepub fn ij_mut(&mut self) -> &mut Vec2
pub fn ij_mut(&mut self) -> &mut Vec2
Returns a mutable reference to the middle two components of the quaternion.
sourcepub fn jk_mut(&mut self) -> &mut Vec2
pub fn jk_mut(&mut self) -> &mut Vec2
Returns a mutable reference to the last two components of the quaternion.
source§impl Quaternion
impl Quaternion
source§impl Quaternion
impl Quaternion
sourcepub fn rotate_by_angle_axis<A: Angle>(&self, angle: A, axis: &Vec3) -> Self
pub fn rotate_by_angle_axis<A: Angle>(&self, angle: A, axis: &Vec3) -> Self
Rotates the quaternion by an angle (in radians) and an axis vector (x, y, z).
§Parameters
angle- The angle of rotation.axis- The axis of rotation.
sourcepub fn rotate_by_yaw<A: Angle>(&self, angle: A) -> Self
pub fn rotate_by_yaw<A: Angle>(&self, angle: A) -> Self
sourcepub fn rotate_by_pitch<A: Angle>(&self, angle: A) -> Self
pub fn rotate_by_pitch<A: Angle>(&self, angle: A) -> Self
sourcepub fn rotate_by_roll<A: Angle>(&self, angle: A) -> Self
pub fn rotate_by_roll<A: Angle>(&self, angle: A) -> Self
sourcepub fn rotate_by_euler_angles<A: Angle>(
&self,
yaw: A,
pitch: A,
roll: A,
) -> Self
pub fn rotate_by_euler_angles<A: Angle>( &self, yaw: A, pitch: A, roll: A, ) -> Self
Rotates the quaternion by a set of Euler angles.
§Parameters
yaw- The yaw angle.pitch- The pitch angle.roll- The roll angle.
sourcepub fn rotate_by_mat4(&self, matrix: &Mat4) -> Self
pub fn rotate_by_mat4(&self, matrix: &Mat4) -> Self
Rotates the quaternion by a 4x4 matrix encoding a rotation.
§Parameters
matrix- The rotation matrix to rotate by.
sourcepub fn rotate_vec3(&self, vec: &Vec3) -> Vector3
pub fn rotate_vec3(&self, vec: &Vec3) -> Vector3
Rotates a 3D vector by the angle represented by the quaternion.
sourcepub fn rotate_vec4(&self, vec: &Vec4) -> Vector4
pub fn rotate_vec4(&self, vec: &Vec4) -> Vector4
Rotates a 3D vector by the angle represented by the quaternion.
§Parameters
vec- The vector to rotate.
Trait Implementations§
source§impl Add<f32> for &Quaternion
impl Add<f32> for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
+ operator.source§impl Add for &Quaternion
impl Add for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
+ operator.source§fn add(self, rhs: &Quaternion) -> Quaternion
fn add(self, rhs: &Quaternion) -> Quaternion
+ operation. Read moresource§impl Add for Quaternion
impl Add for Quaternion
source§type Output = Quaternion
type Output = Quaternion
+ operator.source§fn add(self, rhs: Quaternion) -> Quaternion
fn add(self, rhs: Quaternion) -> Quaternion
+ operation. Read moresource§impl AddAssign<&Quaternion> for Quaternion
impl AddAssign<&Quaternion> for Quaternion
source§fn add_assign(&mut self, rhs: &Quaternion)
fn add_assign(&mut self, rhs: &Quaternion)
+= operation. Read moresource§impl AddAssign<f32> for Quaternion
impl AddAssign<f32> for Quaternion
source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moresource§impl AlmostEq for Quaternion
impl AlmostEq for Quaternion
source§impl Clone for Quaternion
impl Clone for Quaternion
source§fn clone(&self) -> Quaternion
fn clone(&self) -> Quaternion
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for Quaternion
impl Debug for Quaternion
source§impl Default for Quaternion
impl Default for Quaternion
source§impl Display for Quaternion
impl Display for Quaternion
source§impl Div<f32> for &Quaternion
impl Div<f32> for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
/ operator.source§impl DivAssign<f32> for Quaternion
impl DivAssign<f32> for Quaternion
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moresource§impl Dot<Quaternion> for Vec4
impl Dot<Quaternion> for Vec4
source§impl Dot<Vec4> for Quaternion
impl Dot<Vec4> for Quaternion
source§impl Dot for Quaternion
impl Dot for Quaternion
source§impl From<&Vec4> for Quaternion
impl From<&Vec4> for Quaternion
source§impl From<Vector4> for Quaternion
impl From<Vector4> for Quaternion
source§impl Lerp for Quaternion
impl Lerp for Quaternion
source§impl Mul<&Quaternion> for Quaternion
impl Mul<&Quaternion> for Quaternion
source§type Output = Quaternion
type Output = Quaternion
* operator.source§fn mul(self, rhs: &Quaternion) -> Quaternion
fn mul(self, rhs: &Quaternion) -> Quaternion
* operation. Read moresource§impl Mul<&Quaternion> for f32
impl Mul<&Quaternion> for f32
source§type Output = Quaternion
type Output = Quaternion
* operator.source§fn mul(self, rhs: &Quaternion) -> Quaternion
fn mul(self, rhs: &Quaternion) -> Quaternion
* operation. Read moresource§impl Mul<Quaternion> for &Quaternion
impl Mul<Quaternion> for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
* operator.source§fn mul(self, rhs: Quaternion) -> Quaternion
fn mul(self, rhs: Quaternion) -> Quaternion
* operation. Read moresource§impl Mul<f32> for &Quaternion
impl Mul<f32> for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
* operator.source§impl Mul for &Quaternion
impl Mul for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
* operator.source§fn mul(self, rhs: &Quaternion) -> Quaternion
fn mul(self, rhs: &Quaternion) -> Quaternion
* operation. Read moresource§impl Mul for Quaternion
impl Mul for Quaternion
source§type Output = Quaternion
type Output = Quaternion
* operator.source§fn mul(self, rhs: Quaternion) -> Quaternion
fn mul(self, rhs: Quaternion) -> Quaternion
* operation. Read moresource§impl MulAssign<&Quaternion> for Quaternion
impl MulAssign<&Quaternion> for Quaternion
source§fn mul_assign(&mut self, rhs: &Quaternion)
fn mul_assign(&mut self, rhs: &Quaternion)
*= operation. Read moresource§impl MulAssign<f32> for Quaternion
impl MulAssign<f32> for Quaternion
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moresource§impl MulAssign for Quaternion
impl MulAssign for Quaternion
source§fn mul_assign(&mut self, rhs: Quaternion)
fn mul_assign(&mut self, rhs: Quaternion)
*= operation. Read moresource§impl Near for Quaternion
impl Near for Quaternion
source§impl PartialEq for Quaternion
impl PartialEq for Quaternion
source§impl PartialOrd for Quaternion
impl PartialOrd for Quaternion
source§impl Sub<f32> for &Quaternion
impl Sub<f32> for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
- operator.source§impl Sub for &Quaternion
impl Sub for &Quaternion
source§type Output = Quaternion
type Output = Quaternion
- operator.source§fn sub(self, rhs: &Quaternion) -> Quaternion
fn sub(self, rhs: &Quaternion) -> Quaternion
- operation. Read moresource§impl SubAssign<f32> for Quaternion
impl SubAssign<f32> for Quaternion
source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
-= operation. Read moreimpl Copy for Quaternion
impl StructuralPartialEq for Quaternion
Auto Trait Implementations§
impl Freeze for Quaternion
impl RefUnwindSafe for Quaternion
impl Send for Quaternion
impl Sync for Quaternion
impl Unpin for Quaternion
impl UnwindSafe for Quaternion
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)