pub struct GlobalTransform { /* private fields */ }Expand description
A world-space transformation component.
This component caches the computed world-space transformation matrix for
entities in a hierarchy. It is computed by the transform propagation system
based on the entity’s local Transform and its parent’s GlobalTransform.
§When to Use
- Use
Transformfor setting local position/rotation/scale - Use
GlobalTransformfor reading world-space values (rendering, physics)
§Do Not Modify Directly
This component is managed by the transform propagation system. Modifying it directly will cause desynchronization with the entity hierarchy.
§Example
use goud_engine::ecs::components::{Transform, GlobalTransform};
use goud_engine::core::math::Vec3;
// For root entities, global equals local
let transform = Transform::from_position(Vec3::new(10.0, 5.0, 0.0));
let global = GlobalTransform::from(transform);
let position = global.translation();
assert!((position - Vec3::new(10.0, 5.0, 0.0)).length() < 0.001);Implementations§
Source§impl GlobalTransform
impl GlobalTransform
Sourcepub const IDENTITY: GlobalTransform
pub const IDENTITY: GlobalTransform
Identity global transform (no transformation).
Sourcepub const fn from_matrix(matrix: Matrix4<f32>) -> GlobalTransform
pub const fn from_matrix(matrix: Matrix4<f32>) -> GlobalTransform
Creates a GlobalTransform from a 4x4 transformation matrix.
§Arguments
matrix- The world-space transformation matrix
§Example
use goud_engine::ecs::components::GlobalTransform;
use cgmath::Matrix4;
let matrix = Matrix4::from_translation(cgmath::Vector3::new(10.0, 0.0, 0.0));
let global = GlobalTransform::from_matrix(matrix);Sourcepub fn from_translation(translation: Vec3) -> GlobalTransform
pub fn from_translation(translation: Vec3) -> GlobalTransform
Sourcepub fn from_translation_rotation_scale(
translation: Vec3,
rotation: Quat,
scale: Vec3,
) -> GlobalTransform
pub fn from_translation_rotation_scale( translation: Vec3, rotation: Quat, scale: Vec3, ) -> GlobalTransform
Creates a GlobalTransform from translation, rotation, and scale.
§Arguments
translation- World-space positionrotation- World-space rotation as quaternionscale- World-space scale
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::ecs::components::transform::Quat;
use goud_engine::core::math::Vec3;
let global = GlobalTransform::from_translation_rotation_scale(
Vec3::new(10.0, 0.0, 0.0),
Quat::IDENTITY,
Vec3::one(),
);Sourcepub fn matrix(&self) -> Matrix4<f32>
pub fn matrix(&self) -> Matrix4<f32>
Returns the underlying 4x4 transformation matrix.
This matrix is column-major and can be used directly for rendering.
§Example
use goud_engine::ecs::components::GlobalTransform;
let global = GlobalTransform::IDENTITY;
let matrix = global.matrix();Sourcepub fn matrix_ref(&self) -> &Matrix4<f32>
pub fn matrix_ref(&self) -> &Matrix4<f32>
Returns a reference to the underlying matrix.
Sourcepub fn to_cols_array(&self) -> [f32; 16]
pub fn to_cols_array(&self) -> [f32; 16]
Returns the matrix as a flat column-major array.
This is useful for FFI and sending to GPU shaders.
§Example
use goud_engine::ecs::components::GlobalTransform;
let global = GlobalTransform::IDENTITY;
let cols: [f32; 16] = global.to_cols_array();
// First column (x-axis)
assert_eq!(cols[0], 1.0); // m00Sourcepub fn to_rows_array(&self) -> [f32; 16]
pub fn to_rows_array(&self) -> [f32; 16]
Returns the matrix as a flat row-major array.
Some APIs expect row-major ordering.
Source§impl GlobalTransform
impl GlobalTransform
Sourcepub fn translation(&self) -> Vec3
pub fn translation(&self) -> Vec3
Extracts the translation (position) component.
This is the fourth column of the matrix.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::core::math::Vec3;
let global = GlobalTransform::from_translation(Vec3::new(10.0, 5.0, 3.0));
let pos = global.translation();
assert!((pos.x - 10.0).abs() < 0.001);Sourcepub fn scale(&self) -> Vec3
pub fn scale(&self) -> Vec3
Extracts the scale component.
This is computed from the lengths of the first three column vectors. Note: This does not handle negative scales correctly.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::ecs::components::transform::Quat;
use goud_engine::core::math::Vec3;
let global = GlobalTransform::from_translation_rotation_scale(
Vec3::zero(),
Quat::IDENTITY,
Vec3::new(2.0, 3.0, 4.0),
);
let scale = global.scale();
assert!((scale.x - 2.0).abs() < 0.001);Sourcepub fn rotation(&self) -> Quat
pub fn rotation(&self) -> Quat
Extracts the rotation component as a quaternion.
This removes scale from the rotation matrix, then converts to quaternion. Note: This may have issues with non-uniform scales or negative scales.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::ecs::components::transform::Quat;
use goud_engine::core::math::Vec3;
use std::f32::consts::PI;
let rotation = Quat::from_axis_angle(Vec3::unit_y(), PI / 4.0);
let global = GlobalTransform::from_translation_rotation_scale(
Vec3::zero(),
rotation,
Vec3::one(),
);
let extracted = global.rotation();
// Quaternion comparison (accounting for sign flip equivalence)
let dot = rotation.x * extracted.x + rotation.y * extracted.y
+ rotation.z * extracted.z + rotation.w * extracted.w;
assert!(dot.abs() > 0.999);Sourcepub fn decompose(&self) -> (Vec3, Quat, Vec3)
pub fn decompose(&self) -> (Vec3, Quat, Vec3)
Decomposes the transform into translation, rotation, and scale.
Returns (translation, rotation, scale).
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::ecs::components::transform::Quat;
use goud_engine::core::math::Vec3;
let global = GlobalTransform::from_translation_rotation_scale(
Vec3::new(10.0, 5.0, 3.0),
Quat::IDENTITY,
Vec3::new(2.0, 2.0, 2.0),
);
let (translation, rotation, scale) = global.decompose();
assert!((translation.x - 10.0).abs() < 0.001);
assert!((scale.x - 2.0).abs() < 0.001);Sourcepub fn to_transform(&self) -> Transform
pub fn to_transform(&self) -> Transform
Converts this GlobalTransform to a local Transform.
This is useful for extracting a Transform that would produce this GlobalTransform when applied from the origin.
Source§impl GlobalTransform
impl GlobalTransform
Sourcepub fn mul_transform(&self, other: &GlobalTransform) -> GlobalTransform
pub fn mul_transform(&self, other: &GlobalTransform) -> GlobalTransform
Multiplies this transform with another.
This combines two transformations: self * other applies self first,
then other.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::core::math::Vec3;
let parent = GlobalTransform::from_translation(Vec3::new(10.0, 0.0, 0.0));
let child_local = GlobalTransform::from_translation(Vec3::new(5.0, 0.0, 0.0));
let child_global = parent.mul_transform(&child_local);
let pos = child_global.translation();
assert!((pos.x - 15.0).abs() < 0.001);Sourcepub fn transform_by(&self, local: &Transform) -> GlobalTransform
pub fn transform_by(&self, local: &Transform) -> GlobalTransform
Multiplies this transform by a local Transform.
This is the primary method used by transform propagation.
§Example
use goud_engine::ecs::components::{GlobalTransform, Transform};
use goud_engine::core::math::Vec3;
let parent_global = GlobalTransform::from_translation(Vec3::new(10.0, 0.0, 0.0));
let child_local = Transform::from_position(Vec3::new(5.0, 0.0, 0.0));
let child_global = parent_global.transform_by(&child_local);
let pos = child_global.translation();
assert!((pos.x - 15.0).abs() < 0.001);Sourcepub fn transform_point(&self, point: Vec3) -> Vec3
pub fn transform_point(&self, point: Vec3) -> Vec3
Transforms a point from local space to world space.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::core::math::Vec3;
let global = GlobalTransform::from_translation(Vec3::new(10.0, 0.0, 0.0));
let local_point = Vec3::new(5.0, 0.0, 0.0);
let world_point = global.transform_point(local_point);
assert!((world_point.x - 15.0).abs() < 0.001);Sourcepub fn transform_direction(&self, direction: Vec3) -> Vec3
pub fn transform_direction(&self, direction: Vec3) -> Vec3
Transforms a direction from local space to world space.
Unlike points, directions are not affected by translation.
Sourcepub fn inverse(&self) -> Option<GlobalTransform>
pub fn inverse(&self) -> Option<GlobalTransform>
Returns the inverse of this transform.
The inverse transforms from world space back to local space.
Returns None if the matrix is not invertible (e.g., has zero scale).
Sourcepub fn forward(&self) -> Vec3
pub fn forward(&self) -> Vec3
Returns the forward direction vector (negative Z in local space).
Sourcepub fn lerp(&self, other: &GlobalTransform, t: f32) -> GlobalTransform
pub fn lerp(&self, other: &GlobalTransform, t: f32) -> GlobalTransform
Linearly interpolates between two global transforms.
This decomposes both transforms, interpolates components separately (slerp for rotation), then recomposes.
§Example
use goud_engine::ecs::components::GlobalTransform;
use goud_engine::core::math::Vec3;
let a = GlobalTransform::from_translation(Vec3::zero());
let b = GlobalTransform::from_translation(Vec3::new(10.0, 0.0, 0.0));
let mid = a.lerp(&b, 0.5);
let pos = mid.translation();
assert!((pos.x - 5.0).abs() < 0.001);Trait Implementations§
Source§impl Clone for GlobalTransform
impl Clone for GlobalTransform
Source§fn clone(&self) -> GlobalTransform
fn clone(&self) -> GlobalTransform
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GlobalTransform
impl Debug for GlobalTransform
Source§impl Default for GlobalTransform
impl Default for GlobalTransform
Source§fn default() -> GlobalTransform
fn default() -> GlobalTransform
Source§impl<'de> Deserialize<'de> for GlobalTransform
impl<'de> Deserialize<'de> for GlobalTransform
Source§fn deserialize<D>(
deserializer: D,
) -> Result<GlobalTransform, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<GlobalTransform, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<&Transform> for GlobalTransform
impl From<&Transform> for GlobalTransform
Source§fn from(transform: &Transform) -> GlobalTransform
fn from(transform: &Transform) -> GlobalTransform
Source§impl From<Transform> for GlobalTransform
impl From<Transform> for GlobalTransform
Source§fn from(transform: Transform) -> GlobalTransform
fn from(transform: Transform) -> GlobalTransform
Converts a local Transform to a GlobalTransform.
This is used for root entities where local == global.
Source§impl Mul<&GlobalTransform> for GlobalTransform
impl Mul<&GlobalTransform> for GlobalTransform
Source§type Output = GlobalTransform
type Output = GlobalTransform
* operator.Source§fn mul(self, rhs: &GlobalTransform) -> GlobalTransform
fn mul(self, rhs: &GlobalTransform) -> GlobalTransform
* operation. Read moreSource§impl Mul<&Transform> for GlobalTransform
impl Mul<&Transform> for GlobalTransform
Source§type Output = GlobalTransform
type Output = GlobalTransform
* operator.Source§impl Mul<Transform> for GlobalTransform
impl Mul<Transform> for GlobalTransform
Source§type Output = GlobalTransform
type Output = GlobalTransform
* operator.Source§impl Mul for GlobalTransform
impl Mul for GlobalTransform
Source§type Output = GlobalTransform
type Output = GlobalTransform
* operator.Source§fn mul(self, rhs: GlobalTransform) -> GlobalTransform
fn mul(self, rhs: GlobalTransform) -> GlobalTransform
* operation. Read moreSource§impl PartialEq for GlobalTransform
impl PartialEq for GlobalTransform
Source§impl Serialize for GlobalTransform
impl Serialize for GlobalTransform
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Component for GlobalTransform
impl Copy for GlobalTransform
impl StructuralPartialEq for GlobalTransform
Auto Trait Implementations§
impl Freeze for GlobalTransform
impl RefUnwindSafe for GlobalTransform
impl Send for GlobalTransform
impl Sync for GlobalTransform
impl Unpin for GlobalTransform
impl UnsafeUnpin for GlobalTransform
impl UnwindSafe for GlobalTransform
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().