bones_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, TypeUlid)]
9#[ulid = "01GNFQWJWWXJJEXZQEDQJWZQWP"]
10#[repr(C)]
11pub struct Transform {
12    /// The position of the entity in the world.
13    pub translation: Vec3,
14    /// The rotation of the entity.
15    pub rotation: Quat,
16    /// The scale of the entity.
17    pub scale: Vec3,
18}
19
20impl Default for Transform {
21    fn default() -> Self {
22        Self {
23            translation: Default::default(),
24            rotation: Default::default(),
25            scale: Vec3::ONE,
26        }
27    }
28}
29
30impl Transform {
31    /// Create a transform from a translation.
32    pub fn from_translation(translation: Vec3) -> Self {
33        Self {
34            translation,
35            ..default()
36        }
37    }
38
39    /// Create a transform from a rotation.
40    pub fn from_rotation(rotation: Quat) -> Self {
41        Self {
42            rotation,
43            ..default()
44        }
45    }
46
47    /// Create a transform from a scale.
48    pub fn from_scale(scale: Vec3) -> Self {
49        Self { scale, ..default() }
50    }
51}