Merge branch 'treeco/camera-smoothing-setting' into 'master'

Add camera smoothing setting

See merge request veloren/veloren!936
This commit is contained in:
Monty Marz 2020-04-23 22:59:35 +00:00
commit f3200ec1ec
10 changed files with 69 additions and 12 deletions

View File

@ -246,6 +246,7 @@ Enjoy your stay in the World of Veloren."#,
"hud.settings.zoom_sensitivity": "Zoom Sensitivity",
"hud.settings.invert_scroll_zoom": "Invert Scroll Zoom",
"hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis",
"hud.settings.enable_mouse_smoothing": "Camera Smoothing",
"hud.settings.free_look_behavior": "Free look behavior",
"hud.settings.view_distance": "View Distance",

View File

@ -53,10 +53,13 @@ fn main() {
tick: 0,
body: Some(body.clone()),
gamma: 1.0,
mouse_smoothing: true,
};
scene.camera_mut().set_focus_pos(Vec3::unit_z() * 0.8);
scene.camera_mut().set_distance(1.5);
scene.camera_mut().update(0.0, 1.0 / 60.0);
scene
.camera_mut()
.update(0.0, 1.0 / 60.0, scene_data.mouse_smoothing);
scene.maintain(&mut renderer, scene_data);
// Render

View File

@ -208,6 +208,7 @@ pub enum Event {
AdjustMouseZoom(u32),
ToggleZoomInvert(bool),
ToggleMouseYInvert(bool),
ToggleSmoothPan(bool),
AdjustViewDistance(u32),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
@ -1794,6 +1795,9 @@ impl Hud {
settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => {
events.push(Event::ToggleMouseYInvert(mouse_y_inverted));
},
settings_window::Event::ToggleSmoothPan(smooth_pan_enabled) => {
events.push(Event::ToggleSmoothPan(smooth_pan_enabled));
},
settings_window::Event::AdjustViewDistance(view_distance) => {
events.push(Event::AdjustViewDistance(view_distance));
},

View File

@ -66,6 +66,8 @@ widget_ids! {
mouse_zoom_invert_label,
mouse_y_invert_button,
mouse_y_invert_label,
smooth_pan_toggle_button,
smooth_pan_toggle_label,
ch_title,
ch_transp_slider,
ch_transp_label,
@ -205,6 +207,7 @@ pub enum Event {
AdjustMouseZoom(u32),
ToggleZoomInvert(bool),
ToggleMouseYInvert(bool),
ToggleSmoothPan(bool),
AdjustViewDistance(u32),
AdjustFOV(u16),
AdjustGamma(f32),
@ -1239,7 +1242,7 @@ impl<'a> Widget for SettingsWindow<'a> {
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.right_from(state.ids.mouse_zoom_invert_button, 250.0)
.right_from(state.ids.mouse_zoom_invert_button, 175.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.mouse_y_invert_button, ui);
@ -1262,6 +1265,36 @@ impl<'a> Widget for SettingsWindow<'a> {
.color(TEXT_COLOR)
.set(state.ids.mouse_y_invert_label, ui);
// Mouse Smoothing Toggle
let smooth_pan_enabled = ToggleButton::new(
self.global_state.settings.gameplay.smooth_pan_enable,
self.imgs.checkbox,
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.right_from(state.ids.mouse_y_invert_button, 175.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.smooth_pan_toggle_button, ui);
if self.global_state.settings.gameplay.smooth_pan_enable != smooth_pan_enabled {
events.push(Event::ToggleSmoothPan(
!self.global_state.settings.gameplay.smooth_pan_enable,
));
}
Text::new(
&self
.localized_strings
.get("hud.settings.enable_mouse_smoothing"),
)
.right_from(state.ids.smooth_pan_toggle_button, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.graphics_for(state.ids.smooth_pan_toggle_button)
.color(TEXT_COLOR)
.set(state.ids.smooth_pan_toggle_label, ui);
// Free look behaviour
Text::new(
&self

View File

@ -106,6 +106,7 @@ impl PlayState for CharSelectionState {
tick: client.get_tick(),
body: humanoid_body.clone(),
gamma: global_state.settings.graphics.gamma,
mouse_smoothing: global_state.settings.gameplay.smooth_pan_enable,
};
self.scene
.maintain(global_state.window.renderer_mut(), scene_data);

View File

@ -190,7 +190,7 @@ impl Camera {
/// Set the distance of the camera from the target (i.e., zoom).
pub fn set_distance(&mut self, dist: f32) { self.tgt_dist = dist; }
pub fn update(&mut self, time: f64, dt: f32) {
pub fn update(&mut self, time: f64, dt: f32, smoothing_enabled: bool) {
// This is horribly frame time dependent, but so is most of the game
let delta = self.last_time.replace(time).map_or(0.0, |t| time - t);
if (self.dist - self.tgt_dist).abs() > 0.01 {
@ -217,11 +217,15 @@ impl Camera {
Lerp::lerp(a, b + *offs, rate)
};
self.set_ori_instant(Vec3::new(
lerp_angle(self.ori.x, self.tgt_ori.x, LERP_ORI_RATE * dt),
Lerp::lerp(self.ori.y, self.tgt_ori.y, LERP_ORI_RATE * dt),
lerp_angle(self.ori.z, self.tgt_ori.z, LERP_ORI_RATE * dt),
));
if smoothing_enabled {
self.set_ori_instant(Vec3::new(
lerp_angle(self.ori.x, self.tgt_ori.x, LERP_ORI_RATE * dt),
Lerp::lerp(self.ori.y, self.tgt_ori.y, LERP_ORI_RATE * dt),
lerp_angle(self.ori.z, self.tgt_ori.z, LERP_ORI_RATE * dt),
));
} else {
self.set_ori_instant(self.tgt_ori)
};
}
pub fn interp_time(&self) -> f32 {

View File

@ -74,6 +74,8 @@ pub struct SceneData<'a> {
pub view_distance: u32,
pub tick: u64,
pub thread_pool: &'a uvth::ThreadPool,
pub gamma: f32,
pub mouse_smoothing: bool,
}
impl Scene {
@ -177,7 +179,6 @@ impl Scene {
renderer: &mut Renderer,
audio: &mut AudioFrontend,
scene_data: &SceneData,
gamma: f32,
) {
// Get player position.
let ecs = scene_data.state.ecs();
@ -243,6 +244,7 @@ impl Scene {
self.camera.update(
scene_data.state.get_time(),
scene_data.state.get_delta_time(),
scene_data.mouse_smoothing,
);
// Compute camera matrices.
@ -349,7 +351,7 @@ impl Scene {
.map(|b| b.kind())
.unwrap_or(BlockKind::Air),
self.select_pos,
gamma,
scene_data.gamma,
self.camera.get_mode(),
)])
.expect("Failed to update global constants");

View File

@ -73,6 +73,7 @@ pub struct SceneData {
pub tick: u64,
pub body: Option<humanoid::Body>,
pub gamma: f32,
pub mouse_smoothing: bool,
}
impl Scene {
@ -146,7 +147,8 @@ impl Scene {
}
pub fn maintain(&mut self, renderer: &mut Renderer, scene_data: SceneData) {
self.camera.update(scene_data.time, 1.0 / 60.0);
self.camera
.update(scene_data.time, 1.0 / 60.0, scene_data.mouse_smoothing);
self.camera.compute_dependents(&VoidVol);
let camera::Dependents {

View File

@ -579,6 +579,10 @@ impl PlayState for SessionState {
global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleSmoothPan(smooth_pan_enabled) => {
global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustViewDistance(view_distance) => {
self.client.borrow_mut().set_view_distance(view_distance);
@ -728,12 +732,13 @@ impl PlayState for SessionState {
view_distance: client.view_distance().unwrap_or(1),
tick: client.get_tick(),
thread_pool: client.thread_pool(),
gamma: global_state.settings.graphics.gamma,
mouse_smoothing: global_state.settings.gameplay.smooth_pan_enable,
};
self.scene.maintain(
global_state.window.renderer_mut(),
&mut global_state.audio,
&scene_data,
global_state.settings.graphics.gamma,
);
}

View File

@ -448,6 +448,7 @@ pub struct GameplaySettings {
pub sct_player_batch: bool,
pub sct_damage_batch: bool,
pub mouse_y_inversion: bool,
pub smooth_pan_enable: bool,
pub crosshair_transp: f32,
pub chat_transp: f32,
pub crosshair_type: CrosshairType,
@ -466,6 +467,7 @@ impl Default for GameplaySettings {
zoom_sensitivity: 100,
zoom_inversion: false,
mouse_y_inversion: false,
smooth_pan_enable: true,
toggle_debug: false,
sct: true,
sct_player_batch: true,