mirror of https://github.com/wayvr-org/wayvr.git
align_to_hmd regardless of Positioning
This commit is contained in:
parent
f4523f3ab1
commit
4eeb0afb0b
|
|
@ -65,11 +65,9 @@
|
|||
<label translation="EDIT_MODE.INTERPOLATION" />
|
||||
<Slider id="lerp_slider" width="250" height="16" min_value="0.05" max_value="1" value="1" step="0.05" />
|
||||
</div>
|
||||
<div id="pos_align_to_hmd" >
|
||||
<CheckBox id="align_box" translation="EDIT_MODE.ALIGN_TO_HMD" tooltip_side="bottom" />
|
||||
</div>
|
||||
<div id="pos_global" gap="16" justify_content="center" align_items="center">
|
||||
<CheckBox id="global_box" translation="EDIT_MODE.GLOBAL" tooltip_side="bottom" />
|
||||
<CheckBox id="align_box" translation="EDIT_MODE.ALIGN_TO_HMD" tooltip_side="bottom" />
|
||||
<CheckBox id="block_input_box" translation="EDIT_MODE.BLOCK_INPUT" tooltip_side="bottom" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -868,11 +868,8 @@ fn start_grab(
|
|||
.notify(app, OverlayEventData::OverlayGrabbed { name, pos, editing })
|
||||
.inspect_err(|e| log::warn!("Error during Notify OverlayGrabbed: {e:?}"));
|
||||
|
||||
o.default_state.positioning = Positioning::FollowHand {
|
||||
hand,
|
||||
lerp: 0.1,
|
||||
align_to_hmd: true,
|
||||
};
|
||||
o.default_state.positioning = Positioning::FollowHand { hand, lerp: 0.1 };
|
||||
o.default_state.align_to_hmd = true;
|
||||
o.activate(app);
|
||||
}),
|
||||
)));
|
||||
|
|
@ -992,30 +989,22 @@ where
|
|||
if &*overlay.config.name == WATCH_NAME {
|
||||
// watch special: when dropped, follow the hand that wasn't grabbing
|
||||
if let Some(overlay_state) = overlay.config.active_state.as_mut() {
|
||||
let align_to_hmd = overlay_state.align_to_hmd;
|
||||
overlay_state.positioning = match overlay_state.positioning {
|
||||
Positioning::FollowHand {
|
||||
hand,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
} => match pointer.hand() {
|
||||
Positioning::FollowHand { hand, lerp } => match pointer.hand() {
|
||||
Some(LeftRight::Left) => Positioning::FollowHand {
|
||||
hand: LeftRight::Right,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
},
|
||||
Some(LeftRight::Right) => Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
},
|
||||
_ => Positioning::FollowHand {
|
||||
hand,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
},
|
||||
_ => Positioning::FollowHand { hand, lerp },
|
||||
},
|
||||
x => x,
|
||||
};
|
||||
overlay_state.align_to_hmd = align_to_hmd;
|
||||
}
|
||||
} else if overlay.config.global
|
||||
&& let Some(active_state) = overlay.config.active_state.as_ref()
|
||||
|
|
|
|||
|
|
@ -608,7 +608,7 @@ fn reset_panel(
|
|||
let c = panel
|
||||
.parser_state
|
||||
.fetch_component_as::<ComponentCheckbox>("align_box")?;
|
||||
c.set_checked(&mut com, state.positioning.get_align().unwrap_or(false));
|
||||
c.set_checked(&mut com, state.align_to_hmd);
|
||||
|
||||
let c = panel
|
||||
.parser_state
|
||||
|
|
@ -728,7 +728,7 @@ const fn cb_assign_additive(_app: &mut AppState, owc: &mut OverlayWindowConfig,
|
|||
const fn cb_assign_align(_app: &mut AppState, owc: &mut OverlayWindowConfig, align: bool) {
|
||||
owc.dirty = true;
|
||||
let active_state = owc.active_state.as_mut().unwrap();
|
||||
active_state.positioning = active_state.positioning.with_align(align);
|
||||
active_state.align_to_hmd = align;
|
||||
}
|
||||
|
||||
const fn cb_assign_global(_app: &mut AppState, owc: &mut OverlayWindowConfig, global: bool) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ static POS_NAMES: [&str; 6] = ["static", "anchored", "floating", "hmd", "hand_l"
|
|||
pub struct PosTabState {
|
||||
pos: Positioning,
|
||||
has_lerp: bool,
|
||||
has_align: bool,
|
||||
}
|
||||
|
||||
impl From<Positioning> for PosTabState {
|
||||
|
|
@ -23,7 +22,6 @@ impl From<Positioning> for PosTabState {
|
|||
Self {
|
||||
pos: value,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +30,6 @@ pub fn new_pos_tab_handler(
|
|||
panel: &mut EditModeWrapPanel,
|
||||
) -> anyhow::Result<SpriteTabHandler<PosTabState>> {
|
||||
let interpolation_id = panel.parser_state.get_widget_id("pos_interpolation")?;
|
||||
let align_to_hmd_id = panel.parser_state.get_widget_id("pos_align_to_hmd")?;
|
||||
|
||||
SpriteTabHandler::new(
|
||||
panel,
|
||||
|
|
@ -50,9 +47,6 @@ pub fn new_pos_tab_handler(
|
|||
common
|
||||
.alterables
|
||||
.set_widget_visible(interpolation_id, state.has_lerp);
|
||||
common
|
||||
.alterables
|
||||
.set_widget_visible(align_to_hmd_id, state.has_align);
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
|
@ -80,40 +74,32 @@ impl SpriteTabKey for PosTabState {
|
|||
"static" => Self {
|
||||
pos: Positioning::Static,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"anchored" => Self {
|
||||
pos: Positioning::Anchored,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"floating" => Self {
|
||||
pos: Positioning::Floating,
|
||||
has_lerp: false,
|
||||
has_align: false,
|
||||
},
|
||||
"hmd" => Self {
|
||||
pos: Positioning::FollowHead { lerp: 1.0 },
|
||||
has_lerp: true,
|
||||
has_align: false,
|
||||
},
|
||||
"hand_l" => Self {
|
||||
pos: Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
},
|
||||
has_lerp: true,
|
||||
has_align: true,
|
||||
},
|
||||
"hand_r" => Self {
|
||||
pos: Positioning::FollowHand {
|
||||
hand: LeftRight::Right,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
},
|
||||
has_lerp: true,
|
||||
has_align: true,
|
||||
},
|
||||
_ => {
|
||||
panic!("cannot translate to positioning: {key}")
|
||||
|
|
|
|||
|
|
@ -32,7 +32,11 @@ pub const PASSTHRU_PREFIX: &str = "__wvr_passthru-";
|
|||
static PASSTHRU_COUNTER: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
pub fn new_passtrhu_name() -> Arc<str> {
|
||||
format!("{PASSTHRU_PREFIX}{}", PASSTHRU_COUNTER.fetch_add(1, Ordering::Relaxed)).into()
|
||||
format!(
|
||||
"{PASSTHRU_PREFIX}{}",
|
||||
PASSTHRU_COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn new_passthru(name: Arc<str>, app: &AppState) -> OverlayWindowConfig {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,6 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<OverlayWindowConfig> {
|
|||
let relative_to = Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 0.1,
|
||||
align_to_hmd: true,
|
||||
};
|
||||
(vec3(0., 0., 0.), Quat::IDENTITY, relative_to)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
|||
let positioning = Positioning::FollowHand {
|
||||
hand: LeftRight::Left,
|
||||
lerp: 1.0,
|
||||
align_to_hmd: false,
|
||||
};
|
||||
|
||||
panel.update_layout(app)?;
|
||||
|
|
|
|||
|
|
@ -155,18 +155,12 @@ impl OverlayWindowConfig {
|
|||
.unwrap_or(self.default_state.transform);
|
||||
let scale = scalar_scale(&cur_transform);
|
||||
|
||||
let (parent_transform, lerp, align_to_hmd) = match state.positioning {
|
||||
Positioning::FollowHead { lerp } => (app.input_state.hmd, lerp, false),
|
||||
Positioning::FollowHand {
|
||||
hand,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
} => (
|
||||
app.input_state.pointers[hand as usize].pose,
|
||||
lerp,
|
||||
align_to_hmd,
|
||||
),
|
||||
Positioning::Anchored => (app.anchor, 1.0, false),
|
||||
let (parent_transform, lerp) = match state.positioning {
|
||||
Positioning::FollowHead { lerp } => (app.input_state.hmd, lerp),
|
||||
Positioning::FollowHand { hand, lerp } => {
|
||||
(app.input_state.pointers[hand as usize].pose, lerp)
|
||||
}
|
||||
Positioning::Anchored => (app.anchor, 1.0),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
@ -192,7 +186,7 @@ impl OverlayWindowConfig {
|
|||
}
|
||||
};
|
||||
|
||||
if align_to_hmd {
|
||||
if state.align_to_hmd {
|
||||
realign(
|
||||
&mut state.transform,
|
||||
&app.input_state.hmd,
|
||||
|
|
@ -233,17 +227,15 @@ impl OverlayWindowConfig {
|
|||
.saved_transform
|
||||
.unwrap_or(self.default_state.transform);
|
||||
|
||||
let (parent_transform, align_to_hmd) = match state.positioning {
|
||||
Positioning::Floating | Positioning::FollowHead { .. } => (app.input_state.hmd, false),
|
||||
Positioning::FollowHand {
|
||||
hand, align_to_hmd, ..
|
||||
} => (app.input_state.pointers[hand as usize].pose, align_to_hmd),
|
||||
Positioning::Anchored => (app.anchor, false),
|
||||
let parent_transform = match state.positioning {
|
||||
Positioning::Floating | Positioning::FollowHead { .. } => app.input_state.hmd,
|
||||
Positioning::FollowHand { hand, .. } => app.input_state.pointers[hand as usize].pose,
|
||||
Positioning::Anchored => app.anchor,
|
||||
Positioning::Static => {
|
||||
if hard_reset {
|
||||
(app.input_state.hmd, false)
|
||||
app.input_state.hmd
|
||||
} else {
|
||||
(Affine3A::IDENTITY, false)
|
||||
Affine3A::IDENTITY
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -254,7 +246,7 @@ impl OverlayWindowConfig {
|
|||
|
||||
state.transform = parent_transform * cur_transform;
|
||||
|
||||
if align_to_hmd || (state.grabbable && hard_reset) {
|
||||
if state.align_to_hmd || (state.grabbable && hard_reset) {
|
||||
let scale = scalar_scale(&cur_transform);
|
||||
realign(
|
||||
&mut state.transform,
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ pub enum Positioning {
|
|||
hand: LeftRight,
|
||||
#[serde(default)]
|
||||
lerp: f32,
|
||||
#[serde(default)]
|
||||
align_to_hmd: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -43,21 +41,6 @@ impl Positioning {
|
|||
}
|
||||
self
|
||||
}
|
||||
pub const fn get_align(self) -> Option<bool> {
|
||||
match self {
|
||||
Self::FollowHand { align_to_hmd, .. } => Some(align_to_hmd),
|
||||
Self::FollowHead { .. } | Self::Floating | Self::Anchored | Self::Static => None,
|
||||
}
|
||||
}
|
||||
pub const fn with_align(mut self, value: bool) -> Self {
|
||||
match self {
|
||||
Self::FollowHand {
|
||||
ref mut align_to_hmd, ..
|
||||
} => *align_to_hmd = value,
|
||||
Self::FollowHead { .. } | Self::Floating | Self::Anchored | Self::Static => {}
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// Contains the window state for a given set
|
||||
|
|
@ -75,6 +58,8 @@ pub struct OverlayWindowState {
|
|||
pub saved_transform: Option<Affine3A>,
|
||||
pub block_input: bool,
|
||||
pub angle_fade: bool,
|
||||
#[serde(default)]
|
||||
pub align_to_hmd: bool,
|
||||
}
|
||||
|
||||
impl Default for OverlayWindowState {
|
||||
|
|
@ -90,6 +75,7 @@ impl Default for OverlayWindowState {
|
|||
saved_transform: None,
|
||||
block_input: true,
|
||||
angle_fade: false,
|
||||
align_to_hmd: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue