From 3ff91ac64308141968fdcbf3b3c09a01b0c60c97 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 20 Jun 2024 20:25:07 +0200 Subject: refactor(engine): replace Transform with Position & Scale structs --- engine/src/transform.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'engine/src/transform.rs') diff --git a/engine/src/transform.rs b/engine/src/transform.rs index ad67d4c..5e5e296 100644 --- a/engine/src/transform.rs +++ b/engine/src/transform.rs @@ -1,35 +1,42 @@ use ecs::Component; -use crate::matrix::Matrix; use crate::vector::Vec3; -#[derive(Debug, Clone, Component)] -pub struct Transform +/// A position in 3D space. +#[derive(Debug, Default, Clone, Copy, Component)] +pub struct Position { pub position: Vec3, - pub scale: Vec3, } -impl Transform +impl From> for Position { - pub(crate) fn as_matrix(&self) -> Matrix + fn from(position: Vec3) -> Self { - let mut matrix = Matrix::new_identity(); - - matrix.translate(&self.position); + Self { position } + } +} - matrix.scale(&self.scale); +/// Scaling of a 3D object. +#[derive(Debug, Clone, Copy, Component)] +pub struct Scale +{ + pub scale: Vec3, +} - matrix +impl From> for Scale +{ + fn from(scale: Vec3) -> Self + { + Self { scale } } } -impl Default for Transform +impl Default for Scale { fn default() -> Self { Self { - position: Vec3::default(), scale: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, } } -- cgit v1.2.3-18-g5258