mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'treeco/camera-smoothing-setting' into 'master'
Add camera smoothing setting See merge request veloren/veloren!936
This commit is contained in:
@ -246,6 +246,7 @@ Enjoy your stay in the World of Veloren."#,
|
|||||||
"hud.settings.zoom_sensitivity": "Zoom Sensitivity",
|
"hud.settings.zoom_sensitivity": "Zoom Sensitivity",
|
||||||
"hud.settings.invert_scroll_zoom": "Invert Scroll Zoom",
|
"hud.settings.invert_scroll_zoom": "Invert Scroll Zoom",
|
||||||
"hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis",
|
"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.free_look_behavior": "Free look behavior",
|
||||||
|
|
||||||
"hud.settings.view_distance": "View Distance",
|
"hud.settings.view_distance": "View Distance",
|
||||||
|
@ -53,10 +53,13 @@ fn main() {
|
|||||||
tick: 0,
|
tick: 0,
|
||||||
body: Some(body.clone()),
|
body: Some(body.clone()),
|
||||||
gamma: 1.0,
|
gamma: 1.0,
|
||||||
|
mouse_smoothing: true,
|
||||||
};
|
};
|
||||||
scene.camera_mut().set_focus_pos(Vec3::unit_z() * 0.8);
|
scene.camera_mut().set_focus_pos(Vec3::unit_z() * 0.8);
|
||||||
scene.camera_mut().set_distance(1.5);
|
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);
|
scene.maintain(&mut renderer, scene_data);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
@ -208,6 +208,7 @@ pub enum Event {
|
|||||||
AdjustMouseZoom(u32),
|
AdjustMouseZoom(u32),
|
||||||
ToggleZoomInvert(bool),
|
ToggleZoomInvert(bool),
|
||||||
ToggleMouseYInvert(bool),
|
ToggleMouseYInvert(bool),
|
||||||
|
ToggleSmoothPan(bool),
|
||||||
AdjustViewDistance(u32),
|
AdjustViewDistance(u32),
|
||||||
AdjustMusicVolume(f32),
|
AdjustMusicVolume(f32),
|
||||||
AdjustSfxVolume(f32),
|
AdjustSfxVolume(f32),
|
||||||
@ -1794,6 +1795,9 @@ impl Hud {
|
|||||||
settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => {
|
settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => {
|
||||||
events.push(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) => {
|
settings_window::Event::AdjustViewDistance(view_distance) => {
|
||||||
events.push(Event::AdjustViewDistance(view_distance));
|
events.push(Event::AdjustViewDistance(view_distance));
|
||||||
},
|
},
|
||||||
|
@ -66,6 +66,8 @@ widget_ids! {
|
|||||||
mouse_zoom_invert_label,
|
mouse_zoom_invert_label,
|
||||||
mouse_y_invert_button,
|
mouse_y_invert_button,
|
||||||
mouse_y_invert_label,
|
mouse_y_invert_label,
|
||||||
|
smooth_pan_toggle_button,
|
||||||
|
smooth_pan_toggle_label,
|
||||||
ch_title,
|
ch_title,
|
||||||
ch_transp_slider,
|
ch_transp_slider,
|
||||||
ch_transp_label,
|
ch_transp_label,
|
||||||
@ -205,6 +207,7 @@ pub enum Event {
|
|||||||
AdjustMouseZoom(u32),
|
AdjustMouseZoom(u32),
|
||||||
ToggleZoomInvert(bool),
|
ToggleZoomInvert(bool),
|
||||||
ToggleMouseYInvert(bool),
|
ToggleMouseYInvert(bool),
|
||||||
|
ToggleSmoothPan(bool),
|
||||||
AdjustViewDistance(u32),
|
AdjustViewDistance(u32),
|
||||||
AdjustFOV(u16),
|
AdjustFOV(u16),
|
||||||
AdjustGamma(f32),
|
AdjustGamma(f32),
|
||||||
@ -1239,7 +1242,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
self.imgs.checkbox_checked,
|
self.imgs.checkbox_checked,
|
||||||
)
|
)
|
||||||
.w_h(18.0, 18.0)
|
.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)
|
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
|
||||||
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
|
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
|
||||||
.set(state.ids.mouse_y_invert_button, ui);
|
.set(state.ids.mouse_y_invert_button, ui);
|
||||||
@ -1262,6 +1265,36 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.mouse_y_invert_label, ui);
|
.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
|
// Free look behaviour
|
||||||
Text::new(
|
Text::new(
|
||||||
&self
|
&self
|
||||||
|
@ -106,6 +106,7 @@ impl PlayState for CharSelectionState {
|
|||||||
tick: client.get_tick(),
|
tick: client.get_tick(),
|
||||||
body: humanoid_body.clone(),
|
body: humanoid_body.clone(),
|
||||||
gamma: global_state.settings.graphics.gamma,
|
gamma: global_state.settings.graphics.gamma,
|
||||||
|
mouse_smoothing: global_state.settings.gameplay.smooth_pan_enable,
|
||||||
};
|
};
|
||||||
self.scene
|
self.scene
|
||||||
.maintain(global_state.window.renderer_mut(), scene_data);
|
.maintain(global_state.window.renderer_mut(), scene_data);
|
||||||
|
@ -190,7 +190,7 @@ impl Camera {
|
|||||||
/// Set the distance of the camera from the target (i.e., zoom).
|
/// 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 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
|
// 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);
|
let delta = self.last_time.replace(time).map_or(0.0, |t| time - t);
|
||||||
if (self.dist - self.tgt_dist).abs() > 0.01 {
|
if (self.dist - self.tgt_dist).abs() > 0.01 {
|
||||||
@ -217,11 +217,15 @@ impl Camera {
|
|||||||
Lerp::lerp(a, b + *offs, rate)
|
Lerp::lerp(a, b + *offs, rate)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.set_ori_instant(Vec3::new(
|
if smoothing_enabled {
|
||||||
lerp_angle(self.ori.x, self.tgt_ori.x, LERP_ORI_RATE * dt),
|
self.set_ori_instant(Vec3::new(
|
||||||
Lerp::lerp(self.ori.y, self.tgt_ori.y, LERP_ORI_RATE * dt),
|
lerp_angle(self.ori.x, self.tgt_ori.x, LERP_ORI_RATE * dt),
|
||||||
lerp_angle(self.ori.z, self.tgt_ori.z, 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 {
|
pub fn interp_time(&self) -> f32 {
|
||||||
|
@ -74,6 +74,8 @@ pub struct SceneData<'a> {
|
|||||||
pub view_distance: u32,
|
pub view_distance: u32,
|
||||||
pub tick: u64,
|
pub tick: u64,
|
||||||
pub thread_pool: &'a uvth::ThreadPool,
|
pub thread_pool: &'a uvth::ThreadPool,
|
||||||
|
pub gamma: f32,
|
||||||
|
pub mouse_smoothing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
@ -177,7 +179,6 @@ impl Scene {
|
|||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
audio: &mut AudioFrontend,
|
audio: &mut AudioFrontend,
|
||||||
scene_data: &SceneData,
|
scene_data: &SceneData,
|
||||||
gamma: f32,
|
|
||||||
) {
|
) {
|
||||||
// Get player position.
|
// Get player position.
|
||||||
let ecs = scene_data.state.ecs();
|
let ecs = scene_data.state.ecs();
|
||||||
@ -243,6 +244,7 @@ impl Scene {
|
|||||||
self.camera.update(
|
self.camera.update(
|
||||||
scene_data.state.get_time(),
|
scene_data.state.get_time(),
|
||||||
scene_data.state.get_delta_time(),
|
scene_data.state.get_delta_time(),
|
||||||
|
scene_data.mouse_smoothing,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute camera matrices.
|
// Compute camera matrices.
|
||||||
@ -349,7 +351,7 @@ impl Scene {
|
|||||||
.map(|b| b.kind())
|
.map(|b| b.kind())
|
||||||
.unwrap_or(BlockKind::Air),
|
.unwrap_or(BlockKind::Air),
|
||||||
self.select_pos,
|
self.select_pos,
|
||||||
gamma,
|
scene_data.gamma,
|
||||||
self.camera.get_mode(),
|
self.camera.get_mode(),
|
||||||
)])
|
)])
|
||||||
.expect("Failed to update global constants");
|
.expect("Failed to update global constants");
|
||||||
|
@ -73,6 +73,7 @@ pub struct SceneData {
|
|||||||
pub tick: u64,
|
pub tick: u64,
|
||||||
pub body: Option<humanoid::Body>,
|
pub body: Option<humanoid::Body>,
|
||||||
pub gamma: f32,
|
pub gamma: f32,
|
||||||
|
pub mouse_smoothing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
@ -146,7 +147,8 @@ impl Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn maintain(&mut self, renderer: &mut Renderer, scene_data: SceneData) {
|
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);
|
self.camera.compute_dependents(&VoidVol);
|
||||||
let camera::Dependents {
|
let camera::Dependents {
|
||||||
|
@ -579,6 +579,10 @@ impl PlayState for SessionState {
|
|||||||
global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted;
|
global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted;
|
||||||
global_state.settings.save_to_file_warn();
|
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) => {
|
HudEvent::AdjustViewDistance(view_distance) => {
|
||||||
self.client.borrow_mut().set_view_distance(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),
|
view_distance: client.view_distance().unwrap_or(1),
|
||||||
tick: client.get_tick(),
|
tick: client.get_tick(),
|
||||||
thread_pool: client.thread_pool(),
|
thread_pool: client.thread_pool(),
|
||||||
|
gamma: global_state.settings.graphics.gamma,
|
||||||
|
mouse_smoothing: global_state.settings.gameplay.smooth_pan_enable,
|
||||||
};
|
};
|
||||||
self.scene.maintain(
|
self.scene.maintain(
|
||||||
global_state.window.renderer_mut(),
|
global_state.window.renderer_mut(),
|
||||||
&mut global_state.audio,
|
&mut global_state.audio,
|
||||||
&scene_data,
|
&scene_data,
|
||||||
global_state.settings.graphics.gamma,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +448,7 @@ pub struct GameplaySettings {
|
|||||||
pub sct_player_batch: bool,
|
pub sct_player_batch: bool,
|
||||||
pub sct_damage_batch: bool,
|
pub sct_damage_batch: bool,
|
||||||
pub mouse_y_inversion: bool,
|
pub mouse_y_inversion: bool,
|
||||||
|
pub smooth_pan_enable: bool,
|
||||||
pub crosshair_transp: f32,
|
pub crosshair_transp: f32,
|
||||||
pub chat_transp: f32,
|
pub chat_transp: f32,
|
||||||
pub crosshair_type: CrosshairType,
|
pub crosshair_type: CrosshairType,
|
||||||
@ -466,6 +467,7 @@ impl Default for GameplaySettings {
|
|||||||
zoom_sensitivity: 100,
|
zoom_sensitivity: 100,
|
||||||
zoom_inversion: false,
|
zoom_inversion: false,
|
||||||
mouse_y_inversion: false,
|
mouse_y_inversion: false,
|
||||||
|
smooth_pan_enable: true,
|
||||||
toggle_debug: false,
|
toggle_debug: false,
|
||||||
sct: true,
|
sct: true,
|
||||||
sct_player_batch: true,
|
sct_player_batch: true,
|
||||||
|
Reference in New Issue
Block a user