bones_framework/render/
transform.rs

1//! Transform component.
2
3use crate::prelude::*;
4
5/// The main transform component.
6///
7/// Currently we don't have a hierarchy, and this is therefore a global transform.
8#[derive(Clone, Copy, Debug, HasSchema)]
9#[repr(C)]
10pub struct Transform {
11    /// The position of the entity in the world.
12    pub translation: Vec3,
13    /// The rotation of the entity.
14    pub rotation: Quat,
15    /// The scale of the entity.
16    pub scale: Vec3,
17}
18
19impl Default for Transform {
20    fn default() -> Self {
21        Self {
22            translation: Default::default(),
23            rotation: Default::default(),
24            scale: Vec3::ONE,
25        }
26    }
27}
28
29impl Transform {
30    /// Create a transform from a translation.
31    pub fn from_translation(translation: Vec3) -> Self {
32        Self {
33            translation,
34            ..default()
35        }
36    }
37
38    /// Create a transform from a rotation.
39    pub fn from_rotation(rotation: Quat) -> Self {
40        Self {
41            rotation,
42            ..default()
43        }
44    }
45
46    /// Create a transform from a scale.
47    pub fn from_scale(scale: Vec3) -> Self {
48        Self { scale, ..default() }
49    }
50}