diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-22 19:29:11 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-22 19:29:11 +0200 |
commit | 54c0fd70f82eb1a6814872c78bc22380f438c9d1 (patch) | |
tree | 7b0b67b52daa7ce18432c7b83caa862234a3255c /engine/src/transform.rs | |
parent | 30394c16ccdcdb145352e245a7a8893cef28e82d (diff) |
feat(engine): add translating & scaling objects
Diffstat (limited to 'engine/src/transform.rs')
-rw-r--r-- | engine/src/transform.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/engine/src/transform.rs b/engine/src/transform.rs new file mode 100644 index 0000000..9ce52ee --- /dev/null +++ b/engine/src/transform.rs @@ -0,0 +1,45 @@ +use crate::matrix::Matrix; +use crate::vector::Vec3; + +#[derive(Debug, Clone)] +pub struct Transform +{ + translation: Vec3<f32>, + scaling: Vec3<f32>, +} + +impl Transform +{ + pub fn new() -> Self + { + Self { + translation: Vec3::default(), + scaling: Vec3 { + x: 1.0, + y: 1.0, + z: 1.0, + }, + } + } + + pub fn set_translation(&mut self, translation: Vec3<f32>) + { + self.translation = translation; + } + + pub fn set_scaling(&mut self, scaling: Vec3<f32>) + { + self.scaling = scaling; + } + + pub fn as_matrix(&self) -> Matrix<f32, 4, 4> + { + let mut matrix = Matrix::new_identity(); + + matrix.translate(&self.translation); + + matrix.scale(&self.scaling); + + matrix + } +} |