summaryrefslogtreecommitdiff
path: root/engine/src/transform.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-06-20 20:25:07 +0200
committerHampusM <hampus@hampusmat.com>2024-06-20 20:25:07 +0200
commit3ff91ac64308141968fdcbf3b3c09a01b0c60c97 (patch)
treeb0c94c78009c5abdd16f88bedc98a41381fa6b1b /engine/src/transform.rs
parente945f53395be9e0cd1e3a6894bc5e7fa08330298 (diff)
refactor(engine): replace Transform with Position & Scale structs
Diffstat (limited to 'engine/src/transform.rs')
-rw-r--r--engine/src/transform.rs33
1 files changed, 20 insertions, 13 deletions
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<f32>,
- pub scale: Vec3<f32>,
}
-impl Transform
+impl From<Vec3<f32>> for Position
{
- pub(crate) fn as_matrix(&self) -> Matrix<f32, 4, 4>
+ fn from(position: Vec3<f32>) -> 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<f32>,
+}
- matrix
+impl From<Vec3<f32>> for Scale
+{
+ fn from(scale: Vec3<f32>) -> 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 },
}
}