Skip to main content

qualia_core_db/domains/geospatial/
ar_anchor.rs

1/// Physical anchor tying a virtual coordinate to a physical spatial location
2/// Compliant with the Spatial Web Anchoring Spec (UWB/VPS anchoring).
3pub struct PhysicalAnchor {
4    pub virtual_position: (f64, f64, f64), // XYZ in scene coordinates
5    pub physical_id: String,               // UWB beacon ID or VPS feature hash
6    pub confidence: f64,                   // 0.0 to 1.0 confidence in tracking
7    pub is_active: bool,
8}
9
10impl PhysicalAnchor {
11    /// Creates an anchor binding virtual `(vx,vy,vz)` to physical `id`.
12    pub fn new(vx: f64, vy: f64, vz: f64, id: String) -> Self {
13        Self {
14            virtual_position: (vx, vy, vz),
15            physical_id: id,
16            confidence: 1.0,
17            is_active: true,
18        }
19    }
20}
21
22/// Represents the state of the AR device (camera tracking, passthrough mode)
23pub struct ArDeviceState {
24    pub camera_pose: (f64, f64, f64, f64, f64, f64), // (x,y,z, yaw,pitch,roll)
25    pub passthrough_enabled: bool,
26    pub tracking_confidence: f64, // 0.0 = lost, 1.0 = perfect
27    pub anchors: Vec<PhysicalAnchor>,
28}
29
30impl ArDeviceState {
31    /// Creates a device state with no pose/anchors.
32    pub fn new() -> Self {
33        Self {
34            camera_pose: (0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
35            passthrough_enabled: false,
36            tracking_confidence: 0.0,
37            anchors: Vec::new(),
38        }
39    }
40
41    /// Updates the 6-DoF pose with `confidence`.
42    pub fn update_pose(&mut self, pose: (f64, f64, f64, f64, f64, f64), confidence: f64) {
43        self.camera_pose = pose;
44        self.tracking_confidence = confidence;
45    }
46
47    /// Registers a physical anchor.
48    pub fn add_anchor(&mut self, anchor: PhysicalAnchor) {
49        self.anchors.push(anchor);
50    }
51}