From 5f88cd7b644005db85b0935c735ed8045d1f05da Mon Sep 17 00:00:00 2001 From: Nova Date: Tue, 6 Feb 2024 09:00:21 -0500 Subject: [PATCH] refactor(spatial): use clearer to understand global transform --- src/nodes/spatial/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nodes/spatial/mod.rs b/src/nodes/spatial/mod.rs index f7c62050..ec3752b0 100644 --- a/src/nodes/spatial/mod.rs +++ b/src/nodes/spatial/mod.rs @@ -116,10 +116,12 @@ impl Spatial { *self.transform.lock() } pub fn global_transform(&self) -> Mat4 { - match self.get_parent() { - Some(parent) => parent.global_transform() * *self.transform.lock(), - None => *self.transform.lock(), - } + let parent_transform = self + .get_parent() + .as_deref() + .map(Self::global_transform) + .unwrap_or_default(); + parent_transform * self.local_transform() } pub fn set_local_transform(&self, transform: Mat4) { *self.transform.lock() = transform;