From d0bb8fafb0d5f84ebbd0cf263aa0b63b9073f0f4 Mon Sep 17 00:00:00 2001 From: Matthias Seiffert Date: Mon, 6 Sep 2021 12:13:21 +0200 Subject: [PATCH 1/2] Add builder methods to Transform and GlobalTransform --- .../src/components/global_transform.rs | 22 +++++++++++++++++++ .../src/components/transform.rs | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index ceca829bc74f6..f93fa141710c2 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -105,6 +105,28 @@ impl GlobalTransform { self } + #[doc(hidden)] + #[inline] + pub fn with_translation(mut self, translation: Vec3) -> Self { + self.translation = translation; + self + } + + #[doc(hidden)] + #[inline] + pub fn with_rotation(mut self, rotation: Quat) -> Self { + self.rotation = rotation; + self + } + + #[doc(hidden)] + #[inline] + pub fn with_scale(mut self, scale: Vec3) -> Self { + self.scale = scale; + self + } + + /// Returns the 3d affine transformation matrix from this transforms translation, /// rotation, and scale. #[inline] diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index f4a538d30ecb8..9799f45df2699 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -117,6 +117,27 @@ impl Transform { self } + /// Returns this [`Transform`] with a new translation. + #[inline] + pub fn with_translation(mut self, translation: Vec3) -> Self { + self.translation = translation; + self + } + + /// Returns this [`Transform`] with a new rotation. + #[inline] + pub fn with_rotation(mut self, rotation: Quat) -> Self { + self.rotation = rotation; + self + } + + /// Returns this [`Transform`] with a new scale. + #[inline] + pub fn with_scale(mut self, scale: Vec3) -> Self { + self.scale = scale; + self + } + /// Returns the 3d affine transformation matrix from this transforms translation, /// rotation, and scale. #[inline] From 415f6e291f1e268a911b877a39993e9ba64b9868 Mon Sep 17 00:00:00 2001 From: Matthias Seiffert Date: Mon, 6 Sep 2021 14:49:17 +0200 Subject: [PATCH 2/2] Fix formatting --- crates/bevy_transform/src/components/global_transform.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index f93fa141710c2..8d29c7cd35b27 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -126,7 +126,6 @@ impl GlobalTransform { self } - /// Returns the 3d affine transformation matrix from this transforms translation, /// rotation, and scale. #[inline]