WayVR: attach_to, pos and rotation spawn parameters in wayvr.yaml config script

This commit is contained in:
Aleksander
2024-10-24 22:44:37 +02:00
parent cf03beef07
commit 8d82993704
3 changed files with 62 additions and 5 deletions

View File

@@ -5,7 +5,38 @@ use std::collections::{BTreeMap, HashMap};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::config::{load_known_yaml, ConfigType}; use crate::{
backend::overlay::RelativeTo,
config::{load_known_yaml, ConfigType},
};
// Flat version of RelativeTo
#[derive(Clone, Deserialize, Serialize)]
pub enum AttachTo {
None,
HandLeft,
HandRight,
Head,
Stage,
}
impl AttachTo {
pub fn get_relative_to(&self) -> RelativeTo {
match self {
AttachTo::None => RelativeTo::None,
AttachTo::HandLeft => RelativeTo::Hand(0),
AttachTo::HandRight => RelativeTo::Hand(1),
AttachTo::Stage => RelativeTo::Stage,
AttachTo::Head => RelativeTo::Head,
}
}
}
#[derive(Clone, Deserialize, Serialize)]
pub struct Rotation {
pub axis: [f32; 3],
pub angle: f32,
}
#[derive(Clone, Deserialize, Serialize)] #[derive(Clone, Deserialize, Serialize)]
pub struct WayVRAppEntry { pub struct WayVRAppEntry {
@@ -21,6 +52,9 @@ pub struct WayVRDisplay {
pub width: u32, pub width: u32,
pub height: u32, pub height: u32,
pub scale: f32, pub scale: f32,
pub rotation: Option<Rotation>,
pub pos: Option<[f32; 3]>,
pub attach_to: Option<AttachTo>,
} }
#[derive(Clone, Deserialize, Serialize)] #[derive(Clone, Deserialize, Serialize)]

View File

@@ -1,4 +1,4 @@
use glam::{vec3a, Affine2}; use glam::{vec3a, Affine2, Vec3, Vec3A};
use serde::Deserialize; use serde::Deserialize;
use std::{cell::RefCell, rc::Rc, sync::Arc}; use std::{cell::RefCell, rc::Rc, sync::Arc};
use vulkano::image::SubresourceLayout; use vulkano::image::SubresourceLayout;
@@ -314,7 +314,8 @@ where
.ok_or(anyhow::anyhow!( .ok_or(anyhow::anyhow!(
"Cannot find display named \"{}\"", "Cannot find display named \"{}\"",
app_entry.target_display app_entry.target_display
))?; ))?
.clone();
let display_handle = wayvr.create_display( let display_handle = wayvr.create_display(
conf_display.width, conf_display.width,
@@ -322,7 +323,7 @@ where
&app_entry.target_display, &app_entry.target_display,
)?; )?;
let overlay = create_wayvr_display_overlay::<O>( let mut overlay = create_wayvr_display_overlay::<O>(
app, app,
conf_display.width, conf_display.width,
conf_display.height, conf_display.height,
@@ -330,6 +331,21 @@ where
conf_display.scale, conf_display.scale,
)?; )?;
if let Some(attach_to) = &conf_display.attach_to {
overlay.state.relative_to = attach_to.get_relative_to();
}
if let Some(rot) = &conf_display.rotation {
overlay.state.spawn_rotation = glam::Quat::from_axis_angle(
Vec3::from_slice(&rot.axis),
f32::to_radians(rot.angle),
);
}
if let Some(pos) = &conf_display.pos {
overlay.state.spawn_point = Vec3A::from_slice(pos);
}
let display = wayvr.displays.get_mut(&display_handle).unwrap(); // Never fails let display = wayvr.displays.get_mut(&display_handle).unwrap(); // Never fails
display.overlay_id = Some(overlay.state.id); display.overlay_id = Some(overlay.state.id);

View File

@@ -6,6 +6,13 @@
version: 1 version: 1
displays: displays:
Watch:
width: 400
height: 600
scale: 0.4
attach_to: "HandRight" # HandLeft, HandRight
pos: [0.0, 0.0, 0.125]
rotation: {axis: [1.0, 0.0, 0.0], angle: -45.0}
Disp1: Disp1:
width: 640 width: 640
height: 480 height: 480
@@ -24,7 +31,7 @@ catalogs:
env: ["FOO=bar"] env: ["FOO=bar"]
- name: "htop" - name: "htop"
target_display: "Disp1" target_display: "Watch"
exec: "konsole" exec: "konsole"
args: "-e htop" args: "-e htop"