Skip to content

Commit

Permalink
Merge pull request #89 from olekolek1000/wayvr_relativeto
Browse files Browse the repository at this point in the history
WayVR: `attach_to`, `pos` and `rotation` params
  • Loading branch information
olekolek1000 authored Oct 24, 2024
2 parents cf03bee + 8d82993 commit 0b1a7e8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
36 changes: 35 additions & 1 deletion src/config_wayvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)]
Expand Down
22 changes: 19 additions & 3 deletions src/overlays/wayvr.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -314,22 +314,38 @@ where
.ok_or(anyhow::anyhow!(
"Cannot find display named \"{}\"",
app_entry.target_display
))?;
))?
.clone();

let display_handle = wayvr.create_display(
conf_display.width,
conf_display.height,
&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,
display_handle,
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);

Expand Down
9 changes: 8 additions & 1 deletion src/res/wayvr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +31,7 @@ catalogs:
env: ["FOO=bar"]

- name: "htop"
target_display: "Disp1"
target_display: "Watch"
exec: "konsole"
args: "-e htop"

Expand Down

0 comments on commit 0b1a7e8

Please sign in to comment.