Struct Transform

Source
pub struct Transform {
    pub position: Vec2,
    /* private fields */
}

Fields§

§position: Vec2

Implementations§

Source§

impl Transform

Source

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

Source

pub fn rotation(&self) -> f32

Source

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

Source

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

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

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

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

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

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

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

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.