pub struct Transform { /* private fields */ }
Expand description

Local position, rotation, and scale (from parent if it exists).

Used for rendering position and orientation.

The transforms are preformed in this order: scale, then rotation, then translation.

Implementations

Create a new Transform.

Examples
let position = Translation3::new(0.0, 2.0, 4.0);
let rotation = UnitQuaternion::from_euler_angles(0.4, 0.2, 0.0);
let scale = Vector3::new(1.0, 1.0, 1.0);

let t = Transform::new(position, rotation, scale);

assert_eq!(t.translation().y, 2.0);

Makes the entity point towards position.

up says which direction the entity should be ‘rolled’ to once it is pointing at position. If up is parallel to the direction the entity is looking, the result will be garbage.

This function only works with respect to the coordinate system of its parent, so when used with an object that’s not a sibling it will not do what you expect.

Examples
let mut t = Transform::default();
// No rotation by default
assert_eq!(*t.rotation().quaternion(), Quaternion::identity());
// look up with up pointing backwards
t.face_towards(Vector3::new(0.0, 1.0, 0.0), Vector3::new(0.0, 0.0, 1.0));
// our rotation should match the angle from straight ahead to straight up
let rotation = UnitQuaternion::rotation_between(
    &Vector3::new(0.0, 1.0, 0.0),
    &Vector3::new(0.0, 0.0, 1.0),
).unwrap();
assert_eq!(*t.rotation(), rotation);
// now if we move forwards by 1.0, we'll end up at the point we are facing
// (modulo some floating point error)
t.move_forward(1.0);
assert!((*t.translation() - Vector3::new(0.0, 1.0, 0.0)).magnitude() <= 0.0001);

Returns the local object matrix for the transform.

Combined with the parent’s GlobalTransform component it gives the global (or world) matrix for the current entity.

Returns a reference to the translation vector.

Returns a mutable reference to the translation vector.

Returns a reference to the rotation quaternion.

Returns a mutable reference to the rotation quaternion.

Returns a reference to the scale vector.

Returns a mutable reference to the scale vector.

Returns a reference to the isometry of the transform (translation and rotation combined).

Returns a mutable reference to the isometry of the transform (translation and rotation combined).

Move relatively to its current position.

Move relatively to its current position and orientation.

Equivalent to rotating the translation before applying.

Move a distance along an axis.

It will not move in the case where the axis is zero, for any distance.

Move a distance along an axis.

It will not move in the case where the axis is zero, for any distance.

Move forward relative to current position and orientation.

Move backward relative to current position and orientation.

Move right relative to current position and orientation.

Move left relative to current position and orientation.

Move up relative to current position and orientation.

Move down relative to current position and orientation.

Adds the specified amount to the translation vector’s x component.

Adds the specified amount to the translation vector’s y component.

Adds the specified amount to the translation vector’s z component.

Sets the translation vector’s x component to the specified value.

Sets the translation vector’s y component to the specified value.

Sets the translation vector’s z component to the specified value.

Pitch relatively to the world. angle is specified in radians.

Pitch relatively to its own rotation. angle is specified in radians.

Yaw relatively to the world. angle is specified in radians.

Yaw relatively to its own rotation. angle is specified in radians.

Roll relatively to the world. angle is specified in radians.

Roll relatively to its own rotation. angle is specified in radians.

Rotate relatively to the world. angle is specified in radians.

Rotate relatively to the current orientation. angle is specified in radians.

Set the position.

Adds the specified amounts to the translation vector.

Sets the specified values of the translation vector.

Sets the rotation of the transform.

Sets the scale of the transform.

Set the rotation using Euler x, y, z.

All angles are specified in radians. Euler order is roll → pitch → yaw.

Arguments
  • x - The angle to apply around the x axis. Also known as the roll.
  • y - The angle to apply around the y axis. Also known as the pitch.
  • z - The angle to apply around the z axis. Also known as the yaw.
let mut transform = Transform::default();

transform.set_rotation_euler(1.0, 0.0, 0.0);

assert_eq!(transform.rotation().euler_angles().0, 1.0);

Concatenates another transform onto self.

Concatenating is roughly equivalent to doing matrix multiplication except for the fact that it’s done on Transform which is decomposed.

Calculates the inverse of this transform, which we need to render.

We can exploit the extra information we have to perform this inverse faster than O(n^3).

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Associated storage type for this component.
Formats the value using the given formatter. Read more

The default transform does nothing when used to transform an entity.

Deserialize this value from the given Serde deserializer. Read more

Creates a Transform using the Vector3 as the translation vector.

let transform = Transform::from(Vector3::new(100.0, 200.0, 300.0));

assert_eq!(transform.translation().x, 100.0);
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Tries to create the default.
Calls try_default and panics on an error case.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.