1use he3d_math::{Mat4, Quat, Vec3};
2
3#[derive(Clone, Copy, PartialEq, Debug)]
9pub struct Transform {
10 pub position: Vec3,
11 pub orientation: Quat,
12 pub scale: Vec3,
13}
14
15impl Transform {
16 pub const fn from_position(position: Vec3) -> Self {
17 Self {
18 position,
19 orientation: Quat::IDENTITY,
20 scale: Vec3::ONE,
21 }
22 }
23
24 pub const fn from_position_orientation(position: Vec3, orientation: Quat) -> Self {
25 Self {
26 position,
27 orientation,
28 scale: Vec3::ONE,
29 }
30 }
31
32 #[inline]
35 pub fn to_matrix(self) -> Mat4 {
36 Mat4::from_scale_rotation_translation(self.scale, self.orientation, self.position)
37 }
38
39 #[inline]
42 pub fn forward(self) -> Vec3 {
43 self.orientation * Vec3::Z
44 }
45
46 #[inline]
49 pub fn up(self) -> Vec3 {
50 self.orientation * Vec3::Y
51 }
52
53 #[inline]
56 pub fn right(self) -> Vec3 {
57 self.orientation * Vec3::X
58 }
59}
60
61impl Default for Transform {
62 fn default() -> Self {
63 Self {
64 position: Vec3::ZERO,
65 orientation: Quat::IDENTITY,
66 scale: Vec3::ONE,
67 }
68 }
69}