recenter on show

This commit is contained in:
galister
2024-02-04 02:11:32 +01:00
parent e384e96939
commit b5d970e5fd
8 changed files with 32 additions and 13 deletions

View File

@@ -97,7 +97,7 @@ where
self.overlays.values_mut() self.overlays.values_mut()
} }
pub fn show_hide(&mut self) { pub fn show_hide(&mut self, app: &mut AppState) {
let any_shown = self let any_shown = self
.overlays .overlays
.values() .values()
@@ -106,6 +106,9 @@ where
self.overlays.values_mut().for_each(|o| { self.overlays.values_mut().for_each(|o| {
if o.state.show_hide { if o.state.show_hide {
o.state.want_visible = !any_shown; o.state.want_visible = !any_shown;
if o.state.want_visible && app.session.recenter_on_show {
o.state.reset(app, false);
}
} }
}) })
} }

View File

@@ -421,7 +421,6 @@ impl Pointer {
grab_data.offset.z -= self.now.scroll * 0.05; grab_data.offset.z -= self.now.scroll * 0.05;
} }
_ => { _ => {
log::warn!("scale: {}", self.now.scroll);
overlay.state.transform.matrix3 = overlay overlay.state.transform.matrix3 = overlay
.state .state
.transform .transform
@@ -433,7 +432,9 @@ impl Pointer {
overlay.state.realign(hmd); overlay.state.realign(hmd);
overlay.state.dirty = true; overlay.state.dirty = true;
} else { } else {
overlay.state.spawn_point = overlay.state.transform.translation.into(); overlay.state.spawn_point = hmd
.inverse()
.transform_point3a(overlay.state.transform.translation);
self.interaction.grabbed = None; self.interaction.grabbed = None;
log::info!("Hand {}: dropped {}", self.idx, overlay.state.name); log::info!("Hand {}: dropped {}", self.idx, overlay.state.name);
} }

View File

@@ -153,7 +153,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
.iter() .iter()
.any(|p| p.now.show_hide && !p.before.show_hide) .any(|p| p.now.show_hide && !p.before.show_hide)
{ {
overlays.show_hide(); overlays.show_hide(&mut state);
} }
overlays overlays

View File

@@ -200,7 +200,7 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
.any(|p| p.now.show_hide && !p.before.show_hide) .any(|p| p.now.show_hide && !p.before.show_hide)
{ {
if show_hide_counter.click() { if show_hide_counter.click() {
overlays.show_hide(); overlays.show_hide(&mut app_state);
} }
} }

View File

@@ -103,15 +103,20 @@ impl OverlayState {
} }
} }
pub fn reset(&mut self, app: &mut AppState) { pub fn reset(&mut self, app: &mut AppState, reset_scale: bool) {
let translation = app.input_state.hmd.transform_point3a(self.spawn_point); let translation = app.input_state.hmd.transform_point3a(self.spawn_point);
let scale = if reset_scale {
self.spawn_scale
} else {
self.transform.x_axis.length()
};
self.transform = Affine3A::from_scale_rotation_translation( self.transform = Affine3A::from_scale_rotation_translation(
Vec3::ONE * self.spawn_scale, Vec3::ONE * scale,
Quat::IDENTITY, Quat::IDENTITY,
translation.into(), translation.into(),
); );
self.realign(&app.input_state.hmd); self.realign(&app.input_state.hmd);
self.dirty = true;
} }
pub fn realign(&mut self, hmd: &Affine3A) { pub fn realign(&mut self, hmd: &Affine3A) {
@@ -160,7 +165,7 @@ where
T: Default, T: Default,
{ {
pub fn init(&mut self, app: &mut AppState) { pub fn init(&mut self, app: &mut AppState) {
self.state.reset(app); self.state.reset(app, true);
self.backend.init(app); self.backend.init(app);
} }
pub fn render(&mut self, app: &mut AppState) { pub fn render(&mut self, app: &mut AppState) {

View File

@@ -99,16 +99,19 @@ where
{ {
app.tasks.enqueue(TaskType::Overlay( app.tasks.enqueue(TaskType::Overlay(
OverlaySelector::Name("kbd".into()), OverlaySelector::Name("kbd".into()),
Box::new(|_app, o| { Box::new(|app, o| {
o.show_hide = !o.show_hide; o.show_hide = !o.show_hide;
o.want_visible = o.show_hide; o.want_visible = o.show_hide;
if app.session.recenter_on_show {
o.reset(app, false);
}
}), }),
)); ));
} else { } else {
app.tasks.enqueue(TaskType::Overlay( app.tasks.enqueue(TaskType::Overlay(
OverlaySelector::Name("kbd".into()), OverlaySelector::Name("kbd".into()),
Box::new(|app, o| { Box::new(|app, o| {
o.reset(app); o.reset(app, true);
}), }),
)); ));
} }
@@ -146,16 +149,19 @@ where
{ {
app.tasks.enqueue(TaskType::Overlay( app.tasks.enqueue(TaskType::Overlay(
OverlaySelector::Id(scr_idx), OverlaySelector::Id(scr_idx),
Box::new(|_app, o| { Box::new(|app, o| {
o.show_hide = !o.show_hide; o.show_hide = !o.show_hide;
o.want_visible = o.show_hide; o.want_visible = o.show_hide;
if app.session.recenter_on_show {
o.reset(app, false);
}
}), }),
)); ));
} else { } else {
app.tasks.enqueue(TaskType::Overlay( app.tasks.enqueue(TaskType::Overlay(
OverlaySelector::Id(scr_idx), OverlaySelector::Id(scr_idx),
Box::new(|app, o| { Box::new(|app, o| {
o.reset(app); o.reset(app, true);
}), }),
)); ));
} }

View File

@@ -3,6 +3,8 @@
# Default: 300 # Default: 300
click_freeze_time_ms: 300 click_freeze_time_ms: 300
recenter_on_show: true
# Default: true # Default: true
keyboard_sound_enabled: true keyboard_sound_enabled: true

View File

@@ -77,6 +77,7 @@ pub struct AppSession {
pub config: GeneralConfig, pub config: GeneralConfig,
pub show_screens: Vec<String>, pub show_screens: Vec<String>,
pub recenter_on_show: bool,
pub watch_hand: usize, pub watch_hand: usize,
pub watch_pos: Vec3, pub watch_pos: Vec3,
@@ -102,6 +103,7 @@ impl AppSession {
config_root_path, config_root_path,
config, config,
show_screens: vec!["DP-3".to_string()], show_screens: vec!["DP-3".to_string()],
recenter_on_show: true,
capture_method: "auto".to_string(), capture_method: "auto".to_string(),
primary_hand: 1, primary_hand: 1,
watch_hand: 0, watch_hand: 0,