Skip to main content

ferrum_wgpu/math/
transform.rs

1use cgmath::{Matrix4, Quaternion, Vector3};
2
3#[derive(Clone, Copy)]
4pub struct TransformDelta {
5    pub translation: Vector3<f32>,
6    pub rotation: Quaternion<f32>,
7    pub scale: Vector3<f32>,
8}
9
10impl TransformDelta {
11    pub fn new(translation: Vector3<f32>, rotation: Quaternion<f32>, scale: Vector3<f32>) -> Self {
12        Self {
13            translation,
14            rotation,
15            scale,
16        }
17    }
18
19    pub fn to_matrix(&self) -> Matrix4<f32> {
20        Matrix4::from_translation(self.translation)
21            * Matrix4::from(self.rotation)
22            * Matrix4::from_nonuniform_scale(self.scale.x, self.scale.y, self.scale.z)
23    }
24}
25
26impl Default for TransformDelta {
27    fn default() -> Self {
28        TransformDelta {
29            translation: Vector3::new(0.0, 0.0, 0.0),
30            rotation: Quaternion::new(1.0, 0.0, 0.0, 0.0),
31            scale: Vector3::new(1.0, 1.0, 1.0),
32        }
33    }
34}