Skip to main content

Transform3D

Struct Transform3D 

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

Gimbal-lock-free 3D world-space transform backed by a unit Hamilton quaternion (position, rotation, scale).

Implementations§

Source§

impl Transform3D

Quaternion-backed matrix, Euler compatibility, SLERP interpolation, and point transformation helpers for Transform3D.

Source

pub fn new(position: Vec3, yaw_rad: f32, scale: Vec3) -> Self

Constructs a Transform3D from position, Y-axis yaw in radians, and non-uniform scale.

§Arguments
  • Vec3 - World-space translation.
  • f32 - Horizontal Y-axis yaw rotation in radians.
  • Vec3 - Non-uniform scale.
§Returns
  • Self - Constructed quaternion-backed 3D transform.
Source

pub fn from_trs(position: Vec3, rotation: Quat, scale: Vec3) -> Self

Constructs a Transform3D directly from translation, unit quaternion rotation, and scale.

§Arguments
  • Vec3 - World-space translation.
  • Quat - Orientation quaternion.
  • Vec3 - Non-uniform scale.
§Returns
  • Self - Constructed 3D transform.
Source

pub fn from_matrix(matrix: Mat4) -> Self

Decomposes an affine 4x4 matrix into a quaternion-backed Transform3D.

§Arguments
  • Mat4 - Column-major affine transformation matrix.
§Returns
  • Self - Decomposed 3D transform.
Source

pub fn with_rotation(self, rotation: Quat) -> Self

Returns a copy of this transform rotated by rotation.

§Arguments
  • Self - Source transform.
  • Quat - Orientation quaternion.
§Returns
  • Self - Updated transform.
Source

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

Returns a copy of this transform with full yaw, pitch, and roll Euler rotation in radians (Ry * Rx * Rz).

§Arguments
  • Self - Source transform.
  • f32 - Y-axis yaw in radians.
  • f32 - X-axis pitch in radians.
  • f32 - Z-axis roll in radians.
§Returns
  • Self - Rotated 3D transform.
Source

pub fn euler_yxz(&self) -> (f32, f32, f32)

Extracts (yaw_rad, pitch_rad, roll_rad) Euler angles matching Ry(yaw) * Rx(pitch) * Rz(roll) from this transform’s quaternion.

§Returns
  • (f32, f32, f32) - Extracted (yaw_rad, pitch_rad, roll_rad) in radians.
Source

pub fn get_yaw_rad(&self) -> f32

Returns the horizontal Y-axis yaw angle extracted from this transform’s quaternion.

§Returns
  • f32 - Yaw angle in radians.
Source

pub fn get_pitch_rad(&self) -> f32

Returns the vertical X-axis pitch angle extracted from this transform’s quaternion.

§Returns
  • f32 - Pitch angle in radians.
Source

pub fn get_roll_rad(&self) -> f32

Returns the longitudinal Z-axis roll angle extracted from this transform’s quaternion.

§Returns
  • f32 - Roll angle in radians.
Source

pub fn set_yaw_rad(&mut self, yaw_rad: f32)

Updates horizontal Y-axis yaw while preserving current pitch and roll angles.

§Arguments
  • &Self - Mutable transform.
  • f32 - New Y-axis yaw angle in radians.
Source

pub fn set_pitch_rad(&mut self, pitch_rad: f32)

Updates vertical X-axis pitch while preserving current yaw and roll angles.

§Arguments
  • &Self - Mutable transform.
  • f32 - New X-axis pitch angle in radians.
Source

pub fn set_roll_rad(&mut self, roll_rad: f32)

Updates longitudinal Z-axis roll while preserving current yaw and pitch angles.

§Arguments
  • &Self - Mutable transform.
  • f32 - New Z-axis roll angle in radians.
Source

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

Interpolates position, shortest-arc quaternion rotation (SLERP), and scale between self and other.

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

pub fn lerp_shortest_angle(self, other: Self, blend_factor: f32) -> Self

Interpolates position, scale, and shortest-arc quaternion rotation (SLERP) between self and other for render-time snapshot blending.

§Arguments
  • Self - Previous fixed-step transform.
  • Self - Current fixed-step transform.
  • f32 - Normalized interpolation factor in [0.0, 1.0].
§Returns
  • Self - Shortest-arc SLERP interpolated transform.
Source

pub fn to_mat4(&self) -> Mat4

Converts this quaternion-backed TRS transform into a column-major Mat4.

§Arguments
  • &Self - Transform reference.
§Returns
  • Mat4 - Model matrix.
Source

pub fn to_inv_mat4(&self) -> Mat4

Computes the exact inverse TRS matrix mapping world space back to local object space.

§Arguments
  • &Self - Transform reference.
§Returns
  • Mat4 - Inverse model matrix.
Source

pub fn normal_mat3(&self) -> [Vec3; 3]

Precomputes the exact cofactor-transpose 3x3 normal basis [col_x, col_y, col_z] valid under non-uniform and negative scale.

§Arguments
  • &Self - Transform reference.
§Returns
  • [Vec3; 3] - Cofactor 3x3 normal basis columns.
Source

pub fn transform_point(&self, vec_value: Vec3) -> Vec3

Transforms a local-space 3D point into world space.

§Arguments
  • &Self - Transform reference.
  • Vec3 - Local-space point.
§Returns
  • Vec3 - World-space point.
Source

pub fn transform_normal(&self, vec_value: Vec3) -> Vec3

Rotates a local-space surface normal into world space.

§Arguments
  • &Self - Transform reference.
  • Vec3 - Local normal.
§Returns
  • Vec3 - World-space unit normal.
Source

pub fn transform_bounds(&self, local: AxisAlignedBox3D) -> AxisAlignedBox3D

Transforms a local AxisAlignedBox3D into an enclosing world-space AxisAlignedBox3D using Arvo’s 18-multiply method (zero 8-corner loop, zero per-corner trigonometry).

§Arguments
  • &Self - Transform reference.
  • AxisAlignedBox3D - Local bounding box.
§Returns
  • AxisAlignedBox3D - Enclosing world-space bounding box.
Source

pub fn to_oriented_box(&self, local: AxisAlignedBox3D) -> OrientedBox3D

Converts a local-space AxisAlignedBox3D into a tight world-space oriented bounding box (OrientedBox3D) preserving rotation and non-uniform scale without axis-aligned bounding box corner inflation.

§Arguments
  • &Self - Transform reference.
  • AxisAlignedBox3D - Local-space bounding box.
§Returns
  • OrientedBox3D - Oriented bounding box in world space.
Source§

impl Transform3D

Source

pub fn get_position(&self) -> Vec3

Source

pub fn get_mut_position(&mut self) -> &mut Vec3

Source

pub fn set_position(&mut self, val: Vec3) -> &mut Self

Source

pub fn get_rotation(&self) -> Quat

Source

pub fn get_mut_rotation(&mut self) -> &mut Quat

Source

pub fn set_rotation(&mut self, val: Quat) -> &mut Self

Source

pub fn get_scale(&self) -> Vec3

Source

pub fn get_mut_scale(&mut self) -> &mut Vec3

Source

pub fn set_scale(&mut self, val: Vec3) -> &mut Self

Trait Implementations§

Source§

impl Clone for Transform3D

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 Transform3D

Source§

impl Debug for Transform3D

Source§

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

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

impl Default for Transform3D

Default identity Transform3D.

Source§

fn default() -> Self

Returns identity transform at origin with unit quaternion rotation and unit scale.

§Returns
  • Self - Identity Transform3D.
Source§

impl PartialEq for Transform3D

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 Transform3D

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> 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.