use core::fmt::{Debug, Display, Formatter};
use glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3, Vec3A};
#[derive(Clone, Copy, Default, PartialEq)]
#[repr(C)]
#[spirv(matrix)]
#[allow(missing_docs)]
pub struct Matrix4x3 {
pub x_axis: Vec3A,
pub y_axis: Vec3A,
pub z_axis: Vec3A,
pub w_axis: Vec3A,
}
impl Matrix4x3 {
pub fn from_affine3a(affine: Affine3A) -> Self {
Self {
x_axis: affine.x_axis,
y_axis: affine.y_axis,
z_axis: affine.z_axis,
w_axis: affine.w_axis,
}
}
pub fn from_mat3(mat3: Mat3) -> Self {
Self::from_affine3a(Affine3A::from_mat3(mat3))
}
pub fn from_mat3_translation(mat3: Mat3, translation: Vec3) -> Self {
Self::from_affine3a(Affine3A::from_mat3_translation(mat3, translation))
}
pub fn from_mat4(m: Mat4) -> Self {
Self::from_affine3a(Affine3A::from_mat4(m))
}
pub fn to_affine3a(self) -> Affine3A {
Affine3A {
matrix3: Mat3A {
x_axis: self.x_axis,
y_axis: self.y_axis,
z_axis: self.z_axis,
},
translation: self.w_axis,
}
}
pub fn to_mat3a(self) -> Mat3A {
self.to_affine3a().matrix3
}
pub fn to_mat3(self) -> Mat3 {
Mat3::from(self.to_mat3a())
}
pub fn to_mat4(self) -> Mat4 {
Mat4::from(self.to_affine3a())
}
}
impl Debug for Matrix4x3 {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
Debug::fmt(&self.to_mat4(), f)
}
}
impl Display for Matrix4x3 {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
Display::fmt(&self.to_mat4(), f)
}
}