mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(vr): add vehicle profiles in VR menu and Head/World/Smooth OpenXR anchoring
This commit is contained in:
1 parent
226daf6498
commit
4715505800
12 files changed
+681
-112
No files matched your search
+64
-8
@@ -84,28 +84,28 @@ pub struct AppConfig {
|
||||
#[arg(long, default_value_t = 100)]
|
||||
pub controller_vibration: u8,
|
||||
|
||||
/// Seuil CRSF de démarrage des gaz en marche avant (1ère, 2ème, 3ème)
|
||||
#[arg(long, default_value_t = 1065)]
|
||||
/// Seuil CRSF de démarrage des gaz en marche avant (1ère, 2ème, 3ème) — WLToys 144010
|
||||
#[arg(long, default_value_t = 1105)]
|
||||
pub gaz_avant_min: u16,
|
||||
|
||||
/// Plafond CRSF de la 1ère vitesse (Manœuvre)
|
||||
#[arg(long, default_value_t = 1100)]
|
||||
#[arg(long, default_value_t = 1160)]
|
||||
pub gear_1_max: u16,
|
||||
|
||||
/// Plafond CRSF de la 2ème vitesse (Normale)
|
||||
#[arg(long, default_value_t = 1150)]
|
||||
#[arg(long, default_value_t = 1250)]
|
||||
pub gear_2_max: u16,
|
||||
|
||||
/// Plafond CRSF de la 3ème vitesse (Rapide)
|
||||
#[arg(long, default_value_t = 1220)]
|
||||
#[arg(long, default_value_t = 1400)]
|
||||
pub gear_3_max: u16,
|
||||
|
||||
/// Seuil CRSF de démarrage des gaz en marche arrière (R)
|
||||
#[arg(long, default_value_t = 905)]
|
||||
#[arg(long, default_value_t = 875)]
|
||||
pub gaz_arriere_min: u16,
|
||||
|
||||
/// Plafond CRSF de la marche arrière (R)
|
||||
#[arg(long, default_value_t = 800)]
|
||||
#[arg(long, default_value_t = 750)]
|
||||
pub gear_reverse_max: u16,
|
||||
|
||||
/// Codec vidéo reçu depuis le VRX OpenIPC / Ruby ("h264" ou "h265")
|
||||
@@ -120,6 +120,14 @@ pub struct AppConfig {
|
||||
#[arg(long, default_value = "dome")]
|
||||
pub projection_mode: String,
|
||||
|
||||
/// Mode d'ancrage spatial VR : "head" (VIEW), "world" (LOCAL ancré Yaw), ou "smooth" (suivi amorti SLERP)
|
||||
#[arg(long, default_value = "head")]
|
||||
pub vr_lock_mode: String,
|
||||
|
||||
/// Facteur d'amortissement du suivi en mode "smooth" (0.0 = quasi instantané, 1.0 = très amorti)
|
||||
#[arg(long, default_value_t = 0.35)]
|
||||
pub vr_hud_smoothing: f32,
|
||||
|
||||
/// Champ de vision horizontal (FOV en degrés) de la caméra Eachine Sphere Link
|
||||
#[arg(long, default_value_t = 140.0)]
|
||||
pub camera_fov_deg: f32,
|
||||
@@ -276,6 +284,7 @@ pub struct VehicleProfile {
|
||||
pub gaz_arriere_min: u16,
|
||||
pub gear_reverse_max: u16,
|
||||
pub projection_mode: String,
|
||||
pub vr_lock_mode: String,
|
||||
pub camera_fov_deg: f32,
|
||||
pub lens_k1: f32,
|
||||
pub screen_distance_m: f32,
|
||||
@@ -285,6 +294,25 @@ pub struct VehicleProfile {
|
||||
impl VehicleProfile {
|
||||
pub fn builtin_presets() -> Vec<Self> {
|
||||
vec![
|
||||
Self {
|
||||
name: "WLToys 144010 2S".to_string(),
|
||||
control_source: "g29".to_string(),
|
||||
controller_expo: 0.25,
|
||||
controller_deadzone: 0.08,
|
||||
controller_invert_steering: false,
|
||||
gaz_avant_min: 1105,
|
||||
gear_1_max: 1160,
|
||||
gear_2_max: 1250,
|
||||
gear_3_max: 1400,
|
||||
gaz_arriere_min: 875,
|
||||
gear_reverse_max: 750,
|
||||
projection_mode: "dome".to_string(),
|
||||
vr_lock_mode: "head".to_string(),
|
||||
camera_fov_deg: 140.0,
|
||||
lens_k1: -0.14,
|
||||
screen_distance_m: 1.6,
|
||||
battery_cells: 2,
|
||||
},
|
||||
Self {
|
||||
name: "Crawler 3S".to_string(),
|
||||
control_source: "g29".to_string(),
|
||||
@@ -298,6 +326,7 @@ impl VehicleProfile {
|
||||
gaz_arriere_min: 915,
|
||||
gear_reverse_max: 840,
|
||||
projection_mode: "dome".to_string(),
|
||||
vr_lock_mode: "head".to_string(),
|
||||
camera_fov_deg: 140.0,
|
||||
lens_k1: -0.14,
|
||||
screen_distance_m: 1.6,
|
||||
@@ -316,6 +345,7 @@ impl VehicleProfile {
|
||||
gaz_arriere_min: 905,
|
||||
gear_reverse_max: 780,
|
||||
projection_mode: "dome".to_string(),
|
||||
vr_lock_mode: "head".to_string(),
|
||||
camera_fov_deg: 140.0,
|
||||
lens_k1: -0.14,
|
||||
screen_distance_m: 1.6,
|
||||
@@ -334,6 +364,7 @@ impl VehicleProfile {
|
||||
gaz_arriere_min: 905,
|
||||
gear_reverse_max: 800,
|
||||
projection_mode: "cylinder".to_string(),
|
||||
vr_lock_mode: "head".to_string(),
|
||||
camera_fov_deg: 150.0,
|
||||
lens_k1: -0.10,
|
||||
screen_distance_m: 1.8,
|
||||
@@ -356,6 +387,7 @@ impl VehicleProfile {
|
||||
gaz_arriere_min: cfg.gaz_arriere_min,
|
||||
gear_reverse_max: cfg.gear_reverse_max,
|
||||
projection_mode: cfg.projection_mode.clone(),
|
||||
vr_lock_mode: cfg.vr_lock_mode.clone(),
|
||||
camera_fov_deg: cfg.camera_fov_deg,
|
||||
lens_k1: cfg.lens_k1,
|
||||
screen_distance_m: cfg.screen_distance_m,
|
||||
@@ -376,6 +408,7 @@ impl VehicleProfile {
|
||||
cfg.gaz_arriere_min = self.gaz_arriere_min;
|
||||
cfg.gear_reverse_max = self.gear_reverse_max;
|
||||
cfg.projection_mode = self.projection_mode.clone();
|
||||
cfg.vr_lock_mode = self.vr_lock_mode.clone();
|
||||
cfg.camera_fov_deg = self.camera_fov_deg;
|
||||
cfg.lens_k1 = self.lens_k1;
|
||||
cfg.screen_distance_m = self.screen_distance_m;
|
||||
@@ -420,6 +453,7 @@ impl VehicleProfile {
|
||||
gaz_arriere_min = {}\n\
|
||||
gear_reverse_max = {}\n\
|
||||
projection_mode = \"{}\"\n\
|
||||
vr_lock_mode = \"{}\"\n\
|
||||
camera_fov_deg = {:.2}\n\
|
||||
lens_k1 = {:.4}\n\
|
||||
screen_distance_m = {:.3}\n\
|
||||
@@ -436,6 +470,7 @@ impl VehicleProfile {
|
||||
self.gaz_arriere_min,
|
||||
self.gear_reverse_max,
|
||||
self.projection_mode,
|
||||
self.vr_lock_mode,
|
||||
self.camera_fov_deg,
|
||||
self.lens_k1,
|
||||
self.screen_distance_m,
|
||||
@@ -459,6 +494,7 @@ impl VehicleProfile {
|
||||
if let Some(v) = map.get("gaz_arriere_min").and_then(|s| s.parse().ok()) { base.gaz_arriere_min = v; }
|
||||
if let Some(v) = map.get("gear_reverse_max").and_then(|s| s.parse().ok()) { base.gear_reverse_max = v; }
|
||||
if let Some(v) = map.get("projection_mode") { base.projection_mode = v.clone(); }
|
||||
if let Some(v) = map.get("vr_lock_mode") { base.vr_lock_mode = v.clone(); }
|
||||
if let Some(v) = map.get("camera_fov_deg").and_then(|s| s.parse().ok()) { base.camera_fov_deg = v; }
|
||||
if let Some(v) = map.get("lens_k1").and_then(|s| s.parse().ok()) { base.lens_k1 = v; }
|
||||
if let Some(v) = map.get("screen_distance_m").and_then(|s| s.parse().ok()) { base.screen_distance_m = v; }
|
||||
@@ -577,6 +613,8 @@ impl AppConfig {
|
||||
video_width = {}\n\
|
||||
video_height = {}\n\n\
|
||||
projection_mode = \"{}\"\n\
|
||||
vr_lock_mode = \"{}\"\n\
|
||||
vr_hud_smoothing = {:.3}\n\
|
||||
camera_fov_deg = {:.2}\n\
|
||||
lens_k1 = {:.4}\n\
|
||||
lens_k2 = {:.4}\n\
|
||||
@@ -635,6 +673,8 @@ impl AppConfig {
|
||||
self.video_width,
|
||||
self.video_height,
|
||||
esc(&self.projection_mode),
|
||||
esc(&self.vr_lock_mode),
|
||||
self.vr_hud_smoothing,
|
||||
self.camera_fov_deg,
|
||||
self.lens_k1,
|
||||
self.lens_k2,
|
||||
@@ -778,6 +818,8 @@ impl AppConfig {
|
||||
load_parse!(video_height);
|
||||
|
||||
load_str!(projection_mode);
|
||||
load_str!(vr_lock_mode);
|
||||
load_parse!(vr_hud_smoothing);
|
||||
load_parse!(camera_fov_deg);
|
||||
load_parse!(lens_k1);
|
||||
load_parse!(lens_k2);
|
||||
@@ -835,6 +877,7 @@ impl AppConfig {
|
||||
self.camera_fov_deg = self.camera_fov_deg.clamp(60.0, 180.0);
|
||||
self.lens_k1 = self.lens_k1.clamp(-0.50, 0.25);
|
||||
self.screen_distance_m = self.screen_distance_m.clamp(0.5, 5.0);
|
||||
self.vr_hud_smoothing = self.vr_hud_smoothing.clamp(0.0, 1.0);
|
||||
self.controller_vibration = self.controller_vibration.min(100);
|
||||
self.controller_throttle_expo = self.controller_throttle_expo.clamp(0.0, 0.8);
|
||||
self.battery_cells = self.battery_cells.min(6);
|
||||
@@ -855,6 +898,8 @@ mod tests {
|
||||
fn test_config_toml_roundtrip_and_cli_override() {
|
||||
let mut cfg = AppConfig::parse_from(["steamframe-fpv"]);
|
||||
cfg.projection_mode = "cylinder".to_string();
|
||||
cfg.vr_lock_mode = "smooth".to_string();
|
||||
cfg.vr_hud_smoothing = 0.55;
|
||||
cfg.screen_distance_m = 2.2;
|
||||
cfg.lens_k1 = -0.22;
|
||||
cfg.camera_fov_deg = 120.0;
|
||||
@@ -871,6 +916,8 @@ mod tests {
|
||||
loaded.apply_saved_map(&map, |id| id == "wifi_channel");
|
||||
|
||||
assert_eq!(loaded.projection_mode, "cylinder");
|
||||
assert_eq!(loaded.vr_lock_mode, "smooth");
|
||||
assert!((loaded.vr_hud_smoothing - 0.55).abs() < 0.01);
|
||||
assert!((loaded.screen_distance_m - 2.2).abs() < 0.01);
|
||||
assert!((loaded.lens_k1 - (-0.22)).abs() < 0.001);
|
||||
assert!((loaded.camera_fov_deg - 120.0).abs() < 0.01);
|
||||
@@ -885,7 +932,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vehicle_profile_presets_and_apply_roundtrip() {
|
||||
let presets = VehicleProfile::builtin_presets();
|
||||
assert_eq!(presets.len(), 3);
|
||||
assert_eq!(presets.len(), 4);
|
||||
assert!(presets.iter().any(|p| p.name.contains("WLToys 144010")));
|
||||
let buggy = presets
|
||||
.iter()
|
||||
.find(|p| p.name.contains("Buggy"))
|
||||
@@ -906,5 +954,13 @@ mod tests {
|
||||
assert_eq!(parsed.battery_cells, 4);
|
||||
assert_eq!(parsed.gear_3_max, buggy.gear_3_max);
|
||||
assert!((parsed.camera_fov_deg - buggy.camera_fov_deg).abs() < 0.01);
|
||||
assert_eq!(parsed.vr_lock_mode, "head");
|
||||
|
||||
// Rétro-compatibilité : un ancien fichier profil sans vr_lock_mode reste valide
|
||||
let legacy_toml = "name = \"Legacy Crawler\"\ncontrol_source = \"g29\"\nbattery_cells = 3\n";
|
||||
let legacy = VehicleProfile::parse_toml(legacy_toml).expect("TOML legacy valide");
|
||||
assert_eq!(legacy.name, "Legacy Crawler");
|
||||
assert_eq!(legacy.vr_lock_mode, "head");
|
||||
assert_eq!(legacy.battery_cells, 3);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,50 @@ impl ProjectionMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Mode d'ancrage spatial des couches VR (Vidéo + OSD / Menu VR).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum VrLockMode {
|
||||
/// Verrouillé sur la tête (`VIEW`) — suit instantanément les mouvements.
|
||||
#[default]
|
||||
Head,
|
||||
/// Ancré dans l'espace (`LOCAL`) — orientation Yaw uniquement, horizon droit, recentré sur Tare HT.
|
||||
World,
|
||||
/// Suivi amorti (`LOCAL` + SLERP) — réduit les micro-vibrations et la cinétose.
|
||||
Smooth,
|
||||
}
|
||||
|
||||
impl VrLockMode {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
match s.trim().to_ascii_lowercase().as_str() {
|
||||
"world" | "local" => Self::World,
|
||||
"smooth" | "slerp" => Self::Smooth,
|
||||
_ => Self::Head,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_config_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Head => "head",
|
||||
Self::World => "world",
|
||||
Self::Smooth => "smooth",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Head => "HEAD",
|
||||
Self::World => "WORLD",
|
||||
Self::Smooth => "SMOOTH",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cycle(self, step: i32) -> Self {
|
||||
const MODES: [VrLockMode; 3] = [VrLockMode::Head, VrLockMode::World, VrLockMode::Smooth];
|
||||
let idx = MODES.iter().position(|&m| m == self).unwrap_or(0) as isize;
|
||||
MODES[(idx + step as isize).rem_euclid(MODES.len() as isize) as usize]
|
||||
}
|
||||
}
|
||||
|
||||
/// Table de correspondance (LUT) précalculée pour corriger la distorsion en barillet
|
||||
/// de la lentille M12 140° de l'Eachine Sphere Link et la projeter sur le dôme VR.
|
||||
pub struct DomeWarpLut {
|
||||
|
||||
+103
-18
@@ -2,9 +2,9 @@ use super::radxa_ssh::spawn_apply_radxa_channel;
|
||||
use super::types::{DvrConfig, EngineSharedState, LiveOpticalParams};
|
||||
use crate::config::{AppConfig, VehicleProfile};
|
||||
use crate::controller::{ControlSource, GearSpeedLimits};
|
||||
use crate::dome_projection::ProjectionMode;
|
||||
use crate::dome_projection::{ProjectionMode, VrLockMode};
|
||||
use crate::dvr::{DvrContainer, DvrMode};
|
||||
use crate::telemetry_osd::{VrMenuPage, VrMenuRenderData};
|
||||
use crate::telemetry_osd::{StackStr, VrMenuPage, VrMenuRenderData};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::thread::JoinHandle;
|
||||
@@ -60,6 +60,8 @@ impl EngineControlHandle {
|
||||
ProjectionMode::Cylinder140 => "cylinder".to_string(),
|
||||
ProjectionMode::FlatQuad => "flat".to_string(),
|
||||
};
|
||||
cfg.vr_lock_mode = opt.vr_lock_mode.as_config_str().to_string();
|
||||
cfg.vr_hud_smoothing = opt.vr_hud_smoothing.clamp(0.0, 1.0);
|
||||
cfg.camera_fov_deg = opt.camera_fov_deg;
|
||||
cfg.lens_k1 = opt.lens_k1;
|
||||
cfg.lens_k2 = opt.lens_k2;
|
||||
@@ -122,6 +124,7 @@ impl EngineControlHandle {
|
||||
{
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.projection_mode = ProjectionMode::from_str(&profile.projection_mode);
|
||||
opt.vr_lock_mode = VrLockMode::from_str(&profile.vr_lock_mode);
|
||||
opt.camera_fov_deg = profile.camera_fov_deg;
|
||||
opt.lens_k1 = profile.lens_k1;
|
||||
opt.screen_distance_m = profile.screen_distance_m;
|
||||
@@ -444,7 +447,21 @@ impl EngineControlHandle {
|
||||
}
|
||||
|
||||
pub fn toggle_vr_menu(&self) -> bool {
|
||||
let open = self.shared.vr_menu_state.lock().toggle();
|
||||
let active_name = self
|
||||
.shared
|
||||
.persisted_cfg
|
||||
.lock()
|
||||
.as_ref()
|
||||
.map(|c| c.active_profile.clone())
|
||||
.unwrap_or_default();
|
||||
let open = {
|
||||
let mut st = self.shared.vr_menu_state.lock();
|
||||
let is_open = st.toggle();
|
||||
if is_open {
|
||||
st.refresh_profiles(&active_name);
|
||||
}
|
||||
is_open
|
||||
};
|
||||
log::info!(
|
||||
"[Menu VR] {}",
|
||||
if open { "Ouvert dans le casque" } else { "Fermé" }
|
||||
@@ -498,6 +515,44 @@ impl EngineControlHandle {
|
||||
|
||||
match (page, idx) {
|
||||
(VrMenuPage::Main, 0) => {
|
||||
if is_activate {
|
||||
let selected = self
|
||||
.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.selected_profile()
|
||||
.cloned();
|
||||
if let Some(profile) = selected {
|
||||
match self.apply_vehicle_profile(&profile) {
|
||||
Ok(()) => {
|
||||
let toast = format!(
|
||||
"PROFIL : {}",
|
||||
profile
|
||||
.name
|
||||
.chars()
|
||||
.take(24)
|
||||
.map(|c| c.to_ascii_uppercase())
|
||||
.collect::<String>()
|
||||
);
|
||||
self.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback(toast, false);
|
||||
}
|
||||
Err(_) => {
|
||||
self.trigger_controller_rumble_test();
|
||||
self.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback("DESARMER AVANT PROFIL", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.shared.vr_menu_state.lock().cycle_profile(step);
|
||||
}
|
||||
}
|
||||
(VrMenuPage::Main, 1) => {
|
||||
let target = match self.active_control_source() {
|
||||
ControlSource::G29 => ControlSource::SteamController,
|
||||
ControlSource::SteamController => ControlSource::G29,
|
||||
@@ -508,14 +563,16 @@ impl EngineControlHandle {
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback("SOURCE CHANGEE", false),
|
||||
Err(_) => self
|
||||
.shared
|
||||
Err(_) => {
|
||||
self.trigger_controller_rumble_test();
|
||||
self.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback("DESARMER D'ABORD!", true),
|
||||
.set_feedback("DESARMER D'ABORD!", true);
|
||||
}
|
||||
}
|
||||
(VrMenuPage::Main, 1) => {
|
||||
}
|
||||
(VrMenuPage::Main, 2) => {
|
||||
if !is_activate {
|
||||
return;
|
||||
}
|
||||
@@ -525,7 +582,7 @@ impl EngineControlHandle {
|
||||
.lock()
|
||||
.set_feedback("TARE HT OK", false);
|
||||
}
|
||||
(VrMenuPage::Main, 2) => {
|
||||
(VrMenuPage::Main, 3) => {
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.projection_mode = match (opt.projection_mode, step > 0) {
|
||||
(ProjectionMode::Dome140, true) | (ProjectionMode::FlatQuad, false) => {
|
||||
@@ -545,7 +602,7 @@ impl EngineControlHandle {
|
||||
.lock()
|
||||
.set_feedback("PROJECTION MAJ", false);
|
||||
}
|
||||
(VrMenuPage::Main, 3) => {
|
||||
(VrMenuPage::Main, 4) => {
|
||||
{
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.screen_distance_m =
|
||||
@@ -554,14 +611,14 @@ impl EngineControlHandle {
|
||||
}
|
||||
self.persist_live_config();
|
||||
}
|
||||
(VrMenuPage::Main, 4) => {
|
||||
(VrMenuPage::Main, 5) => {
|
||||
let next = self.toggle_telemetry();
|
||||
self.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback(if next { "OSD: ON" } else { "OSD: OFF" }, false);
|
||||
}
|
||||
(VrMenuPage::Main, 5) => {
|
||||
(VrMenuPage::Main, 6) => {
|
||||
if !is_activate {
|
||||
return;
|
||||
}
|
||||
@@ -571,7 +628,7 @@ impl EngineControlHandle {
|
||||
.lock()
|
||||
.set_feedback(if rec { "DVR DEMARRE" } else { "DVR ARRETE" }, false);
|
||||
}
|
||||
(VrMenuPage::Main, 6) => {
|
||||
(VrMenuPage::Main, 7) => {
|
||||
if !is_activate {
|
||||
return;
|
||||
}
|
||||
@@ -614,10 +671,32 @@ impl EngineControlHandle {
|
||||
}
|
||||
let mut st = self.shared.vr_menu_state.lock();
|
||||
st.page = VrMenuPage::Main;
|
||||
st.selected_idx = 6;
|
||||
st.selected_idx = 7;
|
||||
st.feedback = None;
|
||||
}
|
||||
(VrMenuPage::Advanced, 1) => {
|
||||
let next_mode = {
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.vr_lock_mode = opt.vr_lock_mode.cycle(step);
|
||||
opt.vr_lock_mode
|
||||
};
|
||||
log::info!("[Menu VR] Ancrage spatial VR : {}", next_mode.label());
|
||||
self.persist_live_config();
|
||||
self.shared
|
||||
.vr_menu_state
|
||||
.lock()
|
||||
.set_feedback(format!("ANCRAGE : {}", next_mode.label()), false);
|
||||
}
|
||||
(VrMenuPage::Advanced, 2) => {
|
||||
{
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.vr_hud_smoothing =
|
||||
((opt.vr_hud_smoothing + step as f32 * 0.05) * 100.0).round() / 100.0;
|
||||
opt.vr_hud_smoothing = opt.vr_hud_smoothing.clamp(0.0, 1.0);
|
||||
}
|
||||
self.persist_live_config();
|
||||
}
|
||||
(VrMenuPage::Advanced, 3) => {
|
||||
let next = !self.shared.head_tracking_enabled_flag.load(Ordering::Acquire);
|
||||
self.set_head_tracking_enabled(next);
|
||||
self.shared
|
||||
@@ -625,7 +704,7 @@ impl EngineControlHandle {
|
||||
.lock()
|
||||
.set_feedback(if next { "SUIVI HT: ON" } else { "SUIVI HT: OFF" }, false);
|
||||
}
|
||||
(VrMenuPage::Advanced, 2) => {
|
||||
(VrMenuPage::Advanced, 4) => {
|
||||
{
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.lens_k1 = ((opt.lens_k1 + step as f32 * 0.02) * 100.0).round() / 100.0;
|
||||
@@ -633,7 +712,7 @@ impl EngineControlHandle {
|
||||
}
|
||||
self.persist_live_config();
|
||||
}
|
||||
(VrMenuPage::Advanced, 3) => {
|
||||
(VrMenuPage::Advanced, 5) => {
|
||||
{
|
||||
let mut opt = self.shared.optical_params.lock();
|
||||
opt.camera_fov_deg =
|
||||
@@ -641,13 +720,13 @@ impl EngineControlHandle {
|
||||
}
|
||||
self.persist_live_config();
|
||||
}
|
||||
(VrMenuPage::Advanced, 4) => {
|
||||
(VrMenuPage::Advanced, 6) => {
|
||||
let mut limits = *self.shared.gear_speed_limits.lock();
|
||||
limits.forward_max[2] =
|
||||
limits.forward_max[2].saturating_add_signed((step * 10) as i16);
|
||||
self.set_gear_speed_limits(limits);
|
||||
}
|
||||
(VrMenuPage::Advanced, 5) => {
|
||||
(VrMenuPage::Advanced, 7) => {
|
||||
let cur = self.shared.controller_vibration_pct.load(Ordering::Acquire) as i32;
|
||||
let next = (cur + step * 10).clamp(0, 100) as u8;
|
||||
self.set_controller_vibration_pct(next);
|
||||
@@ -680,9 +759,12 @@ impl EngineControlHandle {
|
||||
}
|
||||
let page = st.page;
|
||||
let selected_idx = st.selected_idx % page.item_count();
|
||||
let profile_name = StackStr::<32>::from_truncated(st.selected_profile_name());
|
||||
let wifi_channel = st.wifi_channel;
|
||||
let quit_confirm_pending = st.quit_confirm_pending();
|
||||
let feedback_msg = st.active_feedback();
|
||||
let feedback_msg = st
|
||||
.active_feedback()
|
||||
.map(|(msg, is_err)| (StackStr::<48>::from_truncated(msg), is_err));
|
||||
drop(st);
|
||||
|
||||
let opt = self.shared.optical_params.lock().clone();
|
||||
@@ -690,6 +772,7 @@ impl EngineControlHandle {
|
||||
Some(VrMenuRenderData {
|
||||
page,
|
||||
selected_idx,
|
||||
profile_name,
|
||||
control_source: self.active_control_source(),
|
||||
head_tracking_on: self
|
||||
.shared
|
||||
@@ -697,6 +780,8 @@ impl EngineControlHandle {
|
||||
.load(Ordering::Relaxed),
|
||||
telemetry_osd_on: self.shared.telemetry_enabled_flag.load(Ordering::Relaxed),
|
||||
projection_label: opt.projection_mode.label(),
|
||||
vr_lock_label: opt.vr_lock_mode.label(),
|
||||
vr_hud_smoothing_pct: (opt.vr_hud_smoothing.clamp(0.0, 1.0) * 100.0).round() as u8,
|
||||
screen_distance_m: opt.screen_distance_m,
|
||||
lens_k1: opt.lens_k1,
|
||||
camera_fov_deg: opt.camera_fov_deg,
|
||||
|
||||
+5
-1
@@ -16,7 +16,7 @@ use crate::config::AppConfig;
|
||||
use crate::controller::{
|
||||
ControlSource, GearSpeedLimits, SteamControllerConfig, SteamControllerWorker,
|
||||
};
|
||||
use crate::dome_projection::ProjectionMode;
|
||||
use crate::dome_projection::{ProjectionMode, VrLockMode};
|
||||
use crate::dvr::{DvrContainer, DvrMode, DvrRecorder, ReplayRingBuffer};
|
||||
use crate::g29_bridge::{G29BridgeReceiver, G29State};
|
||||
use crate::nomad_elrs::{HeadPoseSample, NomadHeadTracker, NomadProtocol};
|
||||
@@ -43,6 +43,8 @@ impl FpvEngineController {
|
||||
screen_distance_m: 1.6,
|
||||
screen_width_m: 3.2,
|
||||
projection_mode: ProjectionMode::Dome140,
|
||||
vr_lock_mode: VrLockMode::Head,
|
||||
vr_hud_smoothing: 0.35,
|
||||
brightness: 0.0,
|
||||
contrast: 1.0,
|
||||
gamma: 1.0,
|
||||
@@ -202,6 +204,8 @@ impl FpvEngineController {
|
||||
screen_distance_m: cfg.screen_distance_m,
|
||||
screen_width_m: cfg.screen_width_m,
|
||||
projection_mode: ProjectionMode::from_str(&cfg.projection_mode),
|
||||
vr_lock_mode: VrLockMode::from_str(&cfg.vr_lock_mode),
|
||||
vr_hud_smoothing: cfg.vr_hud_smoothing.clamp(0.0, 1.0),
|
||||
brightness: cfg.video_brightness,
|
||||
contrast: cfg.video_contrast,
|
||||
gamma: cfg.video_gamma,
|
||||
|
||||
+3
-1
@@ -1,7 +1,7 @@
|
||||
use super::vr_menu::VrMenuState;
|
||||
use crate::config::AppConfig;
|
||||
use crate::controller::{ControlSource, GearSpeedLimits, SteamControllerState};
|
||||
use crate::dome_projection::ProjectionMode;
|
||||
use crate::dome_projection::{ProjectionMode, VrLockMode};
|
||||
use crate::dvr::{DvrContainer, DvrMode, ReplayRingBuffer};
|
||||
use crate::g29_bridge::G29State;
|
||||
use crate::nomad_elrs::HeadPoseSample;
|
||||
@@ -30,6 +30,8 @@ pub struct LiveOpticalParams {
|
||||
pub screen_distance_m: f32,
|
||||
pub screen_width_m: f32,
|
||||
pub projection_mode: ProjectionMode,
|
||||
pub vr_lock_mode: VrLockMode,
|
||||
pub vr_hud_smoothing: f32,
|
||||
pub brightness: f32,
|
||||
pub contrast: f32,
|
||||
pub gamma: f32,
|
||||
|
||||
+69
-9
@@ -1,3 +1,4 @@
|
||||
use crate::config::VehicleProfile;
|
||||
use crate::telemetry_osd::VrMenuPage;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -8,10 +9,12 @@ pub struct VrMenuState {
|
||||
pub open: bool,
|
||||
pub page: VrMenuPage,
|
||||
pub selected_idx: usize,
|
||||
pub profiles: Vec<VehicleProfile>,
|
||||
pub profile_idx: usize,
|
||||
pub wifi_channel: u16,
|
||||
pub radxa_vrx_ip: String,
|
||||
pub quit_confirm_until: Option<Instant>,
|
||||
pub feedback: Option<(&'static str, bool, Instant)>,
|
||||
pub feedback: Option<(String, bool, Instant)>,
|
||||
}
|
||||
|
||||
impl Default for VrMenuState {
|
||||
@@ -20,6 +23,8 @@ impl Default for VrMenuState {
|
||||
open: false,
|
||||
page: VrMenuPage::Main,
|
||||
selected_idx: 0,
|
||||
profiles: VehicleProfile::builtin_presets(),
|
||||
profile_idx: 0,
|
||||
wifi_channel: 161,
|
||||
radxa_vrx_ip: "192.168.1.1".to_string(),
|
||||
quit_confirm_until: None,
|
||||
@@ -29,17 +34,56 @@ impl Default for VrMenuState {
|
||||
}
|
||||
|
||||
impl VrMenuState {
|
||||
pub fn set_feedback(&mut self, msg: &'static str, is_err: bool) {
|
||||
self.feedback = Some((msg, is_err, Instant::now() + Duration::from_millis(2000)));
|
||||
pub fn set_feedback(&mut self, msg: impl Into<String>, is_err: bool) {
|
||||
self.feedback = Some((msg.into(), is_err, Instant::now() + Duration::from_millis(2000)));
|
||||
}
|
||||
|
||||
pub fn active_feedback(&self) -> Option<(&'static str, bool)> {
|
||||
match self.feedback {
|
||||
Some((msg, is_err, until)) if Instant::now() < until => Some((msg, is_err)),
|
||||
pub fn active_feedback(&self) -> Option<(&str, bool)> {
|
||||
match &self.feedback {
|
||||
Some((msg, is_err, until)) if Instant::now() < *until => Some((msg.as_str(), *is_err)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn refresh_profiles(&mut self, active_name: &str) {
|
||||
let all = VehicleProfile::list_all();
|
||||
if !all.is_empty() {
|
||||
self.profiles = all;
|
||||
}
|
||||
if !active_name.is_empty() {
|
||||
if let Some(pos) = self
|
||||
.profiles
|
||||
.iter()
|
||||
.position(|p| p.name.eq_ignore_ascii_case(active_name))
|
||||
{
|
||||
self.profile_idx = pos;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if self.profile_idx >= self.profiles.len() {
|
||||
self.profile_idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected_profile(&self) -> Option<&VehicleProfile> {
|
||||
self.profiles.get(self.profile_idx)
|
||||
}
|
||||
|
||||
pub fn selected_profile_name(&self) -> &str {
|
||||
self.selected_profile()
|
||||
.map(|p| p.name.as_str())
|
||||
.unwrap_or("DEFAUT")
|
||||
}
|
||||
|
||||
pub fn cycle_profile(&mut self, step: i32) {
|
||||
if self.profiles.is_empty() {
|
||||
return;
|
||||
}
|
||||
let len = self.profiles.len() as isize;
|
||||
self.profile_idx = (self.profile_idx as isize + step as isize).rem_euclid(len) as usize;
|
||||
self.set_feedback("A/CROIX POUR APPLIQUER", false);
|
||||
}
|
||||
|
||||
pub fn quit_confirm_pending(&self) -> bool {
|
||||
self.quit_confirm_until
|
||||
.map(|u| Instant::now() < u)
|
||||
@@ -65,7 +109,7 @@ impl VrMenuState {
|
||||
self.quit_confirm_until = None;
|
||||
if self.page == VrMenuPage::Advanced {
|
||||
self.page = VrMenuPage::Main;
|
||||
self.selected_idx = 6;
|
||||
self.selected_idx = 7;
|
||||
self.feedback = None;
|
||||
true
|
||||
} else {
|
||||
@@ -112,13 +156,13 @@ mod tests {
|
||||
st.move_selection(1);
|
||||
assert_eq!(st.selected_idx, 0);
|
||||
|
||||
// Sous-menu Avancé -> Retour revient sur Main(6) sans fermer
|
||||
// Sous-menu Avancé -> Retour revient sur Main(7) sans fermer
|
||||
st.page = VrMenuPage::Advanced;
|
||||
st.selected_idx = 2;
|
||||
assert!(st.back());
|
||||
assert!(st.open);
|
||||
assert_eq!(st.page, VrMenuPage::Main);
|
||||
assert_eq!(st.selected_idx, 6);
|
||||
assert_eq!(st.selected_idx, 7);
|
||||
|
||||
// Second back ferme le menu
|
||||
assert!(!st.back());
|
||||
@@ -136,4 +180,20 @@ mod tests {
|
||||
st.cycle_wifi_channel(-1);
|
||||
assert_eq!(st.wifi_channel, 165);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vr_menu_profile_cycle_and_refresh() {
|
||||
let mut st = VrMenuState::default();
|
||||
assert!(!st.profiles.is_empty());
|
||||
let count = st.profiles.len();
|
||||
let first = st.selected_profile_name().to_string();
|
||||
st.cycle_profile(1);
|
||||
assert_eq!(st.profile_idx, 1 % count);
|
||||
assert!(st.active_feedback().is_some());
|
||||
st.cycle_profile(-1);
|
||||
assert_eq!(st.selected_profile_name(), first);
|
||||
|
||||
st.refresh_profiles("Buggy 4S");
|
||||
assert_eq!(st.selected_profile_name(), "Buggy 4S");
|
||||
}
|
||||
}
|
||||
+256
-48
@@ -1,4 +1,4 @@
|
||||
use crate::dome_projection::{DomeWarpLut, ProjectionMode};
|
||||
use crate::dome_projection::{DomeWarpLut, ProjectionMode, VrLockMode};
|
||||
use crate::dvr::DvrMode;
|
||||
use crate::engine::{
|
||||
compose_osd_and_publish, handle_dvr_lifecycle, sync_head_tracker, sync_telemetry_receiver,
|
||||
@@ -10,7 +10,7 @@ use crate::video_usb::{nv12_to_rgba_or_bgra, DmaBufFrame, PixelFormat, UsbVideoR
|
||||
use crate::vulkan_warp::GpuImageEnhanceParams;
|
||||
use crate::vulkan_xr::VulkanXrContext;
|
||||
use anyhow::{Context, Result};
|
||||
use glam::{EulerRot, Quat};
|
||||
use glam::{EulerRot, Quat, Vec3};
|
||||
use openxr as xr;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
@@ -300,6 +300,8 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
let mut fps_timer = Instant::now();
|
||||
let mut last_frame_id: u64 = 0;
|
||||
let mut last_proj_label = initial_proj.label();
|
||||
let mut spatial_anchor = SpatialAnchorState::default();
|
||||
let mut last_spatial_tick: Option<Instant> = None;
|
||||
|
||||
let loop_res: Result<()> = (|| {
|
||||
'xr_loop: while (!ctx.shared.stop_flag.load(Ordering::Relaxed)
|
||||
@@ -493,16 +495,35 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
}
|
||||
};
|
||||
let mut current_pose = HeadPoseSample::default();
|
||||
let now_spatial = Instant::now();
|
||||
let spatial_dt = last_spatial_tick
|
||||
.map(|t| now_spatial.saturating_duration_since(t).as_secs_f32())
|
||||
.unwrap_or(1.0 / 90.0);
|
||||
last_spatial_tick = Some(now_spatial);
|
||||
|
||||
if location
|
||||
let orientation_valid = location
|
||||
.location_flags
|
||||
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
|
||||
{
|
||||
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID);
|
||||
let position_valid = location
|
||||
.location_flags
|
||||
.contains(xr::SpaceLocationFlags::POSITION_VALID);
|
||||
|
||||
let recenter_now = ctx.shared.recenter_flag.swap(false, Ordering::AcqRel);
|
||||
let head_pose_local = if orientation_valid {
|
||||
let q = location.pose.orientation;
|
||||
let quat = Quat::from_xyzw(q.x, q.y, q.z, q.w);
|
||||
let quat = Quat::from_xyzw(q.x, q.y, q.z, q.w).normalize();
|
||||
let pos = if position_valid {
|
||||
Vec3::new(
|
||||
location.pose.position.x,
|
||||
location.pose.position.y,
|
||||
location.pose.position.z,
|
||||
)
|
||||
} else {
|
||||
Vec3::ZERO
|
||||
};
|
||||
|
||||
if let Some(ref mut ht) = ctx.head_tracker_opt.inner {
|
||||
if first_pose || ctx.shared.recenter_flag.swap(false, Ordering::Relaxed) {
|
||||
if first_pose || recenter_now {
|
||||
ht.recenter(quat);
|
||||
first_pose = false;
|
||||
}
|
||||
@@ -517,7 +538,18 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
current_pose = sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some((quat, pos))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let layer_pose = spatial_anchor.update(
|
||||
cur_opt.vr_lock_mode,
|
||||
cur_opt.vr_hud_smoothing,
|
||||
head_pose_local,
|
||||
recenter_now,
|
||||
spatial_dt,
|
||||
);
|
||||
|
||||
if !xr_frame_state.should_render {
|
||||
frame_stream.end(
|
||||
@@ -843,6 +875,12 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
let max_vert_rad = std::f32::consts::FRAC_PI_2 - 0.01;
|
||||
let half_vert_fov_rad = ((horizontal_fov_rad / aspect) * 0.5).clamp(0.1, max_vert_rad);
|
||||
let screen_height_m = safe_width_m / aspect;
|
||||
let layer_space = if layer_pose.use_local_space {
|
||||
&local_space
|
||||
} else {
|
||||
&view_space
|
||||
};
|
||||
let video_center_pose = layer_pose.center_pose();
|
||||
|
||||
// Préparer l'éventuelle couche 1 OSD/Menu transparente (légèrement devant la vidéo)
|
||||
let osd_quad_opt = if osd_layer_active && vk_xr.has_uploaded_osd {
|
||||
@@ -856,17 +894,10 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
let hud_h = hud_w / aspect;
|
||||
xr::CompositionLayerQuad::new()
|
||||
.layer_flags(xr::CompositionLayerFlags::BLEND_TEXTURE_SOURCE_ALPHA)
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(osd_sub)
|
||||
.pose(xr::Posef {
|
||||
orientation: xr::Quaternionf::IDENTITY,
|
||||
position: xr::Vector3f {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: -hud_dist,
|
||||
},
|
||||
})
|
||||
.pose(layer_pose.quad_pose(hud_dist))
|
||||
.size(xr::Extent2Df {
|
||||
width: hud_w,
|
||||
height: hud_h,
|
||||
@@ -914,19 +945,19 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
match active_proj {
|
||||
ProjectionMode::Dome140 => {
|
||||
let left_layer = xr::CompositionLayerEquirect2KHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::LEFT)
|
||||
.sub_image(sub_left)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_horizontal_angle(horizontal_fov_rad)
|
||||
.upper_vertical_angle(sbs_half_vert)
|
||||
.lower_vertical_angle(-sbs_half_vert);
|
||||
let right_layer = xr::CompositionLayerEquirect2KHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::RIGHT)
|
||||
.sub_image(sub_right)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_horizontal_angle(horizontal_fov_rad)
|
||||
.upper_vertical_angle(sbs_half_vert)
|
||||
@@ -947,18 +978,18 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
}
|
||||
ProjectionMode::Cylinder140 => {
|
||||
let left_layer = xr::CompositionLayerCylinderKHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::LEFT)
|
||||
.sub_image(sub_left)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_angle(horizontal_fov_rad)
|
||||
.aspect_ratio(sbs_aspect);
|
||||
let right_layer = xr::CompositionLayerCylinderKHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::RIGHT)
|
||||
.sub_image(sub_right)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_angle(horizontal_fov_rad)
|
||||
.aspect_ratio(sbs_aspect);
|
||||
@@ -977,26 +1008,19 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
}
|
||||
}
|
||||
ProjectionMode::FlatQuad => {
|
||||
let pose = xr::Posef {
|
||||
orientation: xr::Quaternionf::IDENTITY,
|
||||
position: xr::Vector3f {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: -safe_distance_m,
|
||||
},
|
||||
};
|
||||
let pose = layer_pose.quad_pose(safe_distance_m);
|
||||
let sz = xr::Extent2Df {
|
||||
width: safe_width_m,
|
||||
height: sbs_screen_h,
|
||||
};
|
||||
let left_layer = xr::CompositionLayerQuad::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::LEFT)
|
||||
.sub_image(sub_left)
|
||||
.pose(pose)
|
||||
.size(sz);
|
||||
let right_layer = xr::CompositionLayerQuad::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::RIGHT)
|
||||
.sub_image(sub_right)
|
||||
.pose(pose)
|
||||
@@ -1020,10 +1044,10 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
match active_proj {
|
||||
ProjectionMode::Dome140 => {
|
||||
let video_layer = xr::CompositionLayerEquirect2KHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_horizontal_angle(horizontal_fov_rad)
|
||||
.upper_vertical_angle(half_vert_fov_rad)
|
||||
@@ -1044,10 +1068,10 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
}
|
||||
ProjectionMode::Cylinder140 => {
|
||||
let video_layer = xr::CompositionLayerCylinderKHR::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef::IDENTITY)
|
||||
.pose(video_center_pose)
|
||||
.radius(safe_distance_m)
|
||||
.central_angle(horizontal_fov_rad)
|
||||
.aspect_ratio(aspect);
|
||||
@@ -1067,17 +1091,10 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
|
||||
}
|
||||
ProjectionMode::FlatQuad => {
|
||||
let video_layer = xr::CompositionLayerQuad::new()
|
||||
.space(&view_space)
|
||||
.space(layer_space)
|
||||
.eye_visibility(xr::EyeVisibility::BOTH)
|
||||
.sub_image(sub_image)
|
||||
.pose(xr::Posef {
|
||||
orientation: xr::Quaternionf::IDENTITY,
|
||||
position: xr::Vector3f {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: -safe_distance_m,
|
||||
},
|
||||
})
|
||||
.pose(layer_pose.quad_pose(safe_distance_m))
|
||||
.size(xr::Extent2Df {
|
||||
width: safe_width_m,
|
||||
height: screen_height_m,
|
||||
@@ -1137,3 +1154,194 @@ fn resolve_projection(
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn _unused_check(_: OsdExtraOptions) {}
|
||||
|
||||
/// Extrait uniquement la rotation horizontale (Yaw autour de +Y, pitch=0, roll=0)
|
||||
/// pour maintenir l'horizon parfaitement de niveau en mode World-Locked (`LOCAL`).
|
||||
pub(crate) fn yaw_only_quat(q: Quat) -> Quat {
|
||||
let fwd = q * Vec3::NEG_Z;
|
||||
let horiz = Vec3::new(fwd.x, 0.0, fwd.z);
|
||||
if horiz.length_squared() > 1e-6 {
|
||||
let yaw = (-horiz.x).atan2(-horiz.z);
|
||||
Quat::from_rotation_y(yaw)
|
||||
} else {
|
||||
Quat::IDENTITY
|
||||
}
|
||||
}
|
||||
|
||||
/// Pose d'ancrage calculée pour soumettre les couches OpenXR (Vidéo + OSD / Menu VR).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) struct LayerFramePose {
|
||||
pub use_local_space: bool,
|
||||
pub orientation: Quat,
|
||||
pub position: Vec3,
|
||||
}
|
||||
|
||||
impl LayerFramePose {
|
||||
pub const VIEW_IDENTITY: Self = Self {
|
||||
use_local_space: false,
|
||||
orientation: Quat::IDENTITY,
|
||||
position: Vec3::ZERO,
|
||||
};
|
||||
|
||||
/// Pose du centre de la sphère / du cylindre dans l'espace cible.
|
||||
pub fn center_pose(self) -> xr::Posef {
|
||||
xr::Posef {
|
||||
orientation: xr::Quaternionf {
|
||||
x: self.orientation.x,
|
||||
y: self.orientation.y,
|
||||
z: self.orientation.z,
|
||||
w: self.orientation.w,
|
||||
},
|
||||
position: xr::Vector3f {
|
||||
x: self.position.x,
|
||||
y: self.position.y,
|
||||
z: self.position.z,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Pose d'un Quad placé à `distance_m` devant l'origine de ce repère (axe `-Z` local).
|
||||
pub fn quad_pose(self, distance_m: f32) -> xr::Posef {
|
||||
let p = self.position + self.orientation * Vec3::new(0.0, 0.0, -distance_m);
|
||||
xr::Posef {
|
||||
orientation: xr::Quaternionf {
|
||||
x: self.orientation.x,
|
||||
y: self.orientation.y,
|
||||
z: self.orientation.z,
|
||||
w: self.orientation.w,
|
||||
},
|
||||
position: xr::Vector3f {
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
z: p.z,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// État persistant d'ancrage spatial (`Head`, `World` Yaw-only, `Smooth` SLERP).
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub(crate) struct SpatialAnchorState {
|
||||
last_mode: Option<VrLockMode>,
|
||||
world_anchor: Option<(Quat, Vec3)>,
|
||||
smooth_pose: Option<(Quat, Vec3)>,
|
||||
}
|
||||
|
||||
impl SpatialAnchorState {
|
||||
pub fn update(
|
||||
&mut self,
|
||||
mode: VrLockMode,
|
||||
smoothing: f32,
|
||||
head_pose_local: Option<(Quat, Vec3)>,
|
||||
recenter_now: bool,
|
||||
dt_secs: f32,
|
||||
) -> LayerFramePose {
|
||||
let mode_changed = self.last_mode != Some(mode);
|
||||
self.last_mode = Some(mode);
|
||||
|
||||
match mode {
|
||||
VrLockMode::Head => LayerFramePose::VIEW_IDENTITY,
|
||||
VrLockMode::World => {
|
||||
if let Some((head_ori, head_pos)) = head_pose_local {
|
||||
if mode_changed || recenter_now || self.world_anchor.is_none() {
|
||||
self.world_anchor = Some((yaw_only_quat(head_ori), head_pos));
|
||||
}
|
||||
}
|
||||
if let Some((ori, pos)) = self.world_anchor {
|
||||
LayerFramePose {
|
||||
use_local_space: true,
|
||||
orientation: ori,
|
||||
position: pos,
|
||||
}
|
||||
} else {
|
||||
LayerFramePose::VIEW_IDENTITY
|
||||
}
|
||||
}
|
||||
VrLockMode::Smooth => {
|
||||
if let Some((head_ori, head_pos)) = head_pose_local {
|
||||
let s = smoothing.clamp(0.0, 1.0);
|
||||
if mode_changed || recenter_now || self.smooth_pose.is_none() || s <= 0.001 {
|
||||
self.smooth_pose = Some((head_ori, head_pos));
|
||||
} else if let Some((cur_ori, cur_pos)) = self.smooth_pose {
|
||||
let dt = dt_secs.clamp(0.001, 0.1);
|
||||
let tau = 0.02 + s * s * 0.48;
|
||||
let alpha = (1.0 - (-dt / tau).exp()).clamp(0.0, 1.0);
|
||||
let next_ori = cur_ori.slerp(head_ori, alpha).normalize();
|
||||
let next_pos = cur_pos.lerp(head_pos, alpha);
|
||||
self.smooth_pose = Some((next_ori, next_pos));
|
||||
}
|
||||
}
|
||||
if let Some((ori, pos)) = self.smooth_pose {
|
||||
LayerFramePose {
|
||||
use_local_space: true,
|
||||
orientation: ori,
|
||||
position: pos,
|
||||
}
|
||||
} else {
|
||||
LayerFramePose::VIEW_IDENTITY
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::f32::consts::FRAC_PI_2;
|
||||
|
||||
#[test]
|
||||
fn test_yaw_only_quat_keeps_horizon_level() {
|
||||
// Tête tournée à 90° gauche + 25° vers le haut + 15° de roulis
|
||||
let tilted = Quat::from_euler(
|
||||
EulerRot::YXZ,
|
||||
FRAC_PI_2,
|
||||
25.0_f32.to_radians(),
|
||||
15.0_f32.to_radians(),
|
||||
);
|
||||
let yq = yaw_only_quat(tilted);
|
||||
let fwd = yq * Vec3::NEG_Z;
|
||||
let up = yq * Vec3::Y;
|
||||
assert!(fwd.y.abs() < 1e-4, "horizon doit rester horizontal: {:?}", fwd);
|
||||
assert!((fwd.x - (-1.0)).abs() < 1e-3, "yaw 90° gauche attendu: {:?}", fwd);
|
||||
assert!((up - Vec3::Y).length() < 1e-4, "vecteur haut inchangé: {:?}", up);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spatial_anchor_world_captures_on_enter_and_recenter() {
|
||||
let mut st = SpatialAnchorState::default();
|
||||
let head1 = (
|
||||
Quat::from_rotation_y(FRAC_PI_2),
|
||||
Vec3::new(0.1, 1.5, -0.2),
|
||||
);
|
||||
let p1 = st.update(VrLockMode::World, 0.35, Some(head1), false, 0.011);
|
||||
assert!(p1.use_local_space);
|
||||
assert!((p1.position - head1.1).length() < 1e-5);
|
||||
|
||||
// Tourner la tête ne doit PAS bouger l'ancre en mode World
|
||||
let head2 = (Quat::IDENTITY, Vec3::new(0.5, 1.6, 0.0));
|
||||
let p2 = st.update(VrLockMode::World, 0.35, Some(head2), false, 0.011);
|
||||
assert!((p2.position - head1.1).length() < 1e-5);
|
||||
assert!((p2.orientation.dot(p1.orientation)).abs() > 0.9999);
|
||||
|
||||
// Tare HT recentre immédiatement sur head2
|
||||
let p3 = st.update(VrLockMode::World, 0.35, Some(head2), true, 0.011);
|
||||
assert!((p3.position - head2.1).length() < 1e-5);
|
||||
assert!((p3.orientation * Vec3::NEG_Z - Vec3::NEG_Z).length() < 1e-4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spatial_anchor_smooth_interpolates_gradually() {
|
||||
let mut st = SpatialAnchorState::default();
|
||||
let start = (Quat::IDENTITY, Vec3::ZERO);
|
||||
let target = (Quat::from_rotation_y(FRAC_PI_2), Vec3::new(1.0, 0.0, 0.0));
|
||||
|
||||
let p0 = st.update(VrLockMode::Smooth, 0.6, Some(start), false, 0.011);
|
||||
assert!(p0.use_local_space);
|
||||
let p1 = st.update(VrLockMode::Smooth, 0.6, Some(target), false, 0.016);
|
||||
// Doit avoir avancé partiellement (ni figé, ni téléporté)
|
||||
assert!(p1.position.x > 0.01 && p1.position.x < 0.95);
|
||||
let fwd1 = p1.orientation * Vec3::NEG_Z;
|
||||
assert!(fwd1.x < -0.01 && fwd1.z < -0.01);
|
||||
}
|
||||
}
|
||||
+12
-5
@@ -52,17 +52,21 @@ mod tests {
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=OPTIONS", &state, Some(&ctrl), None);
|
||||
assert!(ctrl.is_vr_menu_open());
|
||||
|
||||
// Descendre 2 fois (0 -> 2 : PROJECTION VR) puis flèche droite (DOME 140 -> CYL 140)
|
||||
for _ in 0..2 {
|
||||
// Index 0 : PROFIL VEHICULE -> flèche droite parcourt, Cross applique
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_RIGHT", &state, Some(&ctrl), None);
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=CROSS", &state, Some(&ctrl), None);
|
||||
|
||||
// Descendre 3 fois (0 -> 3 : PROJECTION VR) puis flèche droite (DOME 140 -> CYL 140)
|
||||
for _ in 0..3 {
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_DOWN", &state, Some(&ctrl), None);
|
||||
}
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_RIGHT", &state, Some(&ctrl), None);
|
||||
let data = ctrl.vr_menu_render_data().unwrap();
|
||||
assert_eq!(data.page, crate::telemetry_osd::VrMenuPage::Main);
|
||||
assert_eq!(data.selected_idx, 2);
|
||||
assert_eq!(data.selected_idx, 3);
|
||||
assert_eq!(data.projection_label, "CYL 140");
|
||||
|
||||
// Entrer dans le sous-menu Avancé (index 6) puis revenir au menu principal avec Circle
|
||||
// Entrer dans le sous-menu Avancé (index 7), tester Ancrage VR (HEAD -> WORLD), puis revenir au menu principal avec Circle
|
||||
for _ in 0..4 {
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_DOWN", &state, Some(&ctrl), None);
|
||||
}
|
||||
@@ -71,6 +75,9 @@ mod tests {
|
||||
ctrl.vr_menu_render_data().unwrap().page,
|
||||
crate::telemetry_osd::VrMenuPage::Advanced
|
||||
);
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_DOWN", &state, Some(&ctrl), None);
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_RIGHT", &state, Some(&ctrl), None);
|
||||
assert_eq!(ctrl.vr_menu_render_data().unwrap().vr_lock_label, "WORLD");
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=CIRCLE", &state, Some(&ctrl), None);
|
||||
assert!(ctrl.is_vr_menu_open());
|
||||
assert_eq!(
|
||||
@@ -78,7 +85,7 @@ mod tests {
|
||||
crate::telemetry_osd::VrMenuPage::Main
|
||||
);
|
||||
|
||||
// Double confirmation sur Quitter l'App (index 7)
|
||||
// Double confirmation sur Quitter l'App (index 8)
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=DPAD_DOWN", &state, Some(&ctrl), None);
|
||||
G29BridgeReceiver::process_line("$G29_EVT,BTN=CROSS", &state, Some(&ctrl), None);
|
||||
assert!(!ctrl.is_exit_requested());
|
||||
|
||||
@@ -4,23 +4,37 @@ pub use fpv_core::telemetry::{TelemetryReceiver, TelemetryState};
|
||||
pub use osd::{OsdExtraOptions, OsdOverlay, VrMenuPage, VrMenuRenderData};
|
||||
|
||||
/// Tampon de formatage rapide sur la pile pour éliminer toute allocation sur le tas dans l'OSD
|
||||
pub(super) struct StackStr<const N: usize> {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct StackStr<const N: usize> {
|
||||
buf: [u8; N],
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl<const N: usize> StackStr<N> {
|
||||
#[inline]
|
||||
pub(super) fn new() -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self { buf: [0u8; N], len: 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super) fn as_str(&self) -> &str {
|
||||
pub fn from_truncated(s: &str) -> Self {
|
||||
let mut out = Self::new();
|
||||
let _ = std::fmt::Write::write_str(&mut out, s);
|
||||
out
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_str(&self) -> &str {
|
||||
std::str::from_utf8(&self.buf[..self.len]).unwrap_or("")
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> Default for StackStr<N> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> std::fmt::Write for StackStr<N> {
|
||||
#[inline]
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
@@ -61,10 +75,13 @@ mod tests {
|
||||
let mut menu = VrMenuRenderData {
|
||||
page: VrMenuPage::Main,
|
||||
selected_idx: 0,
|
||||
profile_name: StackStr::from_truncated("Buggy 4S"),
|
||||
control_source: ControlSource::SteamController,
|
||||
head_tracking_on: true,
|
||||
telemetry_osd_on: true,
|
||||
projection_label: "DOME 140",
|
||||
vr_lock_label: "WORLD",
|
||||
vr_hud_smoothing_pct: 35,
|
||||
screen_distance_m: 1.6,
|
||||
lens_k1: -0.14,
|
||||
camera_fov_deg: 140.0,
|
||||
@@ -73,7 +90,7 @@ mod tests {
|
||||
vibration_pct: 100,
|
||||
wifi_channel: 161,
|
||||
quit_confirm_pending: false,
|
||||
feedback_msg: Some(("TARE HT OK", false)),
|
||||
feedback_msg: Some((StackStr::from_truncated("TARE HT OK"), false)),
|
||||
};
|
||||
OsdOverlay::render_vr_menu(&mut rgba, 1280, 720, &menu);
|
||||
let center_idx = ((720 / 2) * 1280 + (1280 / 2)) * 4;
|
||||
|
||||
+45
-17
@@ -22,19 +22,22 @@ impl VrMenuPage {
|
||||
}
|
||||
|
||||
/// Nombre d'entrées dans le menu principal minimaliste VR (actions essentielles).
|
||||
pub const VR_MENU_MAIN_COUNT: usize = 8;
|
||||
pub const VR_MENU_MAIN_COUNT: usize = 9;
|
||||
/// Nombre d'entrées dans le sous-menu Avancé VR.
|
||||
pub const VR_MENU_ADV_COUNT: usize = 7;
|
||||
pub const VR_MENU_ADV_COUNT: usize = 9;
|
||||
|
||||
/// Données d'affichage zéro-allocation (`Copy`) pour le Menu Minimaliste VR dans le casque.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct VrMenuRenderData {
|
||||
pub page: VrMenuPage,
|
||||
pub selected_idx: usize,
|
||||
pub profile_name: StackStr<32>,
|
||||
pub control_source: ControlSource,
|
||||
pub head_tracking_on: bool,
|
||||
pub telemetry_osd_on: bool,
|
||||
pub projection_label: &'static str,
|
||||
pub vr_lock_label: &'static str,
|
||||
pub vr_hud_smoothing_pct: u8,
|
||||
pub screen_distance_m: f32,
|
||||
pub lens_k1: f32,
|
||||
pub camera_fov_deg: f32,
|
||||
@@ -43,7 +46,7 @@ pub struct VrMenuRenderData {
|
||||
pub vibration_pct: u8,
|
||||
pub wifi_channel: u16,
|
||||
pub quit_confirm_pending: bool,
|
||||
pub feedback_msg: Option<(&'static str, bool)>,
|
||||
pub feedback_msg: Option<(StackStr<48>, bool)>,
|
||||
}
|
||||
|
||||
/// Options d'affichage avancées pour le moteur OSD (cellules LiPo, stats vidéo, GPS/Mode).
|
||||
@@ -552,7 +555,7 @@ impl OsdOverlay {
|
||||
}
|
||||
let is_sel = idx == selected;
|
||||
if is_sel {
|
||||
let is_quit_row = menu.page == VrMenuPage::Main && idx == 7;
|
||||
let is_quit_row = menu.page == VrMenuPage::Main && idx == VR_MENU_MAIN_COUNT - 1;
|
||||
let row_bg = if is_quit_row && menu.quit_confirm_pending {
|
||||
[120, 24, 24, 255]
|
||||
} else {
|
||||
@@ -575,8 +578,22 @@ impl OsdOverlay {
|
||||
let prefix = if is_sel { "> " } else { " " };
|
||||
|
||||
let val_color = match (menu.page, idx) {
|
||||
// --- PAGE PRINCIPALE MINIMALISTE (8 entrées) ---
|
||||
// --- PAGE PRINCIPALE MINIMALISTE (9 entrées) ---
|
||||
(VrMenuPage::Main, 0) => {
|
||||
let _ = write!(label_buf, "{}PROFIL VEHICULE", prefix);
|
||||
let raw = menu.profile_name.as_str();
|
||||
if raw.is_empty() {
|
||||
let _ = write!(val_buf, "< DEFAUT >");
|
||||
} else {
|
||||
let _ = write!(val_buf, "< ");
|
||||
for c in raw.chars().take(16) {
|
||||
let _ = write!(val_buf, "{}", c.to_ascii_uppercase());
|
||||
}
|
||||
let _ = write!(val_buf, " >");
|
||||
}
|
||||
[110, 255, 175, 255]
|
||||
}
|
||||
(VrMenuPage::Main, 1) => {
|
||||
let _ = write!(label_buf, "{}SOURCE PILOTAGE", prefix);
|
||||
let src_lbl = match menu.control_source {
|
||||
ControlSource::G29 => "< G29 VOLANT >",
|
||||
@@ -585,22 +602,22 @@ impl OsdOverlay {
|
||||
let _ = write!(val_buf, "{}", src_lbl);
|
||||
[255, 190, 60, 255]
|
||||
}
|
||||
(VrMenuPage::Main, 1) => {
|
||||
(VrMenuPage::Main, 2) => {
|
||||
let _ = write!(label_buf, "{}CENTRER VUE HT", prefix);
|
||||
let _ = write!(val_buf, "[ TARE ]");
|
||||
[0, 235, 255, 255]
|
||||
}
|
||||
(VrMenuPage::Main, 2) => {
|
||||
(VrMenuPage::Main, 3) => {
|
||||
let _ = write!(label_buf, "{}PROJECTION VR", prefix);
|
||||
let _ = write!(val_buf, "< {} >", menu.projection_label);
|
||||
[100, 225, 255, 255]
|
||||
}
|
||||
(VrMenuPage::Main, 3) => {
|
||||
(VrMenuPage::Main, 4) => {
|
||||
let _ = write!(label_buf, "{}DISTANCE ECRAN", prefix);
|
||||
let _ = write!(val_buf, "< {:.1} M >", menu.screen_distance_m);
|
||||
[235, 240, 250, 255]
|
||||
}
|
||||
(VrMenuPage::Main, 4) => {
|
||||
(VrMenuPage::Main, 5) => {
|
||||
let _ = write!(label_buf, "{}OSD TELEMETRIE", prefix);
|
||||
let _ = write!(
|
||||
val_buf,
|
||||
@@ -613,7 +630,7 @@ impl OsdOverlay {
|
||||
[160, 175, 195, 255]
|
||||
}
|
||||
}
|
||||
(VrMenuPage::Main, 5) => {
|
||||
(VrMenuPage::Main, 6) => {
|
||||
let _ = write!(label_buf, "{}ENREGISTREUR DVR", prefix);
|
||||
let _ = write!(
|
||||
val_buf,
|
||||
@@ -626,7 +643,7 @@ impl OsdOverlay {
|
||||
[180, 190, 205, 255]
|
||||
}
|
||||
}
|
||||
(VrMenuPage::Main, 6) => {
|
||||
(VrMenuPage::Main, 7) => {
|
||||
let _ = write!(label_buf, "{}REGLAGES AVANCES", prefix);
|
||||
let _ = write!(val_buf, "[ OUVRIR > ]");
|
||||
[160, 215, 255, 255]
|
||||
@@ -641,13 +658,23 @@ impl OsdOverlay {
|
||||
[255, 130, 120, 255]
|
||||
}
|
||||
}
|
||||
// --- SOUS-MENU AVANCÉ (7 entrées) ---
|
||||
// --- SOUS-MENU AVANCÉ (9 entrées) ---
|
||||
(VrMenuPage::Advanced, 0) => {
|
||||
let _ = write!(label_buf, "{}< RETOUR MENU", prefix);
|
||||
let _ = write!(val_buf, "[ B / RETOUR ]");
|
||||
[0, 235, 255, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 1) => {
|
||||
let _ = write!(label_buf, "{}ANCRAGE VR", prefix);
|
||||
let _ = write!(val_buf, "< {} >", menu.vr_lock_label);
|
||||
[100, 225, 255, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 2) => {
|
||||
let _ = write!(label_buf, "{}AMORTI SMOOTH", prefix);
|
||||
let _ = write!(val_buf, "< {}% >", menu.vr_hud_smoothing_pct);
|
||||
[235, 240, 250, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 3) => {
|
||||
let _ = write!(label_buf, "{}SUIVI TETE (HT)", prefix);
|
||||
let _ = write!(
|
||||
val_buf,
|
||||
@@ -660,22 +687,22 @@ impl OsdOverlay {
|
||||
[160, 175, 195, 255]
|
||||
}
|
||||
}
|
||||
(VrMenuPage::Advanced, 2) => {
|
||||
(VrMenuPage::Advanced, 4) => {
|
||||
let _ = write!(label_buf, "{}CORRECTION K1", prefix);
|
||||
let _ = write!(val_buf, "< {:+.2} >", menu.lens_k1);
|
||||
[235, 240, 250, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 3) => {
|
||||
(VrMenuPage::Advanced, 5) => {
|
||||
let _ = write!(label_buf, "{}FOV CAMERA", prefix);
|
||||
let _ = write!(val_buf, "< {:.0}° >", menu.camera_fov_deg);
|
||||
[235, 240, 250, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 4) => {
|
||||
(VrMenuPage::Advanced, 6) => {
|
||||
let _ = write!(label_buf, "{}PLAFOND 3E VIT.", prefix);
|
||||
let _ = write!(val_buf, "< {} >", menu.gear_3_max);
|
||||
[255, 190, 60, 255]
|
||||
}
|
||||
(VrMenuPage::Advanced, 5) => {
|
||||
(VrMenuPage::Advanced, 7) => {
|
||||
let _ = write!(label_buf, "{}VIBRATIONS SC", prefix);
|
||||
let _ = write!(val_buf, "< {}% >", menu.vibration_pct);
|
||||
[100, 225, 255, 255]
|
||||
@@ -719,7 +746,8 @@ impl OsdOverlay {
|
||||
|
||||
// Pied du menu : message de retour (erreur d'armement / confirmation) ou aide touches
|
||||
let footer_y = py0 + panel_h - footer_h + 6 * s;
|
||||
if let Some((msg, is_err)) = menu.feedback_msg {
|
||||
if let Some((msg_buf, is_err)) = menu.feedback_msg {
|
||||
let msg = msg_buf.as_str();
|
||||
let color = if is_err {
|
||||
[255, 75, 75, 255]
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::super::theme::*;
|
||||
use super::super::SteamFrameGpuiApp;
|
||||
use crate::config::AppConfig;
|
||||
use crate::controller::GearSpeedLimits;
|
||||
use crate::dome_projection::ProjectionMode;
|
||||
use crate::dome_projection::{ProjectionMode, VrLockMode};
|
||||
use crate::engine::LiveOpticalParams;
|
||||
use crate::nomad_elrs::NomadHeadTracker;
|
||||
use gpui::{div, prelude::*, px, rgb, App, Context, ElementId, IntoElement, Window};
|
||||
@@ -148,6 +148,8 @@ impl SteamFrameGpuiApp {
|
||||
pub(super) fn sync_optical_params(&self) {
|
||||
self.controls.update_optical_params(LiveOpticalParams {
|
||||
projection_mode: ProjectionMode::from_str(&self.cfg.projection_mode),
|
||||
vr_lock_mode: VrLockMode::from_str(&self.cfg.vr_lock_mode),
|
||||
vr_hud_smoothing: self.cfg.vr_hud_smoothing.clamp(0.0, 1.0),
|
||||
camera_fov_deg: self.cfg.camera_fov_deg,
|
||||
lens_k1: self.cfg.lens_k1,
|
||||
lens_k2: self.cfg.lens_k2,
|
||||
|
||||
@@ -76,6 +76,45 @@ self.render_settings_card(
|
||||
}),
|
||||
)),
|
||||
))
|
||||
// Mode d'ancrage spatial VR (Head / World / Smooth)
|
||||
.child(self.render_setting_row(
|
||||
"Ancrage Spatial VR (Vidéo + OSD)",
|
||||
div()
|
||||
.flex()
|
||||
.flex_wrap()
|
||||
.gap_2()
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_lock_head",
|
||||
"Head (VIEW)",
|
||||
!self.cfg.vr_lock_mode.eq_ignore_ascii_case("world")
|
||||
&& !self.cfg.vr_lock_mode.eq_ignore_ascii_case("smooth"),
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.cfg.vr_lock_mode = "head".into();
|
||||
this.sync_optical_params();
|
||||
cx.notify();
|
||||
}),
|
||||
))
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_lock_world",
|
||||
"World (LOCAL Yaw)",
|
||||
self.cfg.vr_lock_mode.eq_ignore_ascii_case("world"),
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.cfg.vr_lock_mode = "world".into();
|
||||
this.sync_optical_params();
|
||||
cx.notify();
|
||||
}),
|
||||
))
|
||||
.child(self.render_selectable_pill(
|
||||
"pill_lock_smooth",
|
||||
"Smooth (SLERP)",
|
||||
self.cfg.vr_lock_mode.eq_ignore_ascii_case("smooth"),
|
||||
cx.listener(|this, _, _, cx| {
|
||||
this.cfg.vr_lock_mode = "smooth".into();
|
||||
this.sync_optical_params();
|
||||
cx.notify();
|
||||
}),
|
||||
)),
|
||||
))
|
||||
// Champ de vision, Lentille k1/k2 et Distance virtuelle (réglables à chaud en VR)
|
||||
.child(self.render_setting_row(
|
||||
"Optique & Écran VR (Réglage à chaud)",
|
||||
@@ -135,6 +174,23 @@ self.render_settings_card(
|
||||
.clamp(0.8, 4.0);
|
||||
},
|
||||
cx,
|
||||
))
|
||||
.child(self.render_optical_stepper_row(
|
||||
"opt_smooth",
|
||||
"Amorti Smooth",
|
||||
format!(
|
||||
"{:.0}%",
|
||||
self.cfg.vr_hud_smoothing.clamp(0.0, 1.0) * 100.0
|
||||
),
|
||||
|cfg, step| {
|
||||
cfg.vr_hud_smoothing = (((cfg.vr_hud_smoothing
|
||||
+ step * 0.05)
|
||||
* 100.0)
|
||||
.round()
|
||||
/ 100.0)
|
||||
.clamp(0.0, 1.0);
|
||||
},
|
||||
cx,
|
||||
)),
|
||||
)),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user