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
use number_traits::Float;
use mat4;

use specs::{VecStorage, Component};


pub struct InnerTransform3D<T: 'static + Sync + Send + Copy + Float> {
    pub position: [T; 3],
    pub scale: [T; 3],
    pub rotation: [T; 4],
}


impl<T: 'static + Sync + Send + Copy + Float> Component for InnerTransform3D<T> {
    type Storage = VecStorage<Self>;
}


impl<T: 'static + Sync + Send + Copy + Float> Default for InnerTransform3D<T> {

    #[inline(always)]
    fn default() -> Self {
        InnerTransform3D {
            position: [T::zero(); 3],
            scale: [T::one(); 3],
            rotation: [T::zero(), T::zero(), T::zero(), T::one()],
        }
    }
}


impl<T: 'static + Sync + Send + Copy + Float> InnerTransform3D<T> {

    #[inline(always)]
    pub fn new() -> Self {
        Self::default()
    }

    #[inline]
    pub fn matrix(&self) -> [T; 16] {
        let mut matrix = mat4::new_identity();
        mat4::compose(&mut matrix, &self.position, &self.scale, &self.rotation);
        matrix
    }
}