blob: f55f44e28d888af8515a1958619f919947aaf2bf (
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
|
use ecs::Component;
use crate::matrix::Matrix;
use crate::vector::Vec3;
#[derive(Debug, Clone, Component)]
pub struct Transform
{
position: Vec3<f32>,
scale: Vec3<f32>,
}
impl Transform
{
#[must_use]
pub fn new() -> Self
{
Self {
position: Vec3::default(),
scale: Vec3 { x: 1.0, y: 1.0, z: 1.0 },
}
}
#[must_use]
pub fn position(&self) -> &Vec3<f32>
{
&self.position
}
pub fn set_position(&mut self, position: Vec3<f32>)
{
self.position = position;
}
pub fn set_scale(&mut self, scale: Vec3<f32>)
{
self.scale = scale;
}
pub(crate) fn as_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::new()
}
}
|