Merge branch 'telastrus/first-person' into 'master'

added first person switch

See merge request veloren/veloren!425
This commit is contained in:
Marcel 2019-08-13 17:54:13 +00:00
commit f4aa053b53
2 changed files with 21 additions and 18 deletions

View File

@ -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 /// Get the distance of the camera from the target
pub fn get_distance(&self) -> f32 { pub fn get_distance(&self) -> f32 {
self.tgt_dist self.tgt_dist

View File

@ -106,7 +106,7 @@ impl Scene {
} }
// Zoom the camera when a zoom event occurs // Zoom the camera when a zoom event occurs
Event::Zoom(delta) => { Event::Zoom(delta) => {
self.camera.zoom_by(delta * 0.3); self.camera.zoom_switch(delta * 0.3);
true true
} }
// All other events are unhandled // All other events are unhandled
@ -127,12 +127,7 @@ impl Scene {
// Alter camera position to match player. // Alter camera position to match player.
let tilt = self.camera.get_orientation().y; let tilt = self.camera.get_orientation().y;
let dist = self.camera.get_distance(); let dist = self.camera.get_distance();
let up = if client let up = if self.camera.get_mode() == CameraMode::FirstPerson {
.state()
.read_storage::<comp::CanBuild>()
.get(client.entity())
.is_some()
{
1.5 1.5
} else { } else {
1.2 1.2
@ -213,17 +208,6 @@ impl Scene {
proj_mat, proj_mat,
); );
if client
.state()
.read_storage::<comp::CanBuild>()
.get(client.entity())
.is_some()
{
self.camera.set_mode(CameraMode::FirstPerson);
} else {
self.camera.set_mode(CameraMode::ThirdPerson);
}
// Maintain the figures. // Maintain the figures.
self.figure_mgr.maintain(renderer, client); self.figure_mgr.maintain(renderer, client);