Skip to content

Commit

Permalink
Add more transform relative vectors (bevyengine#1300)
Browse files Browse the repository at this point in the history
* Add more transform relative vectors (bevyengine#1298)

* Add inverse of relative directions (bevyengine#1298)
  • Loading branch information
RedlineTriad authored and rparrett committed Jan 27, 2021
1 parent d2dc8e8 commit e534e0a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,36 @@ impl GlobalTransform {
Mat4::from_scale_rotation_translation(self.scale, self.rotation, self.translation)
}

#[inline]
pub fn right(&self) -> Vec3 {
self.rotation * Vec3::unit_x()
}

#[inline]
pub fn left(&self) -> Vec3 {
-self.right()
}

#[inline]
pub fn up(&self) -> Vec3 {
self.rotation * Vec3::unit_y()
}

#[inline]
pub fn down(&self) -> Vec3 {
-self.up()
}

#[inline]
pub fn forward(&self) -> Vec3 {
self.rotation * Vec3::unit_z()
}

#[inline]
pub fn backward(&self) -> Vec3 {
-self.forward()
}

#[inline]
/// Rotate the transform by the given rotation
pub fn rotate(&mut self, rotation: Quat) {
Expand Down
25 changes: 25 additions & 0 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,36 @@ impl Transform {
Mat4::from_scale_rotation_translation(self.scale, self.rotation, self.translation)
}

#[inline]
pub fn right(&self) -> Vec3 {
self.rotation * Vec3::unit_x()
}

#[inline]
pub fn left(&self) -> Vec3 {
-self.right()
}

#[inline]
pub fn up(&self) -> Vec3 {
self.rotation * Vec3::unit_y()
}

#[inline]
pub fn down(&self) -> Vec3 {
-self.up()
}

#[inline]
pub fn forward(&self) -> Vec3 {
self.rotation * Vec3::unit_z()
}

#[inline]
pub fn backward(&self) -> Vec3 {
-self.forward()
}

#[inline]
/// Rotate the transform by the given rotation
pub fn rotate(&mut self, rotation: Quat) {
Expand Down

0 comments on commit e534e0a

Please sign in to comment.