From a9f20148a4b3104f89004d459e8fd139d7f1baf5 Mon Sep 17 00:00:00 2001 From: Geno <4415544-telastrus@users.noreply.gitlab.com> Date: Tue, 13 Aug 2019 17:54:13 +0000 Subject: [PATCH] added first person switch --- voxygen/src/scene/camera.rs | 19 +++++++++++++++++++ voxygen/src/scene/mod.rs | 20 ++------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index 3021652bef..437dd12046 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -123,6 +123,25 @@ impl Camera { }; } + /// Zoom with the ability to switch between first and third-person mode. + pub fn zoom_switch(&mut self, delta: f32) { + if delta > 0_f32 || self.mode != CameraMode::FirstPerson { + let t = self.tgt_dist + delta; + match self.mode { + CameraMode::ThirdPerson => { + if t < 2_f32 { + self.set_mode(CameraMode::FirstPerson); + } else { + self.tgt_dist = t; + } + } + CameraMode::FirstPerson => { + self.set_mode(CameraMode::ThirdPerson); + } + } + } + } + /// Get the distance of the camera from the target pub fn get_distance(&self) -> f32 { self.tgt_dist diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 8ad014a25b..50acb1a533 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -106,7 +106,7 @@ impl Scene { } // Zoom the camera when a zoom event occurs Event::Zoom(delta) => { - self.camera.zoom_by(delta * 0.3); + self.camera.zoom_switch(delta * 0.3); true } // All other events are unhandled @@ -127,12 +127,7 @@ impl Scene { // Alter camera position to match player. let tilt = self.camera.get_orientation().y; let dist = self.camera.get_distance(); - let up = if client - .state() - .read_storage::() - .get(client.entity()) - .is_some() - { + let up = if self.camera.get_mode() == CameraMode::FirstPerson { 1.5 } else { 1.2 @@ -213,17 +208,6 @@ impl Scene { proj_mat, ); - if client - .state() - .read_storage::() - .get(client.entity()) - .is_some() - { - self.camera.set_mode(CameraMode::FirstPerson); - } else { - self.camera.set_mode(CameraMode::ThirdPerson); - } - // Maintain the figures. self.figure_mgr.maintain(renderer, client);