summaryrefslogtreecommitdiff
path: root/engine/src/transform.rs
blob: b01e3c1966e41e7e7c169dcbf4c0285350fb4a39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 translation(&self) -> &Vec3<f32>
    {
        &self.translation
    }

    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
    }
}