Skip to main content

Quat

Struct Quat 

Source
pub struct Quat { /* private fields */ }
Expand description

Unit Hamilton quaternion (x, y, z, w) representing gimbal-lock-free 3D rotations.

Implementations§

Source§

impl Quat

Hamilton quaternion algebra, Euler/matrix conversions, SLERP/NLERP, and Blender basis conversion for Quat.

Source

pub const fn identity() -> Self

Returns the identity quaternion (0, 0, 0, 1).

§Returns
  • Self - Identity quaternion.
Source

pub const fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> Self

Constructs a quaternion from raw (x, y, z, w) components.

§Arguments
  • f32 - Imaginary X component.
  • f32 - Imaginary Y component.
  • f32 - Imaginary Z component.
  • f32 - Real W component.
§Returns
  • Self - Constructed quaternion.
Source

pub const fn from_array(values: [f32; 4]) -> Self

Constructs a quaternion from glTF [x, y, z, w] ordering.

§Arguments
  • [f32; 4] - Array [x, y, z, w].
§Returns
  • Self - Constructed quaternion.
Source

pub fn to_array(&self) -> [f32; 4]

Packs this quaternion into glTF [x, y, z, w] ordering.

§Arguments
  • &Self - Quaternion reference.
§Returns
  • [f32; 4] - Component array [x, y, z, w].
Source

pub fn dot(self, rhs: Self) -> f32

Computes the 4D dot product between two quaternions.

§Arguments
  • Self - Left quaternion.
  • Self - Right quaternion.
§Returns
  • f32 - Dot product scalar.
Source

pub fn normalize(self) -> Self

Returns the unit-length normalized quaternion (or identity when degenerate).

§Arguments
  • Self - Source quaternion.
§Returns
  • Self - Normalized unit quaternion.
Source

pub fn conjugate(self) -> Self

Returns the quaternion conjugate (-x, -y, -z, w) (inverse for unit quaternions).

§Arguments
  • Self - Source quaternion.
§Returns
  • Self - Conjugated quaternion.
Source

pub fn mul_quat(self, rhs: Self) -> Self

Composes two rotations via Hamilton multiplication self * rhs.

§Arguments
  • Self - Outer rotation quaternion.
  • Self - Inner rotation quaternion.
§Returns
  • Self - Product quaternion.
Source

pub fn rotate_vec3(self, vec_val: Vec3) -> Vec3

Rotates a 3D vector by this unit quaternion (q * v * q^-1).

§Arguments
  • Self - Unit rotation quaternion.
  • Vec3 - Input 3D vector.
§Returns
  • Vec3 - Rotated 3D vector.
Source

pub fn from_axis_angle(axis: Vec3, angle_rad: f32) -> Self

Builds a unit quaternion rotating by angle_rad around axis.

§Arguments
  • Vec3 - Rotation axis (normalized internally).
  • f32 - Right-handed rotation angle in radians.
§Returns
  • Self - Unit axis-angle quaternion.
Source

pub fn from_euler_yxz(yaw_rad: f32, pitch_rad: f32, roll_rad: f32) -> Self

Builds a unit quaternion from Euler angles rotate_y(yaw) * rotate_x(pitch) * rotate_z(roll).

§Arguments
  • f32 - Y-axis yaw in radians.
  • f32 - X-axis pitch in radians.
  • f32 - Z-axis roll in radians.
§Returns
  • Self - Unit rotation quaternion matching Mat4::from_trs_euler.
Source

pub fn from_mat3(col0: Vec3, col1: Vec3, col2: Vec3) -> Self

Extracts a unit quaternion from an orthonormal 3x3 rotation basis [col0, col1, col2] using Shepperd’s method.

§Arguments
  • Vec3 - First basis column (X axis).
  • Vec3 - Second basis column (Y axis).
  • Vec3 - Third basis column (Z axis).
§Returns
  • Self - Equivalent unit quaternion.
Source

pub fn to_mat4(self) -> Mat4

Converts this unit quaternion to a column-major 4x4 rotation matrix.

§Arguments
  • Self - Unit rotation quaternion.
§Returns
  • Mat4 - Equivalent 4x4 rotation matrix.
Source

pub fn nlerp(self, other: Self, alpha: f32) -> Self

Normalized shortest-arc linear interpolation (NLERP) between self and other.

§Arguments
  • Self - Start unit quaternion.
  • Self - End unit quaternion.
  • f32 - Interpolation factor in [0.0, 1.0].
§Returns
  • Self - Normalized interpolated quaternion.
Source

pub fn slerp(self, other: Self, alpha: f32) -> Self

Shortest-arc spherical linear interpolation (SLERP) between self and other.

§Arguments
  • Self - Start unit quaternion.
  • Self - End unit quaternion.
  • f32 - Interpolation factor in [0.0, 1.0].
§Returns
  • Self - Constant-angular-velocity interpolated unit quaternion.
Source

pub fn blender_z_up_to_y_up(self) -> Self

Converts a Blender Z-up quaternion (x, y, z, w) into Engine/glTF Y-up space via basis conjugation.

§Arguments
  • Self - Quaternion in Blender Z-up space.
§Returns
  • Self - Equivalent unit quaternion in Engine Y-up space.
Source

pub fn y_up_to_blender_z_up(self) -> Self

Converts an Engine/glTF Y-up quaternion into Blender Z-up space via basis conjugation.

§Arguments
  • Self - Quaternion in Engine Y-up space.
§Returns
  • Self - Equivalent unit quaternion in Blender Z-up space.
Source§

impl Quat

Source

pub fn get_x(&self) -> f32

Source

pub fn get_mut_x(&mut self) -> &mut f32

Source

pub fn set_x(&mut self, val: f32) -> &mut Self

Source

pub fn get_y(&self) -> f32

Source

pub fn get_mut_y(&mut self) -> &mut f32

Source

pub fn set_y(&mut self, val: f32) -> &mut Self

Source

pub fn get_z(&self) -> f32

Source

pub fn get_mut_z(&mut self) -> &mut f32

Source

pub fn set_z(&mut self, val: f32) -> &mut Self

Source

pub fn get_w(&self) -> f32

Source

pub fn get_mut_w(&mut self) -> &mut f32

Source

pub fn set_w(&mut self, val: f32) -> &mut Self

Trait Implementations§

Source§

impl Clone for Quat

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Quat

Source§

impl Debug for Quat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Quat

Default identity quaternion for Quat.

Source§

fn default() -> Self

Returns the identity rotation quaternion (0, 0, 0, 1).

§Returns
  • Self - Identity quaternion.
Source§

impl PartialEq for Quat

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Quat

Auto Trait Implementations§

§

impl Forget for Quat

§

impl Freeze for Quat

§

impl Move for Quat

§

impl RefUnwindSafe for Quat

§

impl Send for Quat

§

impl Sync for Quat

§

impl Unpin for Quat

§

impl UnsafeUnpin for Quat

§

impl UnwindSafe for Quat

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.