havok_types/math/
transform.rs1use crate::{Rotation, Vector4};
2use parse_display::Display;
3
4#[repr(C, align(16))]
18#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20#[derive(Debug, Clone, Default, PartialEq, PartialOrd, Display)]
21#[display("{rotation}{transition}")]
22pub struct Transform {
23 pub rotation: Rotation,
28 #[display("({x:.06} {y:.06} {z:.06})")]
36 pub transition: Vector4,
37}
38
39static_assertions::assert_eq_size!(Transform, [u8; 64]);
40
41impl Transform {
42 #[inline]
44 pub const fn new(rotation: Rotation, transition: Vector4) -> Self {
45 Self {
46 rotation,
47 transition,
48 }
49 }
50
51 pub fn to_le_bytes(&self) -> [u8; 64] {
52 let mut bytes = [0_u8; 64];
53 bytes[0..48].copy_from_slice(&self.rotation.to_le_bytes());
54 bytes[48..64].copy_from_slice(&self.transition.to_le_bytes());
55 bytes
56 }
57
58 pub fn to_be_bytes(&self) -> [u8; 64] {
59 let mut bytes = [0_u8; 64];
60 bytes[0..48].copy_from_slice(&self.rotation.to_be_bytes());
61 bytes[48..64].copy_from_slice(&self.transition.to_be_bytes());
62 bytes
63 }
64}