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);

View File

@@ -230,6 +230,7 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
app_state.input_state.pointers[idx].pose,
*len,
app_state.input_state.pointers[idx].interaction.mode as usize + 1,
&app_state.input_state.hmd,
);
}
@@ -253,6 +254,10 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let dist_sq = (app_state.input_state.hmd.translation - o.state.transform.translation)
.length_squared();
if !dist_sq.is_normal() {
continue;
}
if let Some(quad) = o.present_xr(&xr_state, &mut command_buffer) {
layers.push((dist_sq, quad));
};
@@ -264,7 +269,7 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
command_buffer.build_and_execute_now();
layers.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap());
layers.sort_by(|a, b| b.0.total_cmp(&a.0));
let frame_ref = layers
.iter()