From b9540c0c896be65d80272fb893db9d62c7d82a7f Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 24 Jan 2021 09:13:01 +0100 Subject: [PATCH 1/2] Add more transform relative vectors (#1298) --- .../bevy_transform/src/components/global_transform.rs | 10 ++++++++++ crates/bevy_transform/src/components/transform.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index e829cd8be3f35..32591f1c5f694 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -74,6 +74,16 @@ 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 up(&self) -> Vec3 { + self.rotation * Vec3::unit_y() + } + #[inline] pub fn forward(&self) -> Vec3 { self.rotation * Vec3::unit_z() diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 6b370e5c16e2d..aae772b11aa97 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -74,6 +74,16 @@ 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 up(&self) -> Vec3 { + self.rotation * Vec3::unit_y() + } + #[inline] pub fn forward(&self) -> Vec3 { self.rotation * Vec3::unit_z() From 250660cf1b6860d8602bc5e222f1adf4732711e7 Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Sun, 24 Jan 2021 14:32:16 +0100 Subject: [PATCH 2/2] Add inverse of relative directions (#1298) --- .../src/components/global_transform.rs | 15 +++++++++++++++ crates/bevy_transform/src/components/transform.rs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index 32591f1c5f694..d964442ca2cfa 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -79,16 +79,31 @@ impl GlobalTransform { 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 aae772b11aa97..ce8be11b0c537 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -79,16 +79,31 @@ impl Transform { 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) {