#[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: f32Implementations§
Source§impl Quaternion
impl Quaternion
Sourcepub fn add_value(self, add: f32) -> Self
pub fn add_value(self, add: f32) -> Self
Add scalar to each component. (raymath QuaternionAddValue)
Sourcepub fn sub_value(self, sub: f32) -> Self
pub fn sub_value(self, sub: f32) -> Self
Subtract scalar from each component. (raymath QuaternionSubtractValue)
Sourcepub fn lerp(self, other: Quaternion, amount: f32) -> Self
pub fn lerp(self, other: Quaternion, amount: f32) -> Self
Linear interpolation. (raymath QuaternionLerp)
Sourcepub fn nlerp(self, other: Quaternion, amount: f32) -> Self
pub fn nlerp(self, other: Quaternion, amount: f32) -> Self
Normalized linear interpolation. (raymath QuaternionNlerp)
Sourcepub fn slerp(self, other: Quaternion, amount: f32) -> Self
pub fn slerp(self, other: Quaternion, amount: f32) -> Self
Spherical linear interpolation. (raymath QuaternionSlerp)
Sourcepub fn cubic_hermite_spline(
self,
out_tangent1: Quaternion,
q2: Quaternion,
in_tangent2: Quaternion,
t: f32,
) -> Self
pub fn cubic_hermite_spline( self, out_tangent1: Quaternion, q2: Quaternion, in_tangent2: Quaternion, t: f32, ) -> Self
Cubic Hermite spline interpolation. (raymath QuaternionCubicHermiteSpline)
Sourcepub fn from_vector3_to_vector3(from: Vector3, to: Vector3) -> Self
pub fn from_vector3_to_vector3(from: Vector3, to: Vector3) -> Self
Quaternion for rotation from one vector to another. (raymath QuaternionFromVector3ToVector3)
Sourcepub fn from_matrix(mat: Matrix) -> Self
pub fn from_matrix(mat: Matrix) -> Self
Quaternion from rotation matrix. (raymath QuaternionFromMatrix)
Sourcepub fn from_axis_angle(axis: Vector3, angle: f32) -> Self
pub fn from_axis_angle(axis: Vector3, angle: f32) -> Self
Quaternion from axis and angle (radians). (raymath QuaternionFromAxisAngle)
Sourcepub fn from_euler(pitch: f32, yaw: f32, roll: f32) -> Self
pub fn from_euler(pitch: f32, yaw: f32, roll: f32) -> Self
Quaternion from Euler angles (pitch, yaw, roll in radians). (raymath QuaternionFromEuler)
Sourcepub fn to_euler(self) -> Vector3
pub fn to_euler(self) -> Vector3
Convert quaternion to Euler angles (roll, pitch, yaw in radians). (raymath QuaternionToEuler)
Sourcepub fn transform(self, mat: Matrix) -> Self
pub fn transform(self, mat: Matrix) -> Self
Transform quaternion by matrix. (raymath QuaternionTransform)
Sourcepub fn equals(self, other: Quaternion) -> bool
pub fn equals(self, other: Quaternion) -> bool
Approximate equality (uses raymath epsilon). (raymath QuaternionEquals)
Trait Implementations§
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 AddAssign for Quaternion
impl AddAssign for Quaternion
Source§fn add_assign(&mut self, rhs: Quaternion)
fn add_assign(&mut self, rhs: Quaternion)
+= operation. Read moreSource§impl Clone for Quaternion
impl Clone for Quaternion
Source§fn clone(&self) -> Quaternion
fn clone(&self) -> Quaternion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Quaternion
Source§impl Debug for Quaternion
impl Debug for Quaternion
Source§impl Default for Quaternion
impl Default for Quaternion
Source§fn default() -> Quaternion
fn default() -> Quaternion
Source§impl Div for Quaternion
impl Div for Quaternion
Source§type Output = Quaternion
type Output = Quaternion
/ operator.Source§fn div(self, rhs: Quaternion) -> Quaternion
fn div(self, rhs: Quaternion) -> Quaternion
/ operation. Read moreSource§impl DivAssign for Quaternion
impl DivAssign for Quaternion
Source§fn div_assign(&mut self, rhs: Quaternion)
fn div_assign(&mut self, rhs: Quaternion)
/= operation. Read moreSource§impl From<Quaternion> for Vector4
impl From<Quaternion> for Vector4
Source§fn from(q: Quaternion) -> Self
fn from(q: Quaternion) -> Self
Source§impl From<Vector4> for Quaternion
impl From<Vector4> for Quaternion
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<f32> for Quaternion
impl Mul<f32> for Quaternion
Source§type Output = Quaternion
type Output = Quaternion
* operator.Source§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 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 PartialEq for Quaternion
impl PartialEq for Quaternion
Source§fn eq(&self, other: &Quaternion) -> bool
fn eq(&self, other: &Quaternion) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Quaternion
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 for Quaternion
impl SubAssign for Quaternion
Source§fn sub_assign(&mut self, rhs: Quaternion)
fn sub_assign(&mut self, rhs: Quaternion)
-= operation. Read more