use ecs::Component; use crate::matrix::Matrix; use crate::vector::Vec3; #[derive(Debug, Clone, Component)] pub struct Transform { position: Vec3, scale: Vec3, } impl Transform { #[must_use] pub fn new() -> Self { Self { position: Vec3::default(), scale: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, } } #[must_use] pub fn position(&self) -> &Vec3 { &self.position } pub fn set_position(&mut self, position: Vec3) { self.position = position; } pub fn set_scale(&mut self, scale: Vec3) { self.scale = scale; } pub(crate) fn as_matrix(&self) -> Matrix { let mut matrix = Matrix::new_identity(); matrix.translate(&self.position); matrix.scale(&self.scale); matrix } } impl Default for Transform { fn default() -> Self { Self::new() } }