mirror of
https://github.com/wayvr-org/wayvr.git
synced 2026-11-24 02:51:19 -08:00
wayvr: openxr: Space gravity: Allow for space rotate at the same time (#707)
This commit is contained in:
1 parent
58ac4bcd84
commit
2d4ded94c7
2 files changed
+65
-14
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use glam::{Affine3A, Mat3A, Quat, Vec3, Vec3A, vec3a};
|
||||
use libmonado::{Monado, Pose, ReferenceSpaceType};
|
||||
use wgui::log::LogErr;
|
||||
use wlx_common::config::GeneralConfig;
|
||||
|
||||
use crate::{
|
||||
backend::{
|
||||
@@ -26,6 +27,11 @@ pub(super) struct PlayspaceMover {
|
||||
playspace_state: PlayspaceState,
|
||||
}
|
||||
|
||||
struct SpaceGravityStepResult {
|
||||
pose_prev: Affine3A,
|
||||
playspace_offset_delta: Vec3A,
|
||||
}
|
||||
|
||||
impl PlayspaceMover {
|
||||
pub fn new() -> Self {
|
||||
log::info!("Monado: using space offset API");
|
||||
@@ -124,10 +130,17 @@ impl PlayspaceMover {
|
||||
data.pose.matrix3 = Mat3A::from_quat(Quat::from_affine3(&data.pose).normalize());
|
||||
}
|
||||
|
||||
data.hand_pose = new_hand;
|
||||
|
||||
if let Some(res_step) =
|
||||
self.space_gravity_step(&mut monado.ipc, &app.session.config, app.delta_time, false)
|
||||
{
|
||||
data.pose.translation += res_step.playspace_offset_delta;
|
||||
}
|
||||
|
||||
if !app.session.config.space_drag_affects_world {
|
||||
playspace_common::shift_world(overlays, &mut app.anchor, &before_pose, &data.pose);
|
||||
}
|
||||
data.hand_pose = new_hand;
|
||||
|
||||
apply_offset(data.pose, &mut monado.ipc);
|
||||
self.rotate = Some(data);
|
||||
@@ -231,23 +244,57 @@ impl PlayspaceMover {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(res) = self.gravity.update(SpaceGravityUpdateParams {
|
||||
dt: app.delta_time,
|
||||
dragging: self.drag.is_some(),
|
||||
config: &app.session.config,
|
||||
floor_height: app.session.config.space_gravity_floor_height,
|
||||
}) {
|
||||
let prev_playspace_pos = res.playspace_pos - res.playspace_pos_offset;
|
||||
let before_pose = Affine3A::from_translation(prev_playspace_pos.into());
|
||||
let after_pose = Affine3A::from_translation(res.playspace_pos.into());
|
||||
apply_offset(after_pose, &mut monado.ipc);
|
||||
// no drag/rotate
|
||||
if let Some(res_step) = self.space_gravity_step(
|
||||
&mut monado.ipc,
|
||||
&app.session.config,
|
||||
app.delta_time,
|
||||
self.drag.is_some(),
|
||||
) {
|
||||
let mut pose = res_step.pose_prev;
|
||||
pose.translation += res_step.playspace_offset_delta;
|
||||
apply_offset(pose, &mut monado.ipc);
|
||||
|
||||
if !app.session.config.space_drag_affects_world {
|
||||
playspace_common::shift_world(overlays, &mut app.anchor, &before_pose, &after_pose);
|
||||
playspace_common::shift_world(
|
||||
overlays,
|
||||
&mut app.anchor,
|
||||
&res_step.pose_prev,
|
||||
&pose,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn space_gravity_step(
|
||||
&mut self,
|
||||
monado: &mut Monado,
|
||||
config: &GeneralConfig,
|
||||
dt: f32,
|
||||
dragging: bool,
|
||||
) -> Option<SpaceGravityStepResult> {
|
||||
let Ok(pose) = monado
|
||||
.get_reference_space_offset(ReferenceSpaceType::Stage)
|
||||
.log_err("Could not get reference space offset.")
|
||||
.map(|p| Affine3A::from_rotation_translation(p.orientation.into(), p.position.into()))
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let res = self.gravity.update(SpaceGravityUpdateParams {
|
||||
dt,
|
||||
dragging,
|
||||
config,
|
||||
floor_height: config.space_gravity_floor_height,
|
||||
current_space_pos: pose.translation,
|
||||
})?;
|
||||
|
||||
Some(SpaceGravityStepResult {
|
||||
pose_prev: pose,
|
||||
playspace_offset_delta: res.playspace_pos_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn recenter(
|
||||
&mut self,
|
||||
app: &mut AppState,
|
||||
@@ -379,6 +426,7 @@ impl PlayspaceMover {
|
||||
log::info!("Space rotate interrupted by fix floor");
|
||||
self.rotate = None;
|
||||
}
|
||||
self.gravity.reset();
|
||||
|
||||
let input = &app.input_state;
|
||||
let anchor = &mut app.anchor;
|
||||
|
||||
@@ -8,6 +8,9 @@ pub struct SpaceGravityUpdateParams<'a> {
|
||||
pub dragging: bool,
|
||||
pub config: &'a GeneralConfig,
|
||||
pub floor_height: f32,
|
||||
|
||||
// current playspace offset
|
||||
pub current_space_pos: Vec3A,
|
||||
}
|
||||
|
||||
pub struct SpaceGravity {
|
||||
@@ -34,7 +37,6 @@ pub fn shift_world<OverlayData>(
|
||||
}
|
||||
|
||||
pub struct SpaceGravityUpdateResult {
|
||||
pub playspace_pos: Vec3A,
|
||||
pub playspace_pos_offset: Vec3A, // position difference compared to previous update() call
|
||||
}
|
||||
|
||||
@@ -71,6 +73,8 @@ impl SpaceGravity {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.space_pos = par.current_space_pos;
|
||||
|
||||
let prev_pos = self.space_pos;
|
||||
|
||||
self.velocity.y += par.config.space_gravity_gravity * par.dt;
|
||||
@@ -94,7 +98,6 @@ impl SpaceGravity {
|
||||
if self.velocity.length_squared() > 0.00003 {
|
||||
// Space position changed
|
||||
return Some(SpaceGravityUpdateResult {
|
||||
playspace_pos: self.space_pos,
|
||||
playspace_pos_offset: self.space_pos - prev_pos,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user