1use glam::{Affine3A, Mat3, Vec3, Vec3Swizzles, Vec4};
2
3#[cfg(feature = "bevy_reflect")]
4use bevy_reflect::Reflect;
5
6#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
10pub struct Affine3 {
11 pub matrix3: Mat3,
13 pub translation: Vec3,
15}
16
17impl Affine3 {
18 #[inline]
20 pub fn to_transpose(&self) -> [Vec4; 3] {
21 let transpose_3x3 = self.matrix3.transpose();
22 [
23 transpose_3x3.x_axis.extend(self.translation.x),
24 transpose_3x3.y_axis.extend(self.translation.y),
25 transpose_3x3.z_axis.extend(self.translation.z),
26 ]
27 }
28
29 #[inline]
31 pub fn inverse_transpose_3x3(&self) -> ([Vec4; 2], f32) {
32 let inverse_transpose_3x3 = Affine3A::from(self).inverse().matrix3.transpose();
33 (
34 [
35 (inverse_transpose_3x3.x_axis, inverse_transpose_3x3.y_axis.x).into(),
36 (
37 inverse_transpose_3x3.y_axis.yz(),
38 inverse_transpose_3x3.z_axis.xy(),
39 )
40 .into(),
41 ],
42 inverse_transpose_3x3.z_axis.z,
43 )
44 }
45}
46
47impl From<&Affine3A> for Affine3 {
48 fn from(affine: &Affine3A) -> Self {
49 Self {
50 matrix3: affine.matrix3.into(),
51 translation: affine.translation.into(),
52 }
53 }
54}
55
56impl From<&Affine3> for Affine3A {
57 fn from(affine3: &Affine3) -> Self {
58 Self {
59 matrix3: affine3.matrix3.into(),
60 translation: affine3.translation.into(),
61 }
62 }
63}