summaryrefslogtreecommitdiff
path: root/engine/src/transform.rs
blob: 05819bceb6c3e8e55fe8ad8d8a4143af5c189d67 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use ecs::Component;

use crate::builder;
use crate::vector::Vec3;

builder!(
    #[builder(name = Builder, derives=(Debug))]
    #[derive(Debug)]
    #[non_exhaustive]
    pub struct Transform
    {
        pub position: Vec3<f32>,
        pub scale: Vec3<f32>,
    }
);

impl Transform
{
    pub fn builder() -> Builder
    {
        Builder::default()
    }
}

impl Default for Transform
{
    fn default() -> Self
    {
        Self::builder().build()
    }
}

impl Default for Builder
{
    fn default() -> Self
    {
        Self {
            position: Vec3::from(0.0),
            scale: Vec3::from(1.0),
        }
    }
}

/// A position in world space.
#[derive(Debug, Default, Clone, Copy, Component)]
pub struct WorldPosition
{
    pub position: Vec3<f32>,
}

impl From<Vec3<f32>> for WorldPosition
{
    fn from(position: Vec3<f32>) -> Self
    {
        Self { position }
    }
}

/// Scaling of a 3D object.
#[derive(Debug, Clone, Copy, Component)]
pub struct Scale
{
    pub scale: Vec3<f32>,
}

impl From<Vec3<f32>> for Scale
{
    fn from(scale: Vec3<f32>) -> Self
    {
        Self { scale }
    }
}

impl Default for Scale
{
    fn default() -> Self
    {
        Self {
            scale: Vec3 { x: 1.0, y: 1.0, z: 1.0 },
        }
    }
}