feat(objects): simulated input switching
This commit is contained in:
@@ -230,12 +230,7 @@ fn stereokit_loop(
|
|||||||
sk_ready_notifier.notify_waiters();
|
sk_ready_notifier.notify_waiters();
|
||||||
info!("Stardust ready!");
|
info!("Stardust ready!");
|
||||||
|
|
||||||
let mut objects = ServerObjects::new(
|
let mut objects = ServerObjects::new(&sk, hmd, World::has_bounds().then_some(play_space));
|
||||||
intentional_flatscreen,
|
|
||||||
&sk,
|
|
||||||
hmd,
|
|
||||||
World::has_bounds().then_some(play_space),
|
|
||||||
);
|
|
||||||
if World::has_bounds() && World::get_bounds_size().x != 0.0 && World::get_bounds_size().y != 0.0
|
if World::has_bounds() && World::get_bounds_size().x != 0.0 && World::get_bounds_size().y != 0.0
|
||||||
{
|
{
|
||||||
let dbus_connection = dbus_connection.clone();
|
let dbus_connection = dbus_connection.clone();
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ impl Default for MouseEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||||
#[derive(Default)]
|
|
||||||
pub struct KeyboardEvent {
|
pub struct KeyboardEvent {
|
||||||
pub keyboard: (),
|
pub keyboard: (),
|
||||||
pub xkbv1: (),
|
pub xkbv1: (),
|
||||||
@@ -370,9 +369,9 @@ fn map_key(key: Key) -> Option<u32> {
|
|||||||
Key::F3 => Some(input_event_codes::KEY_F3!()),
|
Key::F3 => Some(input_event_codes::KEY_F3!()),
|
||||||
Key::F4 => Some(input_event_codes::KEY_F4!()),
|
Key::F4 => Some(input_event_codes::KEY_F4!()),
|
||||||
Key::F5 => Some(input_event_codes::KEY_F5!()),
|
Key::F5 => Some(input_event_codes::KEY_F5!()),
|
||||||
Key::F6 => Some(input_event_codes::KEY_F6!()),
|
// Key::F6 => Some(input_event_codes::KEY_F6!()),
|
||||||
Key::F7 => Some(input_event_codes::KEY_F7!()),
|
// Key::F7 => Some(input_event_codes::KEY_F7!()),
|
||||||
Key::F8 => Some(input_event_codes::KEY_F8!()),
|
// Key::F8 => Some(input_event_codes::KEY_F8!()),
|
||||||
Key::F9 => Some(input_event_codes::KEY_F9!()),
|
Key::F9 => Some(input_event_codes::KEY_F9!()),
|
||||||
Key::F10 => Some(input_event_codes::KEY_F10!()),
|
Key::F10 => Some(input_event_codes::KEY_F10!()),
|
||||||
Key::F11 => Some(input_event_codes::KEY_F11!()),
|
Key::F11 => Some(input_event_codes::KEY_F11!()),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use input::{
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit_rust::{
|
use stereokit_rust::{
|
||||||
sk::{DisplayMode, MainThreadToken, Sk},
|
sk::{DisplayMode, MainThreadToken, Sk},
|
||||||
system::{Handed, Input, World},
|
system::{Handed, Input, Key, World},
|
||||||
util::Device,
|
util::Device,
|
||||||
};
|
};
|
||||||
use zbus::{interface, Connection};
|
use zbus::{interface, Connection};
|
||||||
@@ -24,47 +24,47 @@ use zbus::{interface, Connection};
|
|||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod play_space;
|
pub mod play_space;
|
||||||
|
|
||||||
|
enum Inputs {
|
||||||
|
XR {
|
||||||
|
controllers: (SkController, SkController),
|
||||||
|
hands: (SkHand, SkHand),
|
||||||
|
eye_pointer: Option<EyePointer>,
|
||||||
|
},
|
||||||
|
MousePointer(MousePointer),
|
||||||
|
Controllers((SkController, SkController)),
|
||||||
|
Hands((SkHand, SkHand)),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ServerObjects {
|
pub struct ServerObjects {
|
||||||
hmd: Arc<Spatial>,
|
hmd: Arc<Spatial>,
|
||||||
play_space: Option<Arc<Spatial>>,
|
play_space: Option<Arc<Spatial>>,
|
||||||
mouse_pointer: Option<MousePointer>,
|
inputs: Inputs,
|
||||||
hands: Option<(SkHand, SkHand)>,
|
|
||||||
controllers: Option<(SkController, SkController)>,
|
|
||||||
eye_pointer: Option<EyePointer>,
|
|
||||||
}
|
}
|
||||||
impl ServerObjects {
|
impl ServerObjects {
|
||||||
pub fn new(
|
pub fn new(sk: &Sk, hmd: Arc<Spatial>, play_space: Option<Arc<Spatial>>) -> ServerObjects {
|
||||||
intentional_flatscreen: bool,
|
let inputs = if sk.get_active_display_mode() == DisplayMode::MixedReality {
|
||||||
sk: &Sk,
|
Inputs::XR {
|
||||||
hmd: Arc<Spatial>,
|
controllers: (
|
||||||
play_space: Option<Arc<Spatial>>,
|
SkController::new(Handed::Left).unwrap(),
|
||||||
) -> ServerObjects {
|
SkController::new(Handed::Right).unwrap(),
|
||||||
|
),
|
||||||
|
hands: (
|
||||||
|
SkHand::new(Handed::Left).unwrap(),
|
||||||
|
SkHand::new(Handed::Right).unwrap(),
|
||||||
|
),
|
||||||
|
eye_pointer: Device::has_eye_gaze()
|
||||||
|
.then(EyePointer::new)
|
||||||
|
.transpose()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Inputs::MousePointer(MousePointer::new().unwrap())
|
||||||
|
};
|
||||||
|
|
||||||
ServerObjects {
|
ServerObjects {
|
||||||
hmd,
|
hmd,
|
||||||
play_space,
|
play_space,
|
||||||
mouse_pointer: intentional_flatscreen
|
inputs,
|
||||||
.then(MousePointer::new)
|
|
||||||
.transpose()
|
|
||||||
.unwrap(),
|
|
||||||
hands: (!intentional_flatscreen)
|
|
||||||
.then(|| {
|
|
||||||
let left = SkHand::new(Handed::Left).ok();
|
|
||||||
let right = SkHand::new(Handed::Right).ok();
|
|
||||||
left.zip(right)
|
|
||||||
})
|
|
||||||
.flatten(),
|
|
||||||
controllers: (!intentional_flatscreen)
|
|
||||||
.then(|| {
|
|
||||||
let left = SkController::new(Handed::Left).ok();
|
|
||||||
let right = SkController::new(Handed::Right).ok();
|
|
||||||
left.zip(right)
|
|
||||||
})
|
|
||||||
.flatten(),
|
|
||||||
eye_pointer: (sk.get_active_display_mode() == DisplayMode::MixedReality
|
|
||||||
&& Device::has_eye_gaze())
|
|
||||||
.then(EyePointer::new)
|
|
||||||
.transpose()
|
|
||||||
.unwrap(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,19 +85,47 @@ impl ServerObjects {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mouse_pointer) = self.mouse_pointer.as_mut() {
|
if sk.get_active_display_mode() != DisplayMode::MixedReality {
|
||||||
mouse_pointer.update();
|
if Input::key(Key::F6).is_just_inactive() {
|
||||||
|
self.inputs = Inputs::MousePointer(MousePointer::new().unwrap());
|
||||||
|
}
|
||||||
|
if Input::key(Key::F7).is_just_inactive() {
|
||||||
|
self.inputs = Inputs::Controllers((
|
||||||
|
SkController::new(Handed::Left).unwrap(),
|
||||||
|
SkController::new(Handed::Right).unwrap(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if Input::key(Key::F8).is_just_inactive() {
|
||||||
|
self.inputs = Inputs::Hands((
|
||||||
|
SkHand::new(Handed::Left).unwrap(),
|
||||||
|
SkHand::new(Handed::Right).unwrap(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some((left_hand, right_hand)) = self.hands.as_mut() {
|
|
||||||
left_hand.update(sk, token);
|
match &mut self.inputs {
|
||||||
right_hand.update(sk, token);
|
Inputs::XR {
|
||||||
}
|
controllers: (left_controller, right_controller),
|
||||||
if let Some((left_controller, right_controller)) = self.controllers.as_mut() {
|
hands: (left_hand, right_hand),
|
||||||
left_controller.update(token);
|
eye_pointer,
|
||||||
right_controller.update(token);
|
} => {
|
||||||
}
|
left_hand.update(sk, token);
|
||||||
if let Some(eye_pointer) = self.eye_pointer.as_ref() {
|
right_hand.update(sk, token);
|
||||||
eye_pointer.update();
|
left_controller.update(token);
|
||||||
|
right_controller.update(token);
|
||||||
|
if let Some(eye_pointer) = eye_pointer {
|
||||||
|
eye_pointer.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Inputs::MousePointer(mouse_pointer) => mouse_pointer.update(),
|
||||||
|
Inputs::Controllers((left, right)) => {
|
||||||
|
left.update(token);
|
||||||
|
right.update(token);
|
||||||
|
}
|
||||||
|
Inputs::Hands((left, right)) => {
|
||||||
|
left.update(sk, token);
|
||||||
|
right.update(sk, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user