[][src]Struct amethyst_core::transform::components::Transform

pub struct Transform { /* fields omitted */ }

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.

Methods

impl Transform[src]

pub fn new(
    position: Translation3<f32>,
    rotation: UnitQuaternion<f32>,
    scale: Vector3<f32>
) -> Self
[src]

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);

pub fn face_towards(
    &mut self,
    target: Vector3<f32>,
    up: Vector3<f32>
) -> &mut Self
[src]

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);

pub fn matrix(&self) -> Matrix4<f32>[src]

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.

pub fn translation(&self) -> &Vector3<f32>[src]

Returns a reference to the translation vector.

pub fn translation_mut(&mut self) -> &mut Vector3<f32>[src]

Returns a mutable reference to the translation vector.

pub fn rotation(&self) -> &UnitQuaternion<f32>[src]

Returns a reference to the rotation quaternion.

pub fn rotation_mut(&mut self) -> &mut UnitQuaternion<f32>[src]

Returns a mutable reference to the rotation quaternion.

pub fn scale(&self) -> &Vector3<f32>[src]

Returns a reference to the scale vector.

pub fn scale_mut(&mut self) -> &mut Vector3<f32>[src]

Returns a mutable reference to the scale vector.

pub fn isometry(&self) -> &Isometry3<f32>[src]

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

pub fn isometry_mut(&mut self) -> &mut Isometry3<f32>[src]

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

pub fn move_global(&mut self, translation: Vector3<f32>) -> &mut Self[src]

Move relatively to its current position.

pub fn move_local(&mut self, translation: Vector3<f32>) -> &mut Self[src]

Move relatively to its current position and orientation.

Equivalent to rotating the translation before applying.

pub fn move_along_global(
    &mut self,
    direction: Unit<Vector3<f32>>,
    distance: f32
) -> &mut Self
[src]

Move a distance along an axis.

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

pub fn move_along_local(
    &mut self,
    direction: Unit<Vector3<f32>>,
    distance: f32
) -> &mut Self
[src]

Move a distance along an axis.

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

pub fn move_forward(&mut self, amount: f32) -> &mut Self[src]

Move forward relative to current position and orientation.

pub fn move_backward(&mut self, amount: f32) -> &mut Self[src]

Move backward relative to current position and orientation.

pub fn move_right(&mut self, amount: f32) -> &mut Self[src]

Move right relative to current position and orientation.

pub fn move_left(&mut self, amount: f32) -> &mut Self[src]

Move left relative to current position and orientation.

pub fn move_up(&mut self, amount: f32) -> &mut Self[src]

Move up relative to current position and orientation.

pub fn move_down(&mut self, amount: f32) -> &mut Self[src]

Move down relative to current position and orientation.

pub fn translate_x(&mut self, amount: f32) -> &mut Self[src]

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

pub fn translate_y(&mut self, amount: f32) -> &mut Self[src]

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

pub fn translate_z(&mut self, amount: f32) -> &mut Self[src]

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

pub fn set_x(&mut self, value: f32) -> &mut Self[src]

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

pub fn set_y(&mut self, value: f32) -> &mut Self[src]

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

pub fn set_z(&mut self, value: f32) -> &mut Self[src]

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

pub fn pitch_global(&mut self, angle: f32) -> &mut Self[src]

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

pub fn pitch_local(&mut self, angle: f32) -> &mut Self[src]

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

pub fn yaw_global(&mut self, angle: f32) -> &mut Self[src]

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

pub fn yaw_local(&mut self, angle: f32) -> &mut Self[src]

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

pub fn roll_global(&mut self, angle: f32) -> &mut Self[src]

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

pub fn roll_local(&mut self, angle: f32) -> &mut Self[src]

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

pub fn rotate_global(
    &mut self,
    axis: Unit<Vector3<f32>>,
    angle: f32
) -> &mut Self
[src]

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

pub fn rotate_local(
    &mut self,
    axis: Unit<Vector3<f32>>,
    angle: f32
) -> &mut Self
[src]

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

pub fn set_position(&mut self, position: Vector3<f32>) -> &mut Self[src]

Set the position.

pub fn translate_xyz(&mut self, x: f32, y: f32, z: f32) -> &mut Self[src]

Adds the specified amounts to the translation vector.

pub fn set_xyz(&mut self, x: f32, y: f32, z: f32) -> &mut Self[src]

Sets the specified values of the translation vector.

pub fn set_rotation(&mut self, rotation: UnitQuaternion<f32>) -> &mut Self[src]

Sets the rotation of the transform.

pub fn set_scale(&mut self, x: f32, y: f32, z: f32) -> &mut Self[src]

Sets the scale of the transform.

pub fn set_rotation_euler(&mut self, x: f32, y: f32, z: f32) -> &mut Self[src]

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);

pub fn concat(&mut self, other: &Self) -> &mut Self[src]

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.

pub fn view_matrix(&self) -> Matrix4<f32>[src]

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

impl From<Matrix<f32, U3, U1, <DefaultAllocator as Allocator<f32, U3, U1>>::Buffer>> for Transform[src]

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);

impl Default for Transform[src]

fn default() -> Self[src]

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

impl PartialEq<Transform> for Transform[src]

impl Clone for Transform[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Transform[src]

impl Serialize for Transform[src]

impl<'de> Deserialize<'de> for Transform[src]

impl Component for Transform[src]

type Storage = FlaggedStorage<Self, DenseVecStorage<Self>>

Associated storage type for this component.

Auto Trait Implementations

impl Send for Transform

impl Sync for Transform

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Same for T[src]

type Output = T

Should always be Self

impl<SS, SP> SupersetOf for SP where
    SS: SubsetOf<SP>, 
[src]

impl<T> Resource for T where
    T: Any + Send + Sync
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Event for T where
    T: Send + Sync + 'static, 
[src]

impl<T> Erased for T[src]

impl<T> TryDefault for T where
    T: Default
[src]

fn unwrap_default() -> Self[src]

Calls try_default and panics on an error case.

impl<T> Erased for T[src]