Merge pull request #89 from olekolek1000/wayvr_relativeto
WayVR: `attach_to`, `pos` and `rotation` params
This commit is contained in:
@@ -5,7 +5,38 @@ use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
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)]
|
||||
pub struct WayVRAppEntry {
|
||||
@@ -21,6 +52,9 @@ pub struct WayVRDisplay {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub scale: f32,
|
||||
pub rotation: Option<Rotation>,
|
||||
pub pos: Option<[f32; 3]>,
|
||||
pub attach_to: Option<AttachTo>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use glam::{vec3a, Affine2};
|
||||
use glam::{vec3a, Affine2, Vec3, Vec3A};
|
||||
use serde::Deserialize;
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
use vulkano::image::SubresourceLayout;
|
||||
@@ -314,7 +314,8 @@ where
|
||||
.ok_or(anyhow::anyhow!(
|
||||
"Cannot find display named \"{}\"",
|
||||
app_entry.target_display
|
||||
))?;
|
||||
))?
|
||||
.clone();
|
||||
|
||||
let display_handle = wayvr.create_display(
|
||||
conf_display.width,
|
||||
@@ -322,7 +323,7 @@ where
|
||||
&app_entry.target_display,
|
||||
)?;
|
||||
|
||||
let overlay = create_wayvr_display_overlay::<O>(
|
||||
let mut overlay = create_wayvr_display_overlay::<O>(
|
||||
app,
|
||||
conf_display.width,
|
||||
conf_display.height,
|
||||
@@ -330,6 +331,21 @@ where
|
||||
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
|
||||
display.overlay_id = Some(overlay.state.id);
|
||||
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
version: 1
|
||||
|
||||
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:
|
||||
width: 640
|
||||
height: 480
|
||||
@@ -24,7 +31,7 @@ catalogs:
|
||||
env: ["FOO=bar"]
|
||||
|
||||
- name: "htop"
|
||||
target_display: "Disp1"
|
||||
target_display: "Watch"
|
||||
exec: "konsole"
|
||||
args: "-e htop"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user