From 33b8922aa435aa20d228a986af013e62595afa49 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 2 Mar 2019 14:43:51 -0500 Subject: [PATCH] move/name velocity constant, rename move_vec, simplify cam rotate_by() Former-commit-id: 0835a9e91bd0133922f5d4e9731b9f6b6b547a0b --- client/src/lib.rs | 22 +++++----------------- common/src/sys/phys.rs | 2 +- voxygen/src/scene/camera.rs | 9 +++++---- voxygen/src/session.rs | 4 ++-- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 09305ff7a8..062f063fd7 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -18,7 +18,7 @@ pub enum Error { pub struct Input { // TODO: Use this type to manage client input - pub move_vec: Vec2, + pub move_dir: Vec2, } pub struct Client { @@ -101,23 +101,11 @@ impl Client { // (step 1) if let Some(p) = self.player { - let vel = input.move_vec; + // TODO: remove this + const PLAYER_VELOCITY: f32 = 100.0; - const MIN_LOOKING: f32 = 0.5; - const LEANING_FAC: f32 = 0.05; - - let dir = Vec3::from([ - // Rotation - match vel.magnitude() > MIN_LOOKING { - true => vel[0].atan2(vel[1]), - _ => 0.0, - }, - // Lean - Vec2::new(vel[0], vel[1]).magnitude() * LEANING_FAC, - ]); - - // TODO: Set acceleration instead and adjust dir calculations accordingly - self.state.write_component(p, Vel(Vec3::from(vel))); + // TODO: Set acceleration instead + self.state.write_component(p, Vel(Vec3::from(input.move_dir * PLAYER_VELOCITY))); } // Tick the client's LocalState (step 3) diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 50d944e2c2..2cf6c46aa6 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -20,6 +20,6 @@ impl<'a> System<'a> for MovementSys { fn run(&mut self, (mut positions, velocities, dt): Self::SystemData) { (&mut positions, &velocities) .join() // this can be parallelized with par_join() - .for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32 * 100.0); + .for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32); } } diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index 2c053764a6..4a7953fb1f 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -53,13 +53,14 @@ impl Camera { /// Rotate the camera about its focus by the given delta, limiting the input accordingly. pub fn rotate_by(&mut self, delta: Vec3) { - self.ori += delta; - // Wrap camera roll - self.ori.x = self.ori.x % (2.0 * PI); + // Wrap camera yaw + self.ori.x = (self.ori.x + delta.x) % (2.0 * PI); // Clamp camera pitch to the vertical limits - self.ori.y = self.ori.y + self.ori.y = (self.ori.y + delta.y) .min(PI / 2.0) .max(-PI / 2.0); + // Wrap camera roll + self.ori.z = (self.ori.z + delta.z) % (2.0 * PI); } /// Zoom the camera by the given delta, limiting the input accordingly. diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index ae465f9d2b..d555ec8f23 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -58,9 +58,9 @@ impl SessionState { Vec2::new(ori[0].sin(), ori[0].cos()), ); let dir_vec = self.key_state.dir_vec(); - let move_vec = unit_vecs.0 * dir_vec[0] + unit_vecs.1 * dir_vec[1]; + let move_dir = unit_vecs.0 * dir_vec[0] + unit_vecs.1 * dir_vec[1]; - self.client.tick(client::Input { move_vec }, dt)?; + self.client.tick(client::Input { move_dir }, dt)?; Ok(()) }