laser billboard & sorting fix

This commit is contained in:
galister
2024-02-03 13:44:21 +01:00
parent 6786f997d1
commit c249b5ec2a
6 changed files with 89 additions and 18 deletions

View File

@@ -68,7 +68,14 @@ impl LinePool {
id
}
pub(super) fn draw_from(&mut self, id: usize, mut from: Affine3A, len: f32, color: usize) {
pub(super) fn draw_from(
&mut self,
id: usize,
mut from: Affine3A,
len: f32,
color: usize,
hmd: &Affine3A,
) {
if len < 0.01 {
return;
}
@@ -83,7 +90,25 @@ impl LinePool {
let rotation = Affine3A::from_axis_angle(Vec3::X, PI * 1.5);
from.translation = from.translation + from.transform_vector3a(Vec3A::NEG_Z) * (len * 0.5);
let transform = from * rotation;
let mut transform = from * rotation;
let to_hmd = hmd.translation - from.translation;
let sides = [Vec3A::Z, Vec3A::X, Vec3A::NEG_Z, Vec3A::NEG_X];
let rotations = [
Affine3A::IDENTITY,
Affine3A::from_axis_angle(Vec3::Y, PI * 0.5),
Affine3A::from_axis_angle(Vec3::Y, PI * -1.0),
Affine3A::from_axis_angle(Vec3::Y, PI * 1.5),
];
let mut closest = (0, 0.0);
for (i, &side) in sides.iter().enumerate() {
let dot = to_hmd.dot(transform.transform_vector3a(side));
if i == 0 || dot > closest.1 {
closest = (i, dot);
}
}
transform = transform * rotations[closest.0];
let posef = transform_to_posef(&transform);