use std::collections::{BTreeMap, HashMap};
#[derive(Debug, Clone)]
pub struct EyeTrackingConfig {
pub sample_rate: u32,
pub enable_foveated_rendering: bool,
pub calibration_points: u32,
}
impl Default for EyeTrackingConfig {
fn default() -> Self {
Self {
sample_rate: 120,
enable_foveated_rendering: false,
calibration_points: 9,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct GazePoint {
pub x: f32,
pub y: f32,
pub depth: f32,
}
impl Default for GazePoint {
fn default() -> Self {
Self {
x: 0.5,
y: 0.5,
depth: 1.0,
}
}
}
#[derive(Debug, Clone)]
pub struct FoveatedRegion {
pub center_radius: f32,
pub peripheral_radius: f32,
pub center_quality: f32,
pub peripheral_quality: f32,
}
impl Default for FoveatedRegion {
fn default() -> Self {
Self {
center_radius: 0.1,
peripheral_radius: 0.3,
center_quality: 1.0,
peripheral_quality: 0.5,
}
}
}
pub struct EyeTracking {
config: EyeTrackingConfig,
current_gaze: GazePoint,
calibrated: bool,
}
impl EyeTracking {
pub fn new(config: EyeTrackingConfig) -> Result<Self, EyeTrackingError> {
Ok(Self {
config,
current_gaze: GazePoint::default(),
calibrated: false,
})
}
pub fn foveated_rendering_enabled(&self) -> bool {
self.config.enable_foveated_rendering
}
pub fn get_gaze_point(&mut self) -> Result<GazePoint, EyeTrackingError> {
Ok(self.current_gaze)
}
pub fn calculate_foveated_region(&self, gaze: &GazePoint) -> Result<FoveatedRegion, EyeTrackingError> {
Ok(FoveatedRegion {
center_radius: 0.1,
peripheral_radius: 0.3,
center_quality: 1.0,
peripheral_quality: 0.25,
})
}
pub fn start_calibration(&mut self) -> Result<(), EyeTrackingError> {
self.calibrated = false;
Ok(())
}
pub fn complete_calibration(&mut self) -> Result<(), EyeTrackingError> {
self.calibrated = true;
Ok(())
}
pub fn is_calibrated(&self) -> bool {
self.calibrated
}
}
#[derive(Debug, Clone)]
pub enum EyeTrackingError {
InitializationFailed(String),
TrackingFailed(String),
CalibrationFailed(String),
DeviceNotFound,
}
impl std::fmt::Display for EyeTrackingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InitializationFailed(msg) => write!(f, "初始化失败: {}", msg),
Self::TrackingFailed(msg) => write!(f, "追踪失败: {}", msg),
Self::CalibrationFailed(msg) => write!(f, "校准失败: {}", msg),
Self::DeviceNotFound => write!(f, "设备未找到"),
}
}
}
impl std::error::Error for EyeTrackingError {}