mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Better camera at smaller scales
This commit is contained in:
parent
87a6143375
commit
f349e99cfb
@ -551,13 +551,13 @@ impl Camera {
|
||||
/// Zoom with the ability to switch between first and third-person mode.
|
||||
///
|
||||
/// Note that cap > 18237958000000.0 can cause panic due to float overflow
|
||||
pub fn zoom_switch(&mut self, delta: f32, cap: f32) {
|
||||
pub fn zoom_switch(&mut self, delta: f32, cap: f32, scale: f32) {
|
||||
if delta > 0_f32 || self.mode != CameraMode::FirstPerson {
|
||||
let t = self.tgt_dist + delta;
|
||||
const MIN_THIRD_PERSON: f32 = 2.35;
|
||||
match self.mode {
|
||||
CameraMode::ThirdPerson => {
|
||||
if t < MIN_THIRD_PERSON {
|
||||
if t < MIN_THIRD_PERSON * scale {
|
||||
self.set_mode(CameraMode::FirstPerson);
|
||||
} else {
|
||||
self.tgt_dist = t;
|
||||
@ -565,7 +565,7 @@ impl Camera {
|
||||
},
|
||||
CameraMode::FirstPerson => {
|
||||
self.set_mode(CameraMode::ThirdPerson);
|
||||
self.tgt_dist = MIN_THIRD_PERSON;
|
||||
self.tgt_dist = MIN_THIRD_PERSON * scale;
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
@ -409,15 +409,16 @@ impl Scene {
|
||||
// when zooming in the distance the camera travelles should be based on the
|
||||
// final distance. This is to make sure the camera travelles the
|
||||
// same distance when zooming in and out
|
||||
let player_scale = client.state().read_component_copied::<comp::Scale>(client.entity()).map_or(1.0, |s| s.0);
|
||||
if delta < 0.0 {
|
||||
self.camera.zoom_switch(
|
||||
// Thank you Imbris for doing the math
|
||||
delta * (0.05 + self.camera.get_distance() * 0.01) / (1.0 - delta * 0.01),
|
||||
cap,
|
||||
player_scale,
|
||||
);
|
||||
} else {
|
||||
self.camera
|
||||
.zoom_switch(delta * (0.05 + self.camera.get_distance() * 0.01), cap);
|
||||
self.camera.zoom_switch(delta * (0.05 + self.camera.get_distance() * 0.01), cap, player_scale);
|
||||
}
|
||||
true
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user