diff options
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 + } +} |