From 3552491a9af364b8ec47cbe432a1c29da5f6e949 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 9 Oct 2023 18:29:25 -0700 Subject: [PATCH] calculators --- src/settings.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/settings.rs b/src/settings.rs index dca1763..2e27e87 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -32,6 +32,28 @@ pub struct UserSettings{ fov:Fov, sensitivity:Sensitivity, } +impl UserSettings{ + pub fn calculate_fov(&self,zoom:f64,screen_size:&glam::UVec2)->glam::DVec2{ + zoom*match &self.fov{ + &Fov::Exactly{x,y}=>glam::dvec2(x,y), + Fov::DeriveX{x,y}=>match x{ + DerivedFov::FromScreenAspect=>glam::dvec2(y*(screen_size.x as f64/screen_size.y as f64),*y), + DerivedFov::FromAspect(ratio)=>glam::dvec2(y*ratio.ratio,*y), + }, + Fov::DeriveY{x,y}=>match y{ + DerivedFov::FromScreenAspect=>glam::dvec2(*x,x*(screen_size.y as f64/screen_size.x as f64)), + DerivedFov::FromAspect(ratio)=>glam::dvec2(*x,x*ratio.ratio), + }, + } + } + pub fn calculate_sensitivity(&self)->glam::DVec2{ + match &self.sensitivity{ + &Sensitivity::Exactly{x,y}=>glam::dvec2(x,y), + Sensitivity::DeriveX{x,y}=>glam::dvec2(y*x.ratio,*y), + Sensitivity::DeriveY{x,y}=>glam::dvec2(*x,x*y.ratio), + } + } +} /* //sensitivity is raw input dots (i.e. dpi = dots per inch) to radians conversion factor