[][src]Struct physics2d::Transform

pub struct Transform {
    pub position: Vec2,
    // some fields omitted
}

Fields

position: Vec2

Methods

impl Transform[src]

pub fn new(position: Vec2, rotation: f32) -> Transform[src]

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

pub fn set_rotation(&mut self, rotation: f32)[src]

pub fn world_pos(&self, local_pos: &Vec2) -> Vec2[src]

Returns the world space position for the given local space position with respect to this Transform.

The local space position is first rotated by the world space rotation matrix and then translated by the world space position.

Examples


let t = Transform::new(Vec2::new(1.0, 2.0), math::PI / 2.0);

assert_eq!(t.world_pos(&Vec2::ZERO), Vec2::new(1.0, 2.0));
assert_eq!(t.world_pos(&Vec2::new(1.0, 1.0)), Vec2::new(0.0, 3.0));

pub fn world_dir(&self, local_dir: &Vec2) -> Vec2[src]

Returns the world space direction for the given local space direction with respect to this Transform.

The local space direction is rotated by the world space rotation matrix.

Examples


let t = Transform::new(Vec2::new(1000.01, 333.333), math::PI / 2.0);

assert!((t.world_dir(&Vec2::RIGHT) - Vec2::UP).len() < 1e-07);

pub fn local_pos(&self, world_pos: &Vec2) -> Vec2[src]

Returns the local space position with respect to this Transform for the given world space position.

The world space position is first brought relative to the local origin and then rotated to be relative to the local space rotation.

Examples


let t = Transform::new(Vec2::new(1.0, 2.0), math::PI / 2.0);

assert_eq!(t.local_pos(&Vec2::new(1.0, 2.0)), Vec2::ZERO);
assert!((t.local_pos(&Vec2::new(1.0, 3.0)) - Vec2::new(1.0, 0.0)).len() < 1e-07);

pub fn local_dir(&self, world_dir: &Vec2) -> Vec2[src]

Returns the local space direction with respect to this Transform for the given world space direction.

The world space direction is rotated to be relative to the local space rotation.

Examples


let t = Transform::new(Vec2::new(1000.01, 333.333), math::PI / 2.0);

assert!((t.local_dir(&Vec2::UP) - Vec2::RIGHT).len() < 1e-07);

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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