voirs-spatial 0.1.0-rc.1

3D spatial audio and HRTF processing for VoiRS
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
//! Head tracking and movement tracking systems

use super::types::{
    Box3D, CalibrationData, ComfortSettings, Listener, MovementConstraints, MovementMetrics,
    NavigationMode, OrientationSnapshot, PlatformData, PlatformType, PositionSnapshot,
};
use crate::types::Position3D;
use std::collections::VecDeque;
use std::time::{Duration, Instant};

/// Advanced head tracking with prediction and smoothing
#[derive(Debug, Clone)]
pub struct HeadTracker {
    /// Position history for prediction
    position_history: VecDeque<PositionSnapshot>,
    /// Orientation history for prediction
    orientation_history: VecDeque<OrientationSnapshot>,
    /// Maximum history size
    max_history_size: usize,
    /// Prediction lookahead time
    prediction_time: Duration,
    /// Velocity smoothing factor (0.0 = no smoothing, 1.0 = maximum smoothing)
    velocity_smoothing: f32,
    /// Orientation smoothing factor
    orientation_smoothing: f32,
    /// Motion prediction enabled
    enable_prediction: bool,
    /// Latency compensation in seconds
    latency_compensation: f32,
}

/// Movement detection and prediction
#[derive(Debug, Clone)]
pub struct MovementTracker {
    /// Position history size
    history_size: usize,
    /// Prediction lookahead time
    prediction_time: Duration,
    /// Velocity smoothing factor
    smoothing_factor: f32,
}

/// Real-time listener movement and navigation system
#[derive(Debug, Clone)]
pub struct ListenerMovementSystem {
    /// Current listener reference
    listener: Listener,
    /// Head tracking system
    head_tracker: HeadTracker,
    /// Movement prediction enabled
    pub enable_movement_prediction: bool,
    /// Navigation mode
    pub navigation_mode: NavigationMode,
    /// Comfort settings for VR
    pub comfort_settings: ComfortSettings,
    /// Movement constraints
    pub movement_constraints: MovementConstraints,
    /// Performance metrics
    movement_metrics: MovementMetrics,
}

/// VR/AR platform integration support
#[derive(Debug, Clone)]
pub struct PlatformIntegration {
    /// Platform type
    platform_type: PlatformType,
    /// Platform-specific tracking data
    platform_data: PlatformData,
    /// Calibration data
    calibration: CalibrationData,
}

impl HeadTracker {
    /// Create new head tracker
    pub fn new() -> Self {
        Self {
            position_history: VecDeque::new(),
            orientation_history: VecDeque::new(),
            max_history_size: 50,
            prediction_time: Duration::from_millis(20),
            velocity_smoothing: 0.3,
            orientation_smoothing: 0.4,
            enable_prediction: true,
            latency_compensation: 0.015, // 15ms typical VR latency
        }
    }

    /// Update head position with smoothing and prediction
    pub fn update_position(&mut self, position: Position3D, timestamp: Instant) {
        let timestamp_f64 = timestamp.elapsed().as_secs_f64();

        // Add to history
        self.position_history.push_back(PositionSnapshot {
            position,
            timestamp: timestamp_f64,
            velocity: self.calculate_velocity(&position, timestamp_f64),
        });

        // Limit history size
        while self.position_history.len() > self.max_history_size {
            self.position_history.pop_front();
        }
    }

    /// Update head position with explicit timestamp (for testing)
    pub fn update_position_with_time(&mut self, position: Position3D, timestamp_secs: f64) {
        // Add to history
        self.position_history.push_back(PositionSnapshot {
            position,
            timestamp: timestamp_secs,
            velocity: self.calculate_velocity_for_time(&position, timestamp_secs),
        });

        // Limit history size
        while self.position_history.len() > self.max_history_size {
            self.position_history.pop_front();
        }
    }

    /// Update head orientation with smoothing
    pub fn update_orientation(&mut self, orientation: (f32, f32, f32), timestamp: Instant) {
        let timestamp_f64 = timestamp.elapsed().as_secs_f64();

        // Calculate angular velocity
        let angular_velocity = self.calculate_angular_velocity(&orientation, timestamp_f64);

        self.orientation_history.push_back(OrientationSnapshot {
            orientation,
            timestamp: timestamp_f64,
            angular_velocity,
        });

        // Limit history size
        while self.orientation_history.len() > self.max_history_size {
            self.orientation_history.pop_front();
        }
    }

    /// Update head orientation with explicit timestamp (for testing)
    pub fn update_orientation_with_time(
        &mut self,
        orientation: (f32, f32, f32),
        timestamp_secs: f64,
    ) {
        // Calculate angular velocity
        let angular_velocity =
            self.calculate_angular_velocity_for_time(&orientation, timestamp_secs);

        self.orientation_history.push_back(OrientationSnapshot {
            orientation,
            timestamp: timestamp_secs,
            angular_velocity,
        });

        // Limit history size
        while self.orientation_history.len() > self.max_history_size {
            self.orientation_history.pop_front();
        }
    }

    /// Predict future head position
    pub fn predict_position(&self, time_ahead: Duration) -> Option<Position3D> {
        if !self.enable_prediction || self.position_history.len() < 2 {
            return self.position_history.back().map(|s| s.position);
        }

        let latest = self.position_history.back()?;
        let prediction_time = time_ahead.as_secs_f32() + self.latency_compensation;

        // Linear prediction with velocity
        Some(Position3D::new(
            latest.position.x + latest.velocity.x * prediction_time,
            latest.position.y + latest.velocity.y * prediction_time,
            latest.position.z + latest.velocity.z * prediction_time,
        ))
    }

    /// Predict future head orientation
    pub fn predict_orientation(&self, time_ahead: Duration) -> Option<(f32, f32, f32)> {
        if !self.enable_prediction || self.orientation_history.len() < 2 {
            return self.orientation_history.back().map(|s| s.orientation);
        }

        let latest = self.orientation_history.back()?;
        let prediction_time = time_ahead.as_secs_f32() + self.latency_compensation;

        // Predict orientation with angular velocity
        let predicted_yaw = latest.orientation.0 + latest.angular_velocity.0 * prediction_time;
        let predicted_pitch = latest.orientation.1 + latest.angular_velocity.1 * prediction_time;
        let predicted_roll = latest.orientation.2 + latest.angular_velocity.2 * prediction_time;

        Some((predicted_yaw, predicted_pitch, predicted_roll))
    }

    /// Calculate smoothed velocity
    fn calculate_velocity(&self, position: &Position3D, timestamp: f64) -> Position3D {
        if self.position_history.len() < 2 {
            return Position3D::default();
        }

        let prev = &self.position_history[self.position_history.len() - 1];
        let dt = timestamp - prev.timestamp;

        if dt <= 0.0 {
            return prev.velocity;
        }

        // Calculate raw velocity
        let raw_velocity = Position3D::new(
            (position.x - prev.position.x) / dt as f32,
            (position.y - prev.position.y) / dt as f32,
            (position.z - prev.position.z) / dt as f32,
        );

        // Apply smoothing
        Position3D::new(
            prev.velocity.x * self.velocity_smoothing
                + raw_velocity.x * (1.0 - self.velocity_smoothing),
            prev.velocity.y * self.velocity_smoothing
                + raw_velocity.y * (1.0 - self.velocity_smoothing),
            prev.velocity.z * self.velocity_smoothing
                + raw_velocity.z * (1.0 - self.velocity_smoothing),
        )
    }

    /// Calculate smoothed velocity with explicit timestamp
    fn calculate_velocity_for_time(&self, position: &Position3D, timestamp: f64) -> Position3D {
        if self.position_history.is_empty() {
            return Position3D::default();
        }

        let prev = &self.position_history[self.position_history.len() - 1];
        let dt = timestamp - prev.timestamp;

        if dt <= 0.0 {
            return prev.velocity;
        }

        // Calculate raw velocity
        let raw_velocity = Position3D::new(
            (position.x - prev.position.x) / dt as f32,
            (position.y - prev.position.y) / dt as f32,
            (position.z - prev.position.z) / dt as f32,
        );

        // Apply smoothing if previous velocity exists
        if self.position_history.len() > 1 {
            Position3D::new(
                prev.velocity.x * self.velocity_smoothing
                    + raw_velocity.x * (1.0 - self.velocity_smoothing),
                prev.velocity.y * self.velocity_smoothing
                    + raw_velocity.y * (1.0 - self.velocity_smoothing),
                prev.velocity.z * self.velocity_smoothing
                    + raw_velocity.z * (1.0 - self.velocity_smoothing),
            )
        } else {
            raw_velocity
        }
    }

    /// Calculate angular velocity
    fn calculate_angular_velocity(
        &self,
        orientation: &(f32, f32, f32),
        timestamp: f64,
    ) -> (f32, f32, f32) {
        if self.orientation_history.len() < 2 {
            return (0.0, 0.0, 0.0);
        }

        let prev = &self.orientation_history[self.orientation_history.len() - 1];
        let dt = timestamp - prev.timestamp;

        if dt <= 0.0 {
            return prev.angular_velocity;
        }

        // Calculate raw angular velocity with wrap-around handling
        let raw_angular_velocity = (
            self.angle_difference(orientation.0, prev.orientation.0) / dt as f32,
            self.angle_difference(orientation.1, prev.orientation.1) / dt as f32,
            self.angle_difference(orientation.2, prev.orientation.2) / dt as f32,
        );

        // Apply smoothing
        (
            prev.angular_velocity.0 * self.orientation_smoothing
                + raw_angular_velocity.0 * (1.0 - self.orientation_smoothing),
            prev.angular_velocity.1 * self.orientation_smoothing
                + raw_angular_velocity.1 * (1.0 - self.orientation_smoothing),
            prev.angular_velocity.2 * self.orientation_smoothing
                + raw_angular_velocity.2 * (1.0 - self.orientation_smoothing),
        )
    }

    /// Calculate angular velocity with explicit timestamp
    fn calculate_angular_velocity_for_time(
        &self,
        orientation: &(f32, f32, f32),
        timestamp: f64,
    ) -> (f32, f32, f32) {
        if self.orientation_history.is_empty() {
            return (0.0, 0.0, 0.0);
        }

        let prev = &self.orientation_history[self.orientation_history.len() - 1];
        let dt = timestamp - prev.timestamp;

        if dt <= 0.0 {
            return prev.angular_velocity;
        }

        // Calculate raw angular velocity with wrap-around handling
        let raw_angular_velocity = (
            self.angle_difference(orientation.0, prev.orientation.0) / dt as f32,
            self.angle_difference(orientation.1, prev.orientation.1) / dt as f32,
            self.angle_difference(orientation.2, prev.orientation.2) / dt as f32,
        );

        // Apply smoothing if previous velocity exists
        if self.orientation_history.len() > 1 {
            (
                prev.angular_velocity.0 * self.orientation_smoothing
                    + raw_angular_velocity.0 * (1.0 - self.orientation_smoothing),
                prev.angular_velocity.1 * self.orientation_smoothing
                    + raw_angular_velocity.1 * (1.0 - self.orientation_smoothing),
                prev.angular_velocity.2 * self.orientation_smoothing
                    + raw_angular_velocity.2 * (1.0 - self.orientation_smoothing),
            )
        } else {
            raw_angular_velocity
        }
    }

    /// Calculate angle difference with wrap-around
    pub fn angle_difference(&self, angle1: f32, angle2: f32) -> f32 {
        let diff = angle1 - angle2;
        if diff > std::f32::consts::PI {
            diff - 2.0 * std::f32::consts::PI
        } else if diff < -std::f32::consts::PI {
            diff + 2.0 * std::f32::consts::PI
        } else {
            diff
        }
    }

    /// Configure tracking parameters
    pub fn configure(
        &mut self,
        max_history: usize,
        prediction_ms: u64,
        velocity_smoothing: f32,
        orientation_smoothing: f32,
    ) {
        self.max_history_size = max_history;
        self.prediction_time = Duration::from_millis(prediction_ms);
        self.velocity_smoothing = velocity_smoothing.clamp(0.0, 1.0);
        self.orientation_smoothing = orientation_smoothing.clamp(0.0, 1.0);
    }

    /// Enable/disable prediction
    pub fn set_prediction_enabled(&mut self, enabled: bool) {
        self.enable_prediction = enabled;
    }

    /// Set latency compensation
    pub fn set_latency_compensation(&mut self, latency_ms: f32) {
        self.latency_compensation = latency_ms / 1000.0;
    }

    /// Get current position (latest)
    pub fn current_position(&self) -> Option<Position3D> {
        self.position_history.back().map(|s| s.position)
    }

    /// Get current orientation (latest)
    pub fn current_orientation(&self) -> Option<(f32, f32, f32)> {
        self.orientation_history.back().map(|s| s.orientation)
    }

    /// Get smoothed velocity
    pub fn current_velocity(&self) -> Option<Position3D> {
        self.position_history.back().map(|s| s.velocity)
    }

    /// Get angular velocity
    pub fn current_angular_velocity(&self) -> Option<(f32, f32, f32)> {
        self.orientation_history.back().map(|s| s.angular_velocity)
    }

    /// Clear history
    pub fn reset(&mut self) {
        self.position_history.clear();
        self.orientation_history.clear();
    }

    /// Get prediction quality score (0.0 = poor, 1.0 = excellent)
    pub fn prediction_quality(&self) -> f32 {
        if self.position_history.len() < 3 {
            return 0.0;
        }

        // Calculate velocity consistency
        let mut velocity_consistency = 0.0;
        let mut count = 0;

        for i in 0..self.position_history.len().saturating_sub(1) {
            let v1 = self.position_history[i].velocity;
            let v2 = self.position_history[i + 1].velocity;

            let vel_diff =
                ((v1.x - v2.x).powi(2) + (v1.y - v2.y).powi(2) + (v1.z - v2.z).powi(2)).sqrt();
            velocity_consistency += (-vel_diff * 0.1).exp();
            count += 1;
        }

        if count > 0 {
            velocity_consistency / count as f32
        } else {
            0.0
        }
    }

    /// Get position history for advanced prediction
    pub fn position_history(&self) -> &[PositionSnapshot] {
        // Convert VecDeque to slice using make_contiguous
        let (first, _) = self.position_history.as_slices();
        first
    }
}

impl Default for HeadTracker {
    fn default() -> Self {
        Self::new()
    }
}

impl MovementTracker {
    /// Create new movement tracker
    pub fn new() -> Self {
        Self {
            history_size: 10,
            prediction_time: Duration::from_millis(50),
            smoothing_factor: 0.1,
        }
    }

    /// Track movement for a listener
    pub fn track_listener(&self, _listener: &mut Listener) {
        // Movement tracking is handled in set_position
        // This method could be used for additional processing
    }

    /// Track movement for a sound source
    pub fn track_source(&self, _source: &mut super::types::SoundSource) {
        // Movement tracking is handled in set_position
        // This method could be used for additional processing
    }

    /// Predict collision or intersection
    pub fn predict_intersection(
        &self,
        source: &super::types::SoundSource,
        listener: &Listener,
        time_ahead: Duration,
    ) -> Option<Position3D> {
        let source_future = source.predict_position(time_ahead);
        let listener_future = listener.predict_position(time_ahead);

        let distance = source_future.distance_to(&listener_future);

        // If they'll be close, return the midpoint
        if distance < 2.0 {
            Some(Position3D::new(
                (source_future.x + listener_future.x) / 2.0,
                (source_future.y + listener_future.y) / 2.0,
                (source_future.z + listener_future.z) / 2.0,
            ))
        } else {
            None
        }
    }
}

impl Default for MovementTracker {
    fn default() -> Self {
        Self::new()
    }
}

impl ListenerMovementSystem {
    /// Create new listener movement system
    pub fn new() -> Self {
        Self {
            listener: Listener::new(),
            head_tracker: HeadTracker::new(),
            enable_movement_prediction: true,
            navigation_mode: NavigationMode::FreeFlight,
            comfort_settings: ComfortSettings::default(),
            movement_constraints: MovementConstraints::default(),
            movement_metrics: MovementMetrics::default(),
        }
    }

    /// Create system with specific navigation mode
    pub fn with_navigation_mode(mode: NavigationMode) -> Self {
        let mut system = Self::new();
        system.navigation_mode = mode;

        // Adjust defaults based on mode
        match mode {
            NavigationMode::Seated => {
                system.movement_constraints.max_speed = 0.0;
                system.enable_movement_prediction = false;
            }
            NavigationMode::Walking => {
                system.movement_constraints.max_speed = 5.0; // Walking speed
                system.comfort_settings.ground_reference = true;
            }
            NavigationMode::Vehicle => {
                system.movement_constraints.max_speed = 50.0; // Vehicle speed
                system.comfort_settings.motion_sickness_reduction = 0.7;
            }
            _ => {}
        }

        system
    }

    /// Update listener position with platform data
    pub fn update_position_from_platform(
        &mut self,
        position: Position3D,
        platform_data: Option<PlatformData>,
    ) -> crate::Result<()> {
        let now = Instant::now();

        // Apply movement constraints
        let constrained_position = self.apply_movement_constraints(position)?;

        // Calculate distance before updating position
        let current_pos = self.listener.position();
        let distance = ((constrained_position.x - current_pos.x).powi(2)
            + (constrained_position.y - current_pos.y).powi(2)
            + (constrained_position.z - current_pos.z).powi(2))
        .sqrt();

        // Update head tracker
        self.head_tracker.update_position(constrained_position, now);

        // Update listener
        self.listener.set_position(constrained_position);

        // Update metrics with calculated distance
        self.movement_metrics.total_distance += distance;
        self.movement_metrics.update_count += 1;

        // Process platform-specific data
        if let Some(data) = platform_data {
            self.process_platform_data(data)?;
        }

        Ok(())
    }

    /// Update orientation with platform data
    pub fn update_orientation_from_platform(
        &mut self,
        orientation: (f32, f32, f32),
        platform_data: Option<PlatformData>,
    ) -> crate::Result<()> {
        let now = Instant::now();

        // Apply comfort settings (snap turn, etc.)
        let adjusted_orientation = self.apply_comfort_adjustments(orientation);

        // Update head tracker
        self.head_tracker
            .update_orientation(adjusted_orientation, now);

        // Update listener
        self.listener.set_orientation(adjusted_orientation);

        // Process platform-specific data
        if let Some(data) = platform_data {
            self.process_platform_data(data)?;
        }

        Ok(())
    }

    /// Get predicted listener position for latency compensation
    pub fn predict_position(&self, lookahead: Duration) -> Option<Position3D> {
        if !self.enable_movement_prediction {
            return Some(self.listener.position());
        }

        self.head_tracker.predict_position(lookahead)
    }

    /// Get predicted listener orientation
    pub fn predict_orientation(&self, lookahead: Duration) -> Option<(f32, f32, f32)> {
        if !self.enable_movement_prediction {
            return Some(self.listener.orientation());
        }

        self.head_tracker.predict_orientation(lookahead)
    }

    /// Get listener reference
    pub fn listener(&self) -> &Listener {
        &self.listener
    }

    /// Get mutable listener reference
    pub fn listener_mut(&mut self) -> &mut Listener {
        &mut self.listener
    }

    /// Get head tracker reference
    pub fn head_tracker(&self) -> &HeadTracker {
        &self.head_tracker
    }

    /// Configure comfort settings
    pub fn set_comfort_settings(&mut self, settings: ComfortSettings) {
        self.comfort_settings = settings;
    }

    /// Configure movement constraints
    pub fn set_movement_constraints(&mut self, constraints: MovementConstraints) {
        self.movement_constraints = constraints;
    }

    /// Get movement metrics
    pub fn movement_metrics(&self) -> &MovementMetrics {
        &self.movement_metrics
    }

    /// Reset movement metrics
    pub fn reset_metrics(&mut self) {
        self.movement_metrics = MovementMetrics::default();
    }

    /// Apply movement constraints
    fn apply_movement_constraints(&self, mut position: Position3D) -> crate::Result<Position3D> {
        // Apply boundary constraints
        if let Some(boundary) = &self.movement_constraints.boundary {
            position.x = position.x.clamp(boundary.min.x, boundary.max.x);
            position.y = position.y.clamp(boundary.min.y, boundary.max.y);
            position.z = position.z.clamp(boundary.min.z, boundary.max.z);
        }

        // Apply ground height constraint
        if let Some(ground_height) = self.movement_constraints.ground_height {
            position.y = position.y.max(ground_height);
        }

        // Apply ceiling height constraint
        if let Some(ceiling_height) = self.movement_constraints.ceiling_height {
            position.y = position.y.min(ceiling_height);
        }

        // Check speed constraints (would need velocity calculation)
        // This would be implemented with proper velocity tracking

        Ok(position)
    }

    /// Apply comfort adjustments to orientation
    fn apply_comfort_adjustments(&self, orientation: (f32, f32, f32)) -> (f32, f32, f32) {
        let mut adjusted = orientation;

        // Apply snap turning
        if self.comfort_settings.snap_turn {
            let snap_radians = self.comfort_settings.snap_turn_degrees.to_radians();
            adjusted.0 = (adjusted.0 / snap_radians).round() * snap_radians;
        }

        adjusted
    }

    /// Process platform-specific tracking data
    fn process_platform_data(&mut self, _data: PlatformData) -> crate::Result<()> {
        // This would be implemented for specific platform integrations
        // For now, just validate the data
        Ok(())
    }
}

impl Default for ListenerMovementSystem {
    fn default() -> Self {
        Self::new()
    }
}

impl PlatformIntegration {
    /// Create platform integration for specific platform
    pub fn new(platform: PlatformType) -> Self {
        Self {
            platform_type: platform,
            platform_data: PlatformData {
                device_id: String::new(),
                pose_data: Vec::new(),
                tracking_confidence: 0.0,
                platform_timestamp: 0,
                properties: std::collections::HashMap::new(),
            },
            calibration: CalibrationData {
                head_circumference: None,
                ipd: None,
                height_offset: 0.0,
                forward_offset: 0.0,
                custom_hrtf_profile: None,
            },
        }
    }

    /// Update platform tracking data
    pub fn update_tracking_data(&mut self, data: PlatformData) {
        self.platform_data = data;
    }

    /// Get tracking confidence
    pub fn tracking_confidence(&self) -> f32 {
        self.platform_data.tracking_confidence
    }

    /// Configure calibration
    pub fn set_calibration(&mut self, calibration: CalibrationData) {
        self.calibration = calibration;
    }

    /// Get platform type
    pub fn platform_type(&self) -> PlatformType {
        self.platform_type
    }
}

impl Default for PlatformIntegration {
    fn default() -> Self {
        Self::new(PlatformType::Generic)
    }
}