diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 5a8a36eea1..741a996778 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -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)); + } } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 07d5b96980..eb550c0c2a 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -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 ----------------------------------- diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index d4655e0f49..c6d96072a3 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -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 { diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index fd5cffde92..ddbb4f3343 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -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. diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 647d83675a..50b77657f2 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -27,7 +27,8 @@ impl SessionState { /// Create a new `SessionState`. pub fn new(global_state: &mut GlobalState, client: Rc>) -> 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); + } } } diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 938e77bb82..886d7bb95a 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -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 } } }