feat: improve screen alighment on show/hide

This commit is contained in:
galister
2024-04-14 17:17:20 +09:00
parent 8e799d1b8f
commit d99a58da9e
5 changed files with 54 additions and 37 deletions

View File

@@ -499,3 +499,23 @@ pub fn raycast_cylinder(
Some((t, hit_local.xy()))
}
pub fn snap_upright(transform: Affine3A, up_dir: Vec3A) -> Affine3A {
if transform.x_axis.dot(up_dir).abs() < 0.2 {
let scale = transform.x_axis.length();
let col_z = transform.z_axis.normalize();
let col_y = up_dir;
let col_x = col_y.cross(col_z);
let col_y = col_z.cross(col_x).normalize();
let col_x = col_x.normalize();
Affine3A::from_cols(
col_x * scale,
col_y * scale,
col_z * scale,
transform.translation,
)
} else {
transform
}
}