#[repr(transparent)]pub struct AffineTransform(pub Mat4);Expand description
Represents a 3D affine transformation (translation, rotation, scale).
This is a semantic wrapper around a Mat4 that guarantees the matrix
represents a valid affine transform. It provides a dedicated API for
creating and manipulating these transformations.
Tuple Fields§
§0: Mat4Implementations§
Source§impl AffineTransform
impl AffineTransform
Sourcepub const IDENTITY: AffineTransform
pub const IDENTITY: AffineTransform
The identity transform, which results in no change.
Sourcepub fn from_translation(v: Vec3) -> AffineTransform
pub fn from_translation(v: Vec3) -> AffineTransform
Creates an AffineTransform from a translation vector.
§Arguments
v- The translation vector to apply
§Example
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::from_translation(Vec3::new(1.0, 2.0, 3.0));
assert_eq!(transform.translation(), Vec3::new(1.0, 2.0, 3.0));Sourcepub fn from_scale(scale: Vec3) -> AffineTransform
pub fn from_scale(scale: Vec3) -> AffineTransform
Sourcepub fn from_rotation_x(angle: f32) -> AffineTransform
pub fn from_rotation_x(angle: f32) -> AffineTransform
Sourcepub fn from_rotation_y(angle: f32) -> AffineTransform
pub fn from_rotation_y(angle: f32) -> AffineTransform
Sourcepub fn from_rotation_z(angle: f32) -> AffineTransform
pub fn from_rotation_z(angle: f32) -> AffineTransform
Sourcepub fn from_axis_angle(axis: Vec3, angle: f32) -> AffineTransform
pub fn from_axis_angle(axis: Vec3, angle: f32) -> AffineTransform
Creates an AffineTransform from a rotation around an arbitrary axis.
Uses Rodrigues’ rotation formula to create a rotation matrix.
§Arguments
axis- The axis of rotation (will be normalized automatically)angle- The angle of rotation in radians
§Example
use std::f32::consts::PI;
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let axis = Vec3::new(1.0, 1.0, 0.0);
let transform = AffineTransform::from_axis_angle(axis, PI / 4.0);Sourcepub fn from_quat(q: Quaternion) -> AffineTransform
pub fn from_quat(q: Quaternion) -> AffineTransform
Creates an AffineTransform from a quaternion representing a rotation.
§Arguments
q- The quaternion representing the rotation
§Example
use khora_core::math::{Quaternion, Vec3};
use khora_core::math::affine_transform::AffineTransform;
use std::f32::consts::PI;
let q = Quaternion::from_axis_angle(Vec3::Y, PI / 2.0);
let transform = AffineTransform::from_quat(q);Sourcepub fn to_matrix(&self) -> Mat4
pub fn to_matrix(&self) -> Mat4
Converts the AffineTransform to a Mat4.
This is useful when you need to pass the transformation matrix to shaders or other systems that expect a raw matrix.
§Example
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::IDENTITY;
let matrix = transform.to_matrix();Sourcepub fn translation(&self) -> Vec3
pub fn translation(&self) -> Vec3
Extracts the translation component from the affine transform.
Returns the translation vector representing the position offset applied by this transformation.
§Example
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::from_translation(Vec3::new(1.0, 2.0, 3.0));
assert_eq!(transform.translation(), Vec3::new(1.0, 2.0, 3.0));Sourcepub fn right(&self) -> Vec3
pub fn right(&self) -> Vec3
Extracts the right direction vector from the affine transform.
This returns the first column of the transformation matrix (excluding the w component), which represents the transformed positive X-axis direction.
§Example
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
use std::f32::consts::PI;
let transform = AffineTransform::from_rotation_z(PI / 2.0);
let right = transform.right();
// After 90° rotation around Z, right vector points in -Y directionSourcepub fn up(&self) -> Vec3
pub fn up(&self) -> Vec3
Extracts the up direction vector from the affine transform.
This returns the second column of the transformation matrix (excluding the w component), which represents the transformed positive Y-axis direction.
§Example
use std::f32::consts::PI;
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::from_rotation_x(PI / 2.0);
let up = transform.up();
// After 90° rotation around X, up vector points in -Z directionSourcepub fn forward(&self) -> Vec3
pub fn forward(&self) -> Vec3
Extracts the forward direction vector from the affine transform.
This returns the third column of the transformation matrix (excluding the w component), which represents the transformed positive Z-axis direction.
§Example
use std::f32::consts::PI;
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::from_rotation_y(PI / 2.0);
let forward = transform.forward();
// After 90° rotation around Y, forward vector points in X directionSourcepub fn rotation(&self) -> Quaternion
pub fn rotation(&self) -> Quaternion
Extracts the rotation component as a quaternion.
This method extracts the rotation represented by the upper-left 3x3 portion of the transformation matrix.
§Note
This assumes the transform has uniform or no scale. For transforms with non-uniform scale, the result may not represent a pure rotation. In such cases, consider normalizing the direction vectors first.
§Example
use khora_core::math::{Quaternion, Vec3};
use khora_core::math::affine_transform::AffineTransform;
use std::f32::consts::PI;
let q = Quaternion::from_axis_angle(Vec3::Y, PI / 2.0);
let transform = AffineTransform::from_quat(q);
let extracted = transform.rotation();
// extracted should be approximately equal to qSourcepub fn inverse(&self) -> Option<AffineTransform>
pub fn inverse(&self) -> Option<AffineTransform>
Computes the inverse of the affine transformation.
This uses an optimized affine inverse algorithm that’s more efficient than
a general matrix inverse, taking advantage of the affine transform structure.
Returns None if the transformation is not invertible (e.g., zero scale).
§Returns
Some(AffineTransform) if the inverse exists, None otherwise.
§Example
use khora_core::math::Vec3;
use khora_core::math::affine_transform::AffineTransform;
let transform = AffineTransform::from_translation(Vec3::new(1.0, 2.0, 3.0));
let inverse = transform.inverse().unwrap();
// The inverse should translate by (-1, -2, -3)Trait Implementations§
Source§impl Clone for AffineTransform
impl Clone for AffineTransform
Source§fn clone(&self) -> AffineTransform
fn clone(&self) -> AffineTransform
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AffineTransform
impl Debug for AffineTransform
Source§impl Default for AffineTransform
impl Default for AffineTransform
Source§fn default() -> AffineTransform
fn default() -> AffineTransform
Returns the identity AffineTransform.
Source§impl From<AffineTransform> for Mat4
impl From<AffineTransform> for Mat4
Source§fn from(transform: AffineTransform) -> Mat4
fn from(transform: AffineTransform) -> Mat4
Converts the AffineTransform into its inner Mat4.
Source§impl From<Mat4> for AffineTransform
impl From<Mat4> for AffineTransform
Source§impl PartialEq for AffineTransform
impl PartialEq for AffineTransform
impl Copy for AffineTransform
impl StructuralPartialEq for AffineTransform
Auto Trait Implementations§
impl Freeze for AffineTransform
impl RefUnwindSafe for AffineTransform
impl Send for AffineTransform
impl Sync for AffineTransform
impl Unpin for AffineTransform
impl UnwindSafe for AffineTransform
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more§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
§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().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.