#[repr(C)]pub struct Transform {
pub position: Vec3,
pub rotation: Quat,
pub scale: Vec3,
}Expand description
A 3D spatial transformation component.
Represents position, rotation, and scale in 3D space. This is the primary component for positioning entities in the game world.
§Memory Layout
The component is laid out as:
position: 3 x f32 (12 bytes)rotation: 4 x f32 (16 bytes) - quaternion (x, y, z, w)scale: 3 x f32 (12 bytes)- Total: 40 bytes
§Example
use goud_engine::ecs::components::Transform;
use goud_engine::core::math::Vec3;
// Create at origin with default rotation and scale
let mut transform = Transform::default();
// Or create with specific position
let transform = Transform::from_position(Vec3::new(10.0, 0.0, 0.0));
// Or with full control
let transform = Transform::new(
Vec3::new(10.0, 5.0, 0.0), // position
Transform::IDENTITY_ROTATION, // rotation (identity quaternion)
Vec3::one(), // scale
);Fields§
§position: Vec3Position in world space (or local space if entity has a parent).
rotation: QuatRotation as a quaternion (x, y, z, w).
The quaternion should be normalized. Use the rotation methods to ensure this invariant is maintained.
scale: Vec3Scale along each axis.
A scale of (1, 1, 1) means no scaling. Negative values flip the object along that axis.
Implementations§
Source§impl Transform
impl Transform
Sourcepub const IDENTITY_ROTATION: Quat = Quat::IDENTITY
pub const IDENTITY_ROTATION: Quat = Quat::IDENTITY
Identity rotation (no rotation).
Sourcepub const fn new(position: Vec3, rotation: Quat, scale: Vec3) -> Transform
pub const fn new(position: Vec3, rotation: Quat, scale: Vec3) -> Transform
Creates a new Transform with the specified position, rotation, and scale.
Sourcepub fn from_position(position: Vec3) -> Transform
pub fn from_position(position: Vec3) -> Transform
Creates a Transform at the specified position with default rotation and scale.
Sourcepub fn from_rotation(rotation: Quat) -> Transform
pub fn from_rotation(rotation: Quat) -> Transform
Creates a Transform with the specified rotation and default position/scale.
Sourcepub fn from_scale(scale: Vec3) -> Transform
pub fn from_scale(scale: Vec3) -> Transform
Creates a Transform with the specified scale and default position/rotation.
Sourcepub fn from_scale_uniform(scale: f32) -> Transform
pub fn from_scale_uniform(scale: f32) -> Transform
Creates a Transform with uniform scale.
Sourcepub fn from_position_rotation(position: Vec3, rotation: Quat) -> Transform
pub fn from_position_rotation(position: Vec3, rotation: Quat) -> Transform
Creates a Transform with position and rotation.
Sourcepub fn look_at(eye: Vec3, target: Vec3, up: Vec3) -> Transform
pub fn look_at(eye: Vec3, target: Vec3, up: Vec3) -> Transform
Creates a Transform looking at a target position.
§Arguments
eye- The position of the transformtarget- The point to look atup- The up direction (usually Vec3::unit_y())
§Example
use goud_engine::ecs::components::Transform;
use goud_engine::core::math::Vec3;
let transform = Transform::look_at(
Vec3::new(0.0, 5.0, 10.0), // eye position
Vec3::zero(), // looking at origin
Vec3::unit_y(), // up direction
);Sourcepub fn matrix(&self) -> Matrix4<f32>
pub fn matrix(&self) -> Matrix4<f32>
Computes the 4x4 transformation matrix.
The matrix represents the combined transformation: Scale * Rotation * Translation (applied in that order when transforming points).
Sourcepub fn matrix_inverse(&self) -> Matrix4<f32>
pub fn matrix_inverse(&self) -> Matrix4<f32>
Computes the inverse transformation matrix.
Useful for view matrices or converting world-space to local-space.
Source§impl Transform
impl Transform
Sourcepub fn translate_local(&mut self, offset: Vec3)
pub fn translate_local(&mut self, offset: Vec3)
Translates the transform in local space.
The offset is rotated by the transform’s rotation before being applied.
Sourcepub fn set_position(&mut self, position: Vec3)
pub fn set_position(&mut self, position: Vec3)
Sets the position of the transform.
Sourcepub fn rotate(&mut self, rotation: Quat)
pub fn rotate(&mut self, rotation: Quat)
Rotates the transform by the given quaternion.
The rotation is applied in world space (rotation is applied after the current rotation).
Sourcepub fn rotate_x(&mut self, angle: f32)
pub fn rotate_x(&mut self, angle: f32)
Rotates around the X axis by the given angle in radians.
Sourcepub fn rotate_y(&mut self, angle: f32)
pub fn rotate_y(&mut self, angle: f32)
Rotates around the Y axis by the given angle in radians.
Sourcepub fn rotate_z(&mut self, angle: f32)
pub fn rotate_z(&mut self, angle: f32)
Rotates around the Z axis by the given angle in radians.
Sourcepub fn rotate_axis(&mut self, axis: Vec3, angle: f32)
pub fn rotate_axis(&mut self, axis: Vec3, angle: f32)
Rotates around an arbitrary axis by the given angle in radians.
Sourcepub fn rotate_local_x(&mut self, angle: f32)
pub fn rotate_local_x(&mut self, angle: f32)
Rotates in local space around the X axis.
Sourcepub fn rotate_local_y(&mut self, angle: f32)
pub fn rotate_local_y(&mut self, angle: f32)
Rotates in local space around the Y axis.
Sourcepub fn rotate_local_z(&mut self, angle: f32)
pub fn rotate_local_z(&mut self, angle: f32)
Rotates in local space around the Z axis.
Sourcepub fn set_rotation_euler(&mut self, pitch: f32, yaw: f32, roll: f32)
pub fn set_rotation_euler(&mut self, pitch: f32, yaw: f32, roll: f32)
Sets the rotation from Euler angles (in radians).
Sourcepub fn set_rotation(&mut self, rotation: Quat)
pub fn set_rotation(&mut self, rotation: Quat)
Sets the rotation.
Sourcepub fn look_at_target(&mut self, target: Vec3, up: Vec3)
pub fn look_at_target(&mut self, target: Vec3, up: Vec3)
Makes the transform look at a target position.
Sourcepub fn set_scale_uniform(&mut self, scale: f32)
pub fn set_scale_uniform(&mut self, scale: f32)
Sets uniform scale on all axes.
Sourcepub fn forward(&self) -> Vec3
pub fn forward(&self) -> Vec3
Returns the forward direction vector (negative Z in local space).
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.
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_transform_point(&self, point: Vec3) -> Vec3
pub fn inverse_transform_point(&self, point: Vec3) -> Vec3
Transforms a point from world space to local space.
Sourcepub fn inverse_transform_direction(&self, direction: Vec3) -> Vec3
pub fn inverse_transform_direction(&self, direction: Vec3) -> Vec3
Transforms a direction from world space to local space.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Transform
impl<'de> Deserialize<'de> for Transform
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Transform, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Transform, <__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<&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 Serialize for Transform
impl Serialize for Transform
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 Transform
impl Copy for Transform
impl StructuralPartialEq for Transform
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,
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().