|
|
@ -26,8 +26,7 @@ impl Matrix4 { |
|
|
|
/// Construct a Matrix4 from its rows
|
|
|
|
/// Construct a Matrix4 from its rows
|
|
|
|
pub fn from_rows(rows: [FVec4; 4]) -> Self { |
|
|
|
pub fn from_rows(rows: [FVec4; 4]) -> Self { |
|
|
|
Self(citro3d_sys::C3D_Mtx { |
|
|
|
Self(citro3d_sys::C3D_Mtx { |
|
|
|
// Safety: FVec is repr(transparent)
|
|
|
|
r: rows.map(|r| r.0), |
|
|
|
r: unsafe { core::mem::transmute::<_, [citro3d_sys::C3D_FVec; 4]>(rows) }, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
/// Create a new matrix from a raw citro3d_sys one
|
|
|
|
/// Create a new matrix from a raw citro3d_sys one
|
|
|
@ -49,20 +48,12 @@ impl Matrix4 { |
|
|
|
|
|
|
|
|
|
|
|
/// Get the rows in raw (WZYX) form
|
|
|
|
/// Get the rows in raw (WZYX) form
|
|
|
|
pub fn rows_wzyx(self) -> [FVec4; 4] { |
|
|
|
pub fn rows_wzyx(self) -> [FVec4; 4] { |
|
|
|
// Safety: FVec4 is repr(C) to allow transmute from C3D_Vec
|
|
|
|
unsafe { self.0.r }.map(FVec4::from_raw) |
|
|
|
unsafe { core::mem::transmute::<[citro3d_sys::C3D_FVec; 4], [FVec4; 4]>(self.0.r) } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Get the rows in XYZW form
|
|
|
|
/// Get the rows in XYZW form
|
|
|
|
pub fn rows_xyzw(self) -> [[f32; 4]; 4] { |
|
|
|
pub fn rows_xyzw(self) -> [[f32; 4]; 4] { |
|
|
|
let mut rows = self.rows_wzyx(); |
|
|
|
self.rows_wzyx().map(|r| [r.x(), r.y(), r.z(), r.w()]) |
|
|
|
for r in &mut rows { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
|
|
|
r.0.c.reverse(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Safety: FVec has same layout as citro3d_sys::C3D_FVec which is a union with [f32; 4] as one variant
|
|
|
|
|
|
|
|
unsafe { std::mem::transmute::<_, [[f32; 4]; 4]>(rows) } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/// Construct the zero matrix.
|
|
|
|
/// Construct the zero matrix.
|
|
|
|
#[doc(alias = "Mtx_Zeros")] |
|
|
|
#[doc(alias = "Mtx_Zeros")] |
|
|
|