openxr: toggle for space rotate axis lock

This commit is contained in:
galister
2024-09-18 04:06:37 +09:00
parent 03f2eaf97f
commit 583a5f7fe0
3 changed files with 28 additions and 8 deletions

View File

@@ -77,19 +77,20 @@ impl PlayspaceMover {
Quat::from_affine3(&(data.pose * state.input_state.pointers[data.hand].raw_pose)); Quat::from_affine3(&(data.pose * state.input_state.pointers[data.hand].raw_pose));
let dq = new_hand * data.hand_pose.conjugate(); let dq = new_hand * data.hand_pose.conjugate();
let rel_y = f32::atan2( let mut space_transform = if state.session.config.space_rotate_unlocked {
2.0 * (dq.y * dq.w + dq.x * dq.z), Affine3A::from_quat(dq)
(2.0 * (dq.w * dq.w + dq.x * dq.x)) - 1.0, } else {
); let rel_y = f32::atan2(
2.0 * (dq.y * dq.w + dq.x * dq.z),
(2.0 * (dq.w * dq.w + dq.x * dq.x)) - 1.0,
);
//let mut space_transform = Affine3A::from_rotation_translation(dq, Vec3::ZERO); Affine3A::from_rotation_y(rel_y)
let mut space_transform = Affine3A::from_rotation_y(rel_y); };
let offset = (space_transform.transform_vector3a(state.input_state.hmd.translation) let offset = (space_transform.transform_vector3a(state.input_state.hmd.translation)
- state.input_state.hmd.translation) - state.input_state.hmd.translation)
* -1.0; * -1.0;
let mut overlay_transform = Affine3A::from_rotation_y(-rel_y);
overlay_transform.translation = offset;
space_transform.translation = offset; space_transform.translation = offset;
data.pose *= space_transform; data.pose *= space_transform;

View File

@@ -270,6 +270,9 @@ pub struct GeneralConfig {
#[serde(default = "def_point3")] #[serde(default = "def_point3")]
pub pointer_lerp_factor: f32, pub pointer_lerp_factor: f32,
#[serde(default = "def_false")]
pub space_rotate_unlocked: bool,
} }
impl GeneralConfig { impl GeneralConfig {

View File

@@ -47,6 +47,7 @@ pub enum HighlightTest {
AutoRealign, AutoRealign,
NotificationSounds, NotificationSounds,
Notifications, Notifications,
RorateLock,
} }
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
@@ -55,6 +56,7 @@ pub enum SystemAction {
ToggleAutoRealign, ToggleAutoRealign,
ToggleNotificationSounds, ToggleNotificationSounds,
ToggleNotifications, ToggleNotifications,
ToggleRotateLock,
PlayspaceResetOffset, PlayspaceResetOffset,
PlayspaceFixFloor, PlayspaceFixFloor,
RecalculateExtent, RecalculateExtent,
@@ -298,6 +300,7 @@ fn modular_button_highlight(
HighlightTest::AutoRealign => app.session.config.realign_on_showhide, HighlightTest::AutoRealign => app.session.config.realign_on_showhide,
HighlightTest::NotificationSounds => app.session.config.notifications_sound_enabled, HighlightTest::NotificationSounds => app.session.config.notifications_sound_enabled,
HighlightTest::Notifications => app.session.config.notifications_enabled, HighlightTest::Notifications => app.session.config.notifications_enabled,
HighlightTest::RorateLock => !app.session.config.space_rotate_unlocked,
}; };
if lit { if lit {
@@ -369,6 +372,19 @@ fn run_system(action: &SystemAction, app: &mut AppState) {
) )
.submit(app); .submit(app);
} }
SystemAction::ToggleRotateLock => {
app.session.config.space_rotate_unlocked = !app.session.config.space_rotate_unlocked;
Toast::new(
ToastTopic::System,
format!(
"Space rotate axis lock now {}.",
ENABLED_DISABLED[!app.session.config.space_rotate_unlocked as usize]
)
.into(),
"".into(),
)
.submit(app);
}
SystemAction::PlayspaceResetOffset => { SystemAction::PlayspaceResetOffset => {
app.tasks app.tasks
.enqueue(TaskType::System(SystemTask::ResetPlayspace)); .enqueue(TaskType::System(SystemTask::ResetPlayspace));