havok_types/math/
matrix4.rs
1use crate::Vector4;
2use parse_display::Display;
3
4#[repr(C, align(16))]
16#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[derive(Debug, Clone, Default, PartialEq, PartialOrd, Display)]
19#[display("{x}{y}{z}{w}")]
20pub struct Matrix4 {
21 pub x: Vector4,
26 pub y: Vector4,
31 pub z: Vector4,
36 pub w: Vector4,
41}
42
43static_assertions::assert_eq_size!(Matrix4, [u8; 64]);
44
45impl Matrix4 {
46 #[inline]
48 pub const fn new(x: Vector4, y: Vector4, z: Vector4, w: Vector4) -> Self {
49 Self { x, y, z, w }
50 }
51
52 pub fn to_le_bytes(&self) -> [u8; 64] {
53 let mut bytes = [0; 64];
54 bytes[0..16].copy_from_slice(&self.x.to_le_bytes());
55 bytes[16..32].copy_from_slice(&self.y.to_le_bytes());
56 bytes[32..48].copy_from_slice(&self.z.to_le_bytes());
57 bytes[48..64].copy_from_slice(&self.w.to_le_bytes());
58 bytes
59 }
60
61 pub fn to_be_bytes(&self) -> [u8; 64] {
62 let mut bytes = [0_u8; 64];
63 bytes[0..16].copy_from_slice(&self.x.to_be_bytes());
64 bytes[16..32].copy_from_slice(&self.y.to_be_bytes());
65 bytes[32..48].copy_from_slice(&self.z.to_be_bytes());
66 bytes[48..64].copy_from_slice(&self.w.to_be_bytes());
67 bytes
68 }
69}