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
pub mod audio_player;
pub mod camera;
pub mod renderables;
pub mod spatial_queries;

use oxygengine_core::prelude::*;
use oxygengine_ha_renderer::prelude::*;

#[derive(Debug, Copy, Clone)]
pub struct Transform2d {
    pub position: Vec2,
    pub rotation: Scalar,
    pub scale: Vec2,
}

impl Default for Transform2d {
    fn default() -> Self {
        Self {
            position: 0.0.into(),
            rotation: 0.0,
            scale: 1.0.into(),
        }
    }
}

impl Transform2d {
    pub fn position(mut self, value: impl Into<Vec2>) -> Self {
        self.position = value.into();
        self
    }

    pub fn rotation(mut self, value: Scalar) -> Self {
        self.rotation = value;
        self
    }

    pub fn scale(mut self, value: impl Into<Vec2>) -> Self {
        self.scale = value.into();
        self
    }
}

impl From<Transform2d> for HaTransform {
    fn from(other: Transform2d) -> Self {
        HaTransform::new(
            other.position.into(),
            Eulers::yaw(other.rotation),
            other.scale.with_z(1.0),
        )
    }
}