diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index e829cd8be3f35..d964442ca2cfa 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -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) { diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 6b370e5c16e2d..ce8be11b0c537 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -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) {