From 08a9d8ed66afc47bee410070ff67cc9781163bae Mon Sep 17 00:00:00 2001 From: Nicola Guerrera Date: Sun, 26 Feb 2023 23:40:43 +0100 Subject: [PATCH] Repositioning --- Cargo.lock | 16 +++++--------- Cargo.toml | 4 ++-- examples/app_grid.rs | 6 +----- examples/hexagon_launcher.rs | 4 ---- src/protostar.rs | 42 ++++++++++++++++++++++-------------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aed1c08..5857705 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,12 +66,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "anyhow" -version = "1.0.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" - [[package]] name = "arrayref" version = "0.3.6" @@ -1976,11 +1970,11 @@ dependencies = [ [[package]] name = "stardust-xr-fusion" -version = "0.38.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f6c2945a8246880297b1f059e48a8eeb6ba39c58f67e83c05725b86f869149" +checksum = "45a0a1ee96c4be1d4866e1920feb4fb732b810a6cc2e9f7eeff66f07f9c2f496" dependencies = [ - "anyhow", + "color-eyre", "color-rs", "enum_dispatch", "flagset", @@ -1999,9 +1993,9 @@ dependencies = [ [[package]] name = "stardust-xr-molecules" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ae6569520bc27bd6fc015e4e0a687bb730631dc039bb5c5c14c2ad40457cfac" +checksum = "4c16d448b75aff896519f94910a525bf5588a53cf54d5256a7eef05f604ffce4" dependencies = [ "color-rs", "glam 0.23.0", diff --git a/Cargo.toml b/Cargo.toml index 8943d72..8a15648 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ mint = "0.5.9" nix = "0.26.1" resvg = "0.29.0" rustc-hash = "1.1.0" -stardust-xr-fusion = "0.38.0" -stardust-xr-molecules = "0.21.0" +stardust-xr-fusion = "0.38.1" +stardust-xr-molecules = "0.21.1" tokio = { version = "1.24.1", features = ["full"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tween = "2.0.0" diff --git a/examples/app_grid.rs b/examples/app_grid.rs index 33da3d2..80d394f 100644 --- a/examples/app_grid.rs +++ b/examples/app_grid.rs @@ -95,7 +95,7 @@ impl App { text_align: Alignment::XCenter | Alignment::YCenter, ..Default::default() }; - let protostar = ProtoStar::create_from_desktop_file(parent, desktop_file.clone()).ok()?; + let protostar = ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?; let text = Text::create( protostar.content_parent(), Transform::from_position_rotation( @@ -106,10 +106,6 @@ impl App { style, ) .unwrap(); - protostar - .content_parent() - .set_position(None, position) - .unwrap(); Some(App { _text: text, _desktop_file: desktop_file, diff --git a/examples/hexagon_launcher.rs b/examples/hexagon_launcher.rs index 329d253..0b8331c 100644 --- a/examples/hexagon_launcher.rs +++ b/examples/hexagon_launcher.rs @@ -155,10 +155,6 @@ impl App { style, ) .unwrap(); - protostar - .content_parent() - .set_position(None, position) - .unwrap(); Some(App { _text: text, _desktop_file: desktop_file, diff --git a/src/protostar.rs b/src/protostar.rs index fa23c0b..e73d2be 100644 --- a/src/protostar.rs +++ b/src/protostar.rs @@ -104,7 +104,7 @@ impl ProtoStar { )?; let grabbable = Grabbable::new( parent, - Transform::default(), + Transform::from_position(position), &field, GrabData { max_distance: 0.01, @@ -151,6 +151,9 @@ impl RootHandler for ProtoStar { } else { self.icon_grow = Some(Tweener::quart_in_out(0.0001, 0.03, 0.25)); //TODO make the scale a parameter self.icon_shrink = None; + self.grabbable.content_parent().set_position(Some(self.client.get_root()) , self.position).unwrap(); + self.grabbable.content_parent().set_rotation(Some(self.client.get_root()), Quat::default()).unwrap(); + self.icon.set_rotation(None, Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI) ).unwrap(); } } else if let Some(icon_grow) = &mut self.icon_grow { if !icon_grow.is_finished() { @@ -159,8 +162,6 @@ impl RootHandler for ProtoStar { .set_scale(None, Vector3::from([scale; 3])) .unwrap(); } else { - self.icon.set_position(None, [0.0,0.0,0.0]).unwrap(); - self.icon.set_rotation(None, Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI) ).unwrap(); self.icon_grow = None; } }else if self.grabbable.grab_action().actor_stopped() { @@ -179,22 +180,31 @@ impl RootHandler for ProtoStar { .set_root(self.grabbable.content_parent()) .unwrap(); self.icon_shrink = Some(Tweener::quart_in_out(0.03, 0.0001, 0.25)); //TODO make the scale a parameter - let future = startup_settings.generate_startup_token().unwrap(); + let distance_future = self.grabbable.content_parent().get_position_rotation_scale(self.client.get_root()).unwrap(); + let executable = dbg!(self.execute_command.clone()); + //TODO: split the executable string for the args tokio::task::spawn(async move { - std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap()); - unsafe { - Command::new(executable) - .stdin(Stdio::null()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .pre_exec(|| { - _ = setsid(); - Ok(()) - }) - .spawn() - .expect("Failed to start child process") + let distance_vector = distance_future.await.ok().unwrap().0; + let distance = distance_vector.x.abs() + distance_vector.y.abs() + distance_vector.z.abs(); + if dbg!(distance) > 1.0 { + let future = startup_settings.generate_startup_token().unwrap(); + + std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap()); + + unsafe { + Command::new(executable) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .pre_exec(|| { + _ = setsid(); + Ok(()) + }) + .spawn() + .expect("Failed to start child process"); + } } }); }