pub struct Transform {
pub position: Vec3,
pub rotation: Vec3,
pub scale: Vec3,
}Expand description
Local translation, Euler rotation and scale relative to the parent.
Units: metres, degrees and dimensionless scale. Rotations use Y-X-Z order, +Y is up and -Z is forward. Scale defaults to one. Shear is not representable.
use kvas_engine::components::Transform;
use glam::Vec3;
let mut pose = Transform::at(Vec3::new(0.0, 1.0, 0.0));
assert!(pose.look_at(Vec3::new(0.0, 1.0, -1.0), Vec3::Y));
assert!((pose.forward() - Vec3::NEG_Z).length() < 1e-5);Fields§
§position: Vec3Translation in parent-local metres.
rotation: Vec3Euler angles in degrees.
scale: Vec3Per-axis local scale, one for an unscaled object.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn at(position: Vec3) -> Self
pub fn at(position: Vec3) -> Self
Identity orientation/scale positioned at a parent-local point.
Sourcepub fn quat(&self) -> Quat
pub fn quat(&self) -> Quat
Converts stored Euler degrees to a quaternion using Y-X-Z rotation order.
Sourcepub fn set_quat(&mut self, q: Quat)
pub fn set_quat(&mut self, q: Quat)
Stores a unit quaternion as Euler degrees; equivalent angles may wrap. The caller must supply a finite normalized quaternion.
Sourcepub fn matrix(&self) -> Mat4
pub fn matrix(&self) -> Mat4
Local TRS matrix for column-vector multiplication (translation * rotation * scale).
Sourcepub fn from_matrix(m: Mat4) -> Self
pub fn from_matrix(m: Mat4) -> Self
Decomposes a finite, non-singular TRS matrix.
Shear cannot be retained. Use Self::try_from_matrix for unchecked input.
Sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Checks that every stored scalar is finite; zero scale remains valid data.
Sourcepub fn try_from_matrix(matrix: Mat4) -> Option<Self>
pub fn try_from_matrix(matrix: Mat4) -> Option<Self>
Decomposes a finite non-singular matrix, returning None for invalid data.
Perspective and shear matrices are rejected by checking the reconstructed TRS.
Sourcepub fn transform_point(&self, point: Vec3) -> Vec3
pub fn transform_point(&self, point: Vec3) -> Vec3
Transforms a local point into parent space, including translation and scale.
Sourcepub fn transform_direction(&self, direction: Vec3) -> Vec3
pub fn transform_direction(&self, direction: Vec3) -> Vec3
Rotates a direction into parent space, ignoring translation and scale.
Sourcepub fn inverse_transform_point(&self, point: Vec3) -> Option<Vec3>
pub fn inverse_transform_point(&self, point: Vec3) -> Option<Vec3>
Converts a parent-space point to local space, or None for a singular/invalid pose.
Sourcepub fn look_at(&mut self, target: Vec3, up: Vec3) -> bool
pub fn look_at(&mut self, target: Vec3, up: Vec3) -> bool
Orients local -Z toward a parent-space target while keeping position/scale.
Returns false without mutation for coincident points, non-finite data,
a zero up vector or an up vector parallel to the viewing direction.
Sourcepub fn interpolate(&self, other: &Self, t: f32) -> Self
pub fn interpolate(&self, other: &Self, t: f32) -> Self
Interpolates translation/scale linearly and orientation along the shortest
quaternion arc. t is clamped to [0, 1]; non-finite t selects self.
Trait Implementations§
impl Copy for Transform
Source§impl<'de> Deserialize<'de> for Transform
impl<'de> Deserialize<'de> for Transform
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnsafeUnpin for Transform
impl UnwindSafe for Transform
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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
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 moreimpl<T> MaybeSync for T
§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.