From 7e368e0b782161813890722d3768a11852d5e391 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Mon, 25 Jan 2021 04:05:30 +0000 Subject: [PATCH] Add more transform relative vectors (#1300) * Add more transform relative vectors (#1298) * Add inverse of relative directions (#1298) --- .../src/components/global_transform.rs | 25 +++++++++++++++++++ .../src/components/transform.rs | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index e829cd8be3..d964442ca2 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 6b370e5c16..ce8be11b0c 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) {