mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add zoom cap to admin to keep zoom in a sensible range
By clamping zoom, panic due to float overflow is avoided Regular player zoom cap is also reduced to a more sensible range
This commit is contained in:
parent
4131b3ac20
commit
8a132d0726
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Removed
|
||||
|
||||
### Fixed
|
||||
- Fixed crash due to zooming out very far
|
||||
|
||||
## [0.13.0] - 2022-07-23
|
||||
|
||||
|
@ -541,7 +541,9 @@ impl Camera {
|
||||
}
|
||||
|
||||
/// Zoom with the ability to switch between first and third-person mode.
|
||||
pub fn zoom_switch(&mut self, delta: f32, cap: Option<f32>) {
|
||||
///
|
||||
/// Note that cap > 18237958000000.0 can cause panic due to float overflow
|
||||
pub fn zoom_switch(&mut self, delta: f32, cap: f32) {
|
||||
if delta > 0_f32 || self.mode != CameraMode::FirstPerson {
|
||||
let t = self.tgt_dist + delta;
|
||||
const MIN_THIRD_PERSON: f32 = 2.35;
|
||||
@ -561,9 +563,7 @@ impl Camera {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cap) = cap {
|
||||
self.tgt_dist = self.tgt_dist.min(cap);
|
||||
}
|
||||
self.tgt_dist = self.tgt_dist.min(cap);
|
||||
}
|
||||
|
||||
/// Get the distance of the camera from the focus
|
||||
|
@ -44,7 +44,8 @@ use num::traits::{Float, FloatConst};
|
||||
use specs::{Entity as EcsEntity, Join, WorldExt};
|
||||
use vek::*;
|
||||
|
||||
const ZOOM_CAP: f32 = 10000.0;
|
||||
const ZOOM_CAP_PLAYER: f32 = 1000.0;
|
||||
const ZOOM_CAP_ADMIN: f32 = 100000.0;
|
||||
|
||||
// TODO: Don't hard-code this.
|
||||
const CURSOR_PAN_SCALE: f32 = 0.005;
|
||||
@ -380,10 +381,14 @@ impl Scene {
|
||||
},
|
||||
// Zoom the camera when a zoom event occurs
|
||||
Event::Zoom(delta) => {
|
||||
let cap = if client.is_moderator() {
|
||||
ZOOM_CAP_ADMIN
|
||||
} else {
|
||||
ZOOM_CAP_PLAYER
|
||||
};
|
||||
// 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 cap = (!client.is_moderator()).then_some(ZOOM_CAP);
|
||||
if delta < 0.0 {
|
||||
self.camera.zoom_switch(
|
||||
// Thank you Imbris for doing the math
|
||||
|
Loading…
Reference in New Issue
Block a user