Quat

Struct Quat 

Source
#[repr(C)]
pub struct Quat { pub x: Float, pub y: Float, pub z: Float, pub w: Float, }
Expand description

A quaternion for representing rotations.

Stored as (x, y, z, w) where w is the scalar component.

Fields§

§x: Float

X component (vector part).

§y: Float

Y component (vector part).

§z: Float

Z component (vector part).

§w: Float

W component (scalar part).

Implementations§

Source§

impl Quat

Source

pub const IDENTITY: Self

Identity quaternion (no rotation).

Source

pub const fn new(x: Float, y: Float, z: Float, w: Float) -> Self

Creates a quaternion from components.

Source

pub fn from_axis_angle(axis: Vec3, angle: Float) -> Self

Creates a quaternion from an axis and angle.

Source

pub fn from_euler_xyz(x: Float, y: Float, z: Float) -> Self

Creates a quaternion from Euler angles (XYZ order).

Source

pub fn from_mat4(m: &Mat4) -> Self

Creates a quaternion from a rotation matrix.

Source

pub fn to_mat4(self) -> Mat4

Converts to a rotation matrix.

Source

pub fn conjugate(self) -> Self

Returns the conjugate (inverse for unit quaternions).

Source

pub fn dot(self, other: Self) -> Float

Computes the dot product.

Source

pub fn length_squared(self) -> Float

Computes the squared length.

Source

pub fn length(self) -> Float

Computes the length.

Source

pub fn normalize(self) -> Self

Returns a normalized quaternion.

Source

pub fn inverse(self) -> Self

Returns the inverse.

Source

pub fn rotate(self, v: Vec3) -> Vec3

Rotates a vector by this quaternion.

Source

pub fn lerp(self, other: Self, t: Float) -> Self

Linear interpolation between quaternions.

Note: For most cases, prefer slerp for smooth interpolation.

Source

pub fn nlerp(self, other: Self, t: Float) -> Self

Normalized linear interpolation (faster than slerp, nearly as good).

Source

pub fn slerp(self, other: Self, t: Float) -> Self

Spherical linear interpolation between quaternions.

Source

pub fn to_euler_xyz(self) -> (Float, Float, Float)

Converts to Euler angles (XYZ order) in radians.

Source

pub fn to_axis_angle(self) -> (Vec3, Float)

Returns the axis and angle of this rotation.

Source

pub fn approx_eq(self, other: Self) -> bool

Checks if this quaternion is approximately equal to another.

Trait Implementations§

Source§

impl Clone for Quat

Source§

fn clone(&self) -> Quat

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Mul<Vec3> for Quat

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vec3) -> Vec3

Performs the * operation. Read more
Source§

impl Mul for Quat

Source§

type Output = Quat

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl PartialEq for Quat

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Quat

Source§

impl StructuralPartialEq for Quat

Auto Trait Implementations§

§

impl Freeze for Quat

§

impl RefUnwindSafe for Quat

§

impl Send for Quat

§

impl Sync for Quat

§

impl Unpin for Quat

§

impl UnwindSafe for Quat

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.