Skip to main content

Quaternion

Struct Quaternion 

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

A unit quaternion used for 3D rotations.

C aliases Quaternion to Vector4 (typedef Vector4 Quaternion); raylib-rs uses a distinct #[repr(C)] struct so the two types have their own method namespaces. The layout is identical (x, y, z, w as f32), and zero-cost conversions are provided:

  • Quaternion::from(v: Vector4) — convert from a raw four-component vector.
  • Vector4::from(q: Quaternion) — convert back.

Build a Quaternion with one of the constructor functions: from_axis_angle, from_euler, from_matrix, or identity.

Fields§

§x: f32§y: f32§z: f32§w: f32

Implementations§

Source§

impl Quaternion

Source

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

Source§

impl Quaternion

Source

pub fn identity() -> Self

Identity quaternion (0, 0, 0, 1). (raymath QuaternionIdentity)

Source

pub fn add_value(self, add: f32) -> Self

Add scalar to each component. (raymath QuaternionAddValue)

Source

pub fn sub_value(self, sub: f32) -> Self

Subtract scalar from each component. (raymath QuaternionSubtractValue)

Source

pub fn length(self) -> f32

Quaternion length. (raymath QuaternionLength)

Source

pub fn normalize(self) -> Self

Normalize quaternion. (raymath QuaternionNormalize)

Source

pub fn invert(self) -> Self

Invert quaternion. (raymath QuaternionInvert)

Source

pub fn lerp(self, other: Quaternion, amount: f32) -> Self

Linear interpolation. (raymath QuaternionLerp)

Source

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

Normalized linear interpolation. (raymath QuaternionNlerp)

Source

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

Spherical linear interpolation. (raymath QuaternionSlerp)

Source

pub fn cubic_hermite_spline( self, out_tangent1: Quaternion, q2: Quaternion, in_tangent2: Quaternion, t: f32, ) -> Self

Cubic Hermite spline interpolation. (raymath QuaternionCubicHermiteSpline)

Source

pub fn from_vector3_to_vector3(from: Vector3, to: Vector3) -> Self

Quaternion for rotation from one vector to another. (raymath QuaternionFromVector3ToVector3)

Source

pub fn from_matrix(mat: Matrix) -> Self

Quaternion from rotation matrix. (raymath QuaternionFromMatrix)

Source

pub fn to_matrix(self) -> Matrix

Rotation matrix from quaternion. (raymath QuaternionToMatrix)

Source

pub fn from_axis_angle(axis: Vector3, angle: f32) -> Self

Quaternion from axis and angle (radians). (raymath QuaternionFromAxisAngle)

Source

pub fn from_euler(pitch: f32, yaw: f32, roll: f32) -> Self

Quaternion from Euler angles (pitch, yaw, roll in radians). (raymath QuaternionFromEuler)

Source

pub fn to_euler(self) -> Vector3

Convert quaternion to Euler angles (roll, pitch, yaw in radians). (raymath QuaternionToEuler)

Source

pub fn transform(self, mat: Matrix) -> Self

Transform quaternion by matrix. (raymath QuaternionTransform)

Source

pub fn equals(self, other: Quaternion) -> bool

Approximate equality (uses raymath epsilon). (raymath QuaternionEquals)

Trait Implementations§

Source§

impl Add for Quaternion

Source§

type Output = Quaternion

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quaternion) -> Quaternion

Performs the + operation. Read more
Source§

impl AddAssign for Quaternion

Source§

fn add_assign(&mut self, rhs: Quaternion)

Performs the += operation. Read more
Source§

impl Clone for Quaternion

Source§

fn clone(&self) -> Quaternion

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 Quaternion

Source§

impl Debug for Quaternion

Source§

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

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

impl Default for Quaternion

Source§

fn default() -> Quaternion

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

impl Div for Quaternion

Source§

type Output = Quaternion

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Quaternion) -> Quaternion

Performs the / operation. Read more
Source§

impl DivAssign for Quaternion

Source§

fn div_assign(&mut self, rhs: Quaternion)

Performs the /= operation. Read more
Source§

impl From<Quaternion> for Vector4

Source§

fn from(q: Quaternion) -> Self

Converts to this type from the input type.
Source§

impl From<Vector4> for Quaternion

Source§

fn from(v: Vector4) -> Self

Converts to this type from the input type.
Source§

impl Mul for Quaternion

Source§

type Output = Quaternion

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quaternion) -> Quaternion

Performs the * operation. Read more
Source§

impl Mul<f32> for Quaternion

Source§

type Output = Quaternion

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Quaternion

Performs the * operation. Read more
Source§

impl MulAssign for Quaternion

Source§

fn mul_assign(&mut self, rhs: Quaternion)

Performs the *= operation. Read more
Source§

impl MulAssign<f32> for Quaternion

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl PartialEq for Quaternion

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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 StructuralPartialEq for Quaternion

Source§

impl Sub for Quaternion

Source§

type Output = Quaternion

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Quaternion) -> Quaternion

Performs the - operation. Read more
Source§

impl SubAssign for Quaternion

Source§

fn sub_assign(&mut self, rhs: Quaternion)

Performs the -= operation. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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.