X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcore%2Fcontroller.rs;h=1eeb13c9ff1e837d24e8db1101419f1ac89a0ba0;hb=3fd8761bc3123ed0de1c5416c7efbbb931257248;hp=832480d6830686956003345f53c0fd0d63f0fa66;hpb=05ba09764d251b4dbf3d6572e1fe54bcbc154dda;p=kaka%2Frust-sdl-test.git diff --git a/src/core/controller.rs b/src/core/controller.rs index 832480d..1eeb13c 100644 --- a/src/core/controller.rs +++ b/src/core/controller.rs @@ -1,5 +1,5 @@ use common::Point2D; -use hashmap; +use {hashmap, point}; use common::Radians; use sdl2::HapticSubsystem; use sdl2::JoystickSubsystem; @@ -68,7 +68,6 @@ pub struct Stick { pub x: f32, pub y: f32, pub a: Radians, - pub len: f32, } impl Stick { @@ -82,27 +81,24 @@ impl Stick { Err(_) => panic!("invalid y axis {}", self.idy), }; self.a = Radians(self.y.atan2(self.x) as f64); - self.len = { - let x = (self.x / self.y).abs().min(1.0); - let y = (self.y / self.x).abs().min(1.0); - (self.x.powi(2) + self.y.powi(2)).sqrt() / (x.powi(2) + y.powi(2)).sqrt() - } } - #[inline(always)] #[allow(dead_code)] fn up(&self) -> bool { self.y > 0.99 } - #[inline(always)] #[allow(dead_code)] fn down(&self) -> bool { self.y < -0.99 } - #[inline(always)] #[allow(dead_code)] fn left(&self) -> bool { self.x < -0.99 } - #[inline(always)] #[allow(dead_code)] fn right(&self) -> bool { self.x > 0.99 } + #[inline(always)] #[allow(dead_code)] pub fn up(&self) -> bool { self.y < -0.99 } + #[inline(always)] #[allow(dead_code)] pub fn down(&self) -> bool { self.y > 0.99 } + #[inline(always)] #[allow(dead_code)] pub fn left(&self) -> bool { self.x < -0.99 } + #[inline(always)] #[allow(dead_code)] pub fn right(&self) -> bool { self.x > 0.99 } - pub fn to_point(&self) -> Point2D { - Point2D { - x: self.x as f64, - y: self.y as f64, - } + pub fn to_axis_point(&self) -> Point2D { + point!(self.x as f64, self.y as f64) } - pub fn to_adjusted_point(&self) -> Point2D { - Point2D::from(self.a) * self.len as f64 + pub fn to_point(&self) -> Point2D { + let p = point!(self.x as f64, self.y as f64); + if p.length() > 1.0 { + p.normalized() + } else { + p + } } } @@ -220,7 +216,7 @@ fn get_action_mapping() -> HashMap { ActionControls::MovementY => DeviceControls::AxisLY, ActionControls::AimX => DeviceControls::AxisRX, ActionControls::AimY => DeviceControls::AxisRY, - ActionControls::Jump => DeviceControls::ButtonL1, + ActionControls::Jump => DeviceControls::ButtonA, ActionControls::Shoot => DeviceControls::ButtonR1, ActionControls::Start => DeviceControls::ButtonStart )