From 347b5374fb344507b57f4c5eecd28785a9f00961 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 13 Nov 2023 19:04:05 +0100 Subject: fix(engine): make object translate function add to current pos --- engine/src/object.rs | 7 ++++--- engine/src/transform.rs | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'engine') diff --git a/engine/src/object.rs b/engine/src/object.rs index 4112bcb..3827763 100644 --- a/engine/src/object.rs +++ b/engine/src/object.rs @@ -42,17 +42,18 @@ impl Object #[must_use] pub fn position(&self) -> &Vec3 { - self.transform.translation() + self.transform.position() } pub fn translate(&mut self, translation: Vec3) { - self.transform.set_translation(translation); + self.transform + .set_position(self.transform.position().clone() + translation); } pub fn scale(&mut self, scaling: Vec3) { - self.transform.set_scaling(scaling); + self.transform.set_scale(scaling); } #[must_use] diff --git a/engine/src/transform.rs b/engine/src/transform.rs index b01e3c1..a9d9980 100644 --- a/engine/src/transform.rs +++ b/engine/src/transform.rs @@ -4,8 +4,8 @@ use crate::vector::Vec3; #[derive(Debug, Clone)] pub struct Transform { - translation: Vec3, - scaling: Vec3, + position: Vec3, + scale: Vec3, } impl Transform @@ -13,33 +13,33 @@ impl Transform pub fn new() -> Self { Self { - translation: Vec3::default(), - scaling: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, + position: Vec3::default(), + scale: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, } } - pub fn translation(&self) -> &Vec3 + pub fn position(&self) -> &Vec3 { - &self.translation + &self.position } - pub fn set_translation(&mut self, translation: Vec3) + pub fn set_position(&mut self, position: Vec3) { - self.translation = translation; + self.position = position; } - pub fn set_scaling(&mut self, scaling: Vec3) + pub fn set_scale(&mut self, scale: Vec3) { - self.scaling = scaling; + self.scale = scale; } pub fn as_matrix(&self) -> Matrix { let mut matrix = Matrix::new_identity(); - matrix.translate(&self.translation); + matrix.translate(&self.position); - matrix.scale(&self.scaling); + matrix.scale(&self.scale); matrix } -- cgit v1.2.3-18-g5258