Added adjustable FOV slider

This commit is contained in:
telastrus 2019-08-05 12:37:52 -04:00
parent ade0724baf
commit c098a5efd7
6 changed files with 66 additions and 4 deletions

View File

@ -137,6 +137,7 @@ pub enum Event {
AdjustVolume(f32),
ChangeAudioDevice(String),
ChangeMaxFPS(u32),
ChangeFOV(u16),
CrosshairTransp(f32),
CrosshairType(CrosshairType),
UiScale(ScaleChange),
@ -681,6 +682,9 @@ impl Hud {
settings_window::Event::UiScale(scale_change) => {
events.push(Event::UiScale(scale_change));
}
settings_window::Event::AdjustFOV(new_fov) => {
events.push(Event::ChangeFOV(new_fov));
}
}
}
}

View File

@ -74,6 +74,9 @@ widget_ids! {
max_fps_slider,
max_fps_text,
max_fps_value,
fov_slider,
fov_text,
fov_value,
audio_volume_slider,
audio_volume_text,
audio_device_list,
@ -132,6 +135,7 @@ pub enum Event {
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustViewDistance(u32),
AdjustFOV(u16),
AdjustVolume(f32),
ChangeAudioDevice(String),
MaximumFPS(u32),
@ -976,6 +980,41 @@ impl<'a> Widget for SettingsWindow<'a> {
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.max_fps_value, ui);
// FOV
Text::new("Field of View (deg)")
.down_from(state.ids.max_fps_slider, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.fov_text, ui);
if let Some(new_val) = ImageSlider::discrete(
self.global_state.settings.graphics.fov,
30,
120,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.down_from(state.ids.fov_text, 8.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.fov_slider, ui)
{
events.push(Event::AdjustFOV(new_val));
}
Text::new(&format!(
"{}",
self.global_state.settings.graphics.fov
))
.right_from(state.ids.fov_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.fov_value, ui);
}
// 5) Sound Tab -----------------------------------

View File

@ -38,7 +38,7 @@ impl Camera {
ori: Vec3::zero(),
tgt_dist: 10.0,
dist: 10.0,
fov: 1.1,
fov: 1.3,
aspect,
mode,
@ -173,6 +173,17 @@ impl Camera {
self.fov
}
/// Set the field of view of the camera in radians.
pub fn set_fov(&mut self, fov: f32) {
self.fov = fov;
}
/// Set the FOV in degrees
pub fn set_fov_deg(&mut self, fov: u16) {
//Magic value comes from p/180; no use recalculating.
self.set_fov((fov as f32) * 0.01745329)
}
/// Set the mode of the camera.
pub fn set_mode(&mut self, mode: CameraMode) {
if self.mode != mode {

View File

@ -80,8 +80,8 @@ impl Scene {
}
/// Get a reference to the scene's camera.
pub fn camera(&self) -> &Camera {
&self.camera
pub fn camera(&mut self) -> &mut Camera {
&mut self.camera
}
/// Get a mutable reference to the scene's camera.

View File

@ -27,7 +27,8 @@ impl SessionState {
/// Create a new `SessionState`.
pub fn new(global_state: &mut GlobalState, client: Rc<RefCell<Client>>) -> Self {
// Create a scene for this session. The scene handles visible elements of the game world.
let scene = Scene::new(global_state.window.renderer_mut());
let mut scene = Scene::new(global_state.window.renderer_mut());
scene.camera_mut().set_fov_deg(global_state.settings.graphics.fov);
Self {
scene,
client,
@ -354,6 +355,11 @@ impl PlayState for SessionState {
HudEvent::DropInventorySlot(x) => {
self.client.borrow_mut().drop_inventory_slot(x)
}
HudEvent::ChangeFOV(new_fov) => {
global_state.settings.graphics.fov = new_fov;
global_state.settings.save_to_file_warn();
&self.scene.camera_mut().set_fov_deg(new_fov);
}
}
}

View File

@ -135,6 +135,7 @@ impl Default for Log {
pub struct GraphicsSettings {
pub view_distance: u32,
pub max_fps: u32,
pub fov: u16
}
impl Default for GraphicsSettings {
@ -142,6 +143,7 @@ impl Default for GraphicsSettings {
Self {
view_distance: 5,
max_fps: 60,
fov: 75
}
}
}