concinnity_core/components/transform.rs
1// src/components/transform.rs
2
3/// World-space placement of an entity: translation, rotation, and scale.
4///
5/// Runtime-only placement state. Physics and interaction systems mutate it and
6/// the renderer reads it to position draws. Not authored directly in a world
7/// file; it carries the same transform fields a `Prop` declares.
8#[derive(Debug, Clone, Copy)]
9pub struct Transform {
10 /// World-space position [x, y, z].
11 pub position: [f32; 3],
12 /// Euler rotation in degrees [pitch, yaw, roll], applied in YXZ order.
13 pub rotation_deg: [f32; 3],
14 /// Non-uniform scale [x, y, z].
15 pub scale: [f32; 3],
16}
17
18impl Default for Transform {
19 fn default() -> Self {
20 Self {
21 position: [0.0, 0.0, 0.0],
22 rotation_deg: [0.0, 0.0, 0.0],
23 scale: [1.0, 1.0, 1.0],
24 }
25 }
26}
27
28impl Transform {
29 /// Build a column-major model matrix from this transform.
30 /// Order: scale, then YXZ Euler rotation, then translation.
31 pub fn model_matrix(&self) -> [[f32; 4]; 4] {
32 crate::gfx::transform::trs_matrix(self.position, self.rotation_deg, self.scale)
33 }
34}