Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_math/src/affine3.rs
9358 views
1
use glam::{Affine3, Affine3A, Vec3Swizzles, Vec4};
2
3
/// Extension trait for [`Affine3`]
4
pub trait Affine3Ext {
5
/// Calculates the transpose of the affine 4x3 matrix to a 3x4 and formats it for packing into GPU buffers
6
fn to_transpose(self) -> [Vec4; 3];
7
/// Calculates the inverse transpose of the 3x3 matrix and formats it for packing into GPU buffers
8
fn inverse_transpose_3x3(self) -> ([Vec4; 2], f32);
9
}
10
11
impl Affine3Ext for Affine3 {
12
#[inline]
13
fn to_transpose(self) -> [Vec4; 3] {
14
let transpose_3x3 = self.matrix3.transpose();
15
[
16
transpose_3x3.x_axis.extend(self.translation.x),
17
transpose_3x3.y_axis.extend(self.translation.y),
18
transpose_3x3.z_axis.extend(self.translation.z),
19
]
20
}
21
22
#[inline]
23
fn inverse_transpose_3x3(self) -> ([Vec4; 2], f32) {
24
let inverse_transpose_3x3 = Affine3A::from(self).inverse().matrix3.transpose();
25
(
26
[
27
(inverse_transpose_3x3.x_axis, inverse_transpose_3x3.y_axis.x).into(),
28
(
29
inverse_transpose_3x3.y_axis.yz(),
30
inverse_transpose_3x3.z_axis.xy(),
31
)
32
.into(),
33
],
34
inverse_transpose_3x3.z_axis.z,
35
)
36
}
37
}
38
39