Skip to content

Commit

Permalink
Add synonyms for transform relative vectors (bevyengine#1667)
Browse files Browse the repository at this point in the history
Fixes bevyengine#1663.

I think the directions are correct (same as [here](https://docs.godotengine.org/en/stable/classes/class_vector3.html?highlight=forward#constants)), but please double check because I might have mixed them up.

Co-authored-by: guimcaballero <guim.caballero@gmail.com>
Co-authored-by: Guim Caballero <guim.caballero@gmail.com>
  • Loading branch information
2 people authored and James Higgins committed Apr 18, 2021
1 parent 38fc63c commit f8a13c6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,54 @@ impl GlobalTransform {
self.rotation * Vec3::X
}

/// Equivalent to -local_x()
#[inline]
pub fn left(&self) -> Vec3 {
-self.local_x()
}

/// Equivalent to local_x()
#[inline]
pub fn right(&self) -> Vec3 {
self.local_x()
}

/// Get the unit vector in the local y direction
#[inline]
pub fn local_y(&self) -> Vec3 {
self.rotation * Vec3::Y
}

/// Equivalent to local_y()
#[inline]
pub fn up(&self) -> Vec3 {
self.local_y()
}

/// Equivalent to -local_y()
#[inline]
pub fn down(&self) -> Vec3 {
-self.local_y()
}

/// Get the unit vector in the local z direction
#[inline]
pub fn local_z(&self) -> Vec3 {
self.rotation * Vec3::Z
}

/// Equivalent to -local_z()
#[inline]
pub fn forward(&self) -> Vec3 {
-self.local_z()
}

/// Equivalent to local_z()
#[inline]
pub fn back(&self) -> Vec3 {
self.local_z()
}

#[doc(hidden)]
#[inline]
pub fn rotate(&mut self, rotation: Quat) {
Expand Down
36 changes: 36 additions & 0 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,54 @@ impl Transform {
self.rotation * Vec3::X
}

/// Equivalent to -local_x()
#[inline]
pub fn left(&self) -> Vec3 {
-self.local_x()
}

/// Equivalent to local_x()
#[inline]
pub fn right(&self) -> Vec3 {
self.local_x()
}

/// Get the unit vector in the local y direction.
#[inline]
pub fn local_y(&self) -> Vec3 {
self.rotation * Vec3::Y
}

/// Equivalent to local_y()
#[inline]
pub fn up(&self) -> Vec3 {
self.local_y()
}

/// Equivalent to -local_y()
#[inline]
pub fn down(&self) -> Vec3 {
-self.local_y()
}

/// Get the unit vector in the local z direction.
#[inline]
pub fn local_z(&self) -> Vec3 {
self.rotation * Vec3::Z
}

/// Equivalent to -local_z()
#[inline]
pub fn forward(&self) -> Vec3 {
-self.local_z()
}

/// Equivalent to local_z()
#[inline]
pub fn back(&self) -> Vec3 {
self.local_z()
}

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

0 comments on commit f8a13c6

Please sign in to comment.