#[repr(C)]pub struct Quat {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}Expand description
A quaternion for representing rotations.
Stored as (x, y, z, w) where:
- (x, y, z) is the vector part (imaginary components)
- w is the scalar part (real component)
The identity rotation is (0, 0, 0, 1).
Fields§
§x: f32The x-component of the vector part.
y: f32The y-component of the vector part.
z: f32The z-component of the vector part.
w: f32The scalar (real) part.
Implementations§
Source§impl Quat
impl Quat
Sourcepub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self
Creates a new quaternion from components.
Sourcepub fn from_axis_angle(axis: Vec3, angle: f32) -> Self
pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self
Creates a quaternion from axis-angle representation.
§Arguments
axis- The normalized rotation axisangle- The rotation angle in radians
§Example
use goud_engine::ecs::components::transform::Quat;
use goud_engine::core::math::Vec3;
use std::f32::consts::PI;
// Rotate 90 degrees around Y axis
let q = Quat::from_axis_angle(Vec3::unit_y(), PI / 2.0);Sourcepub fn from_euler(pitch: f32, yaw: f32, roll: f32) -> Self
pub fn from_euler(pitch: f32, yaw: f32, roll: f32) -> Self
Creates a quaternion from Euler angles (in radians).
Uses XYZ rotation order (pitch, yaw, roll):
- X: pitch (rotation around right axis)
- Y: yaw (rotation around up axis)
- Z: roll (rotation around forward axis)
§Example
use goud_engine::ecs::components::transform::Quat;
use std::f32::consts::PI;
// 45 degree yaw rotation
let q = Quat::from_euler(0.0, PI / 4.0, 0.0);Sourcepub fn from_rotation_arc(from: Vec3, to: Vec3) -> Self
pub fn from_rotation_arc(from: Vec3, to: Vec3) -> Self
Creates a quaternion that rotates from one direction to another.
Both vectors should be normalized.
Sourcepub fn length_squared(self) -> f32
pub fn length_squared(self) -> f32
Returns the squared length of the quaternion.
Sourcepub fn conjugate(self) -> Self
pub fn conjugate(self) -> Self
Returns the conjugate of this quaternion.
For a unit quaternion, the conjugate is also the inverse.
Sourcepub fn inverse(self) -> Self
pub fn inverse(self) -> Self
Returns the inverse of this quaternion.
For unit quaternions (normalized), this is equivalent to the conjugate.
Sourcepub fn multiply(self, other: Self) -> Self
pub fn multiply(self, other: Self) -> Self
Multiplies two quaternions (combines rotations).
This represents combining two rotations, where self is applied first,
then other. This is also available via the * operator.
Sourcepub fn rotate_vector(self, v: Vec3) -> Vec3
pub fn rotate_vector(self, v: Vec3) -> Vec3
Rotates a vector by this quaternion.
Sourcepub fn slerp(self, other: Self, t: f32) -> Self
pub fn slerp(self, other: Self, t: f32) -> Self
Spherical linear interpolation between two quaternions.
This provides smooth interpolation between rotations.
Sourcepub fn to_euler(self) -> (f32, f32, f32)
pub fn to_euler(self) -> (f32, f32, f32)
Converts the quaternion to Euler angles (in radians).
Returns (pitch, yaw, roll) using XYZ convention.
Sourcepub fn forward(self) -> Vec3
pub fn forward(self) -> Vec3
Returns the forward direction vector (negative Z axis after rotation).
Trait Implementations§
Source§impl From<Quaternion<f32>> for Quat
impl From<Quaternion<f32>> for Quat
Source§fn from(q: Quaternion<f32>) -> Self
fn from(q: Quaternion<f32>) -> Self
impl Copy for Quat
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 UnsafeUnpin for Quat
impl UnwindSafe for Quat
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§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().