summaryrefslogtreecommitdiff
path: root/engine/src/transform.rs
blob: 8e768a61cb2cc219c516e8d98040a0092681821e (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
47
48
49
use crate::data_types::dimens::Dimens3;
use crate::ecs::Component;
use crate::matrix::Matrix;
use crate::reflection::Reflection;
use crate::vector::Vec3;

#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct Transform
{
    pub position: Vec3<f32>,
    pub scale: Dimens3<f32>,
}

impl Transform
{
    pub fn position(mut self, position: Vec3<f32>) -> Self
    {
        self.position = position;
        self
    }

    pub fn scale(mut self, scale: Dimens3<f32>) -> Self
    {
        self.scale = scale;
        self
    }

    pub fn to_matrix(&self) -> Matrix<f32, 4, 4>
    {
        let mut matrix = Matrix::new_identity();

        matrix.translate(&self.position);
        matrix.scale(&self.scale);

        matrix
    }
}

impl Default for Transform
{
    fn default() -> Self
    {
        Self {
            position: Vec3 { x: 0.0, y: 0.0, z: 0.0 },
            scale: Dimens3 { width: 1.0, height: 1.0, depth: 1.0 },
        }
    }
}