Add zoom scaling as well as FOV scaling to ChargedRanged, and restore the old zoom afterwards.

This commit is contained in:
Avi Weinstock 2021-05-23 17:31:44 -04:00
parent 4d7828ec94
commit 7a97fbb5cf
3 changed files with 31 additions and 12 deletions

View File

@ -64,7 +64,11 @@ pub struct Data {
impl Data { impl Data {
/// How complete the charge is, on a scale of 0.0 to 1.0 /// How complete the charge is, on a scale of 0.0 to 1.0
pub fn charge_frac(&self) -> f32 { pub fn charge_frac(&self) -> f32 {
(self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()).min(1.0) if let StageSection::Charge = self.stage_section {
(self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()).min(1.0)
} else {
0.0
}
} }
} }

View File

@ -42,6 +42,7 @@ pub struct Camera {
ori: Vec3<f32>, ori: Vec3<f32>,
tgt_dist: f32, tgt_dist: f32,
dist: f32, dist: f32,
tgt_fov: f32,
fov: f32, fov: f32,
aspect: f32, aspect: f32,
mode: CameraMode, mode: CameraMode,
@ -76,6 +77,7 @@ impl Camera {
ori: Vec3::zero(), ori: Vec3::zero(),
tgt_dist: 10.0, tgt_dist: 10.0,
dist: 10.0, dist: 10.0,
tgt_fov: 1.1,
fov: 1.1, fov: 1.1,
aspect, aspect,
mode, mode,
@ -222,6 +224,14 @@ impl Camera {
); );
} }
if (self.fov - self.tgt_fov).abs() > 0.01 {
self.fov = f32::lerp(
self.fov,
self.tgt_fov,
0.65 * (delta as f32) / self.interp_time(),
);
}
if (self.focus - self.tgt_focus).magnitude_squared() > 0.001 { if (self.focus - self.tgt_focus).magnitude_squared() > 0.001 {
let lerped_focus = Lerp::lerp( let lerped_focus = Lerp::lerp(
self.focus, self.focus,
@ -290,7 +300,7 @@ impl Camera {
pub fn get_fov(&self) -> f32 { self.fov } pub fn get_fov(&self) -> f32 { self.fov }
/// Set the field of view of the camera in radians. /// Set the field of view of the camera in radians.
pub fn set_fov(&mut self, fov: f32) { self.fov = fov; } pub fn set_fov(&mut self, fov: f32) { self.tgt_fov = fov; }
/// Set the FOV in degrees /// Set the FOV in degrees
pub fn set_fov_deg(&mut self, fov: u16) { pub fn set_fov_deg(&mut self, fov: u16) {

View File

@ -72,6 +72,7 @@ pub struct SessionState {
target_entity: Option<specs::Entity>, target_entity: Option<specs::Entity>,
selected_entity: Option<(specs::Entity, std::time::Instant)>, selected_entity: Option<(specs::Entity, std::time::Instant)>,
interactable: Option<Interactable>, interactable: Option<Interactable>,
saved_zoom_dist: Option<f32>,
} }
/// Represents an active game session (i.e., the one being played). /// Represents an active game session (i.e., the one being played).
@ -118,6 +119,7 @@ impl SessionState {
target_entity: None, target_entity: None,
selected_entity: None, selected_entity: None,
interactable: None, interactable: None,
saved_zoom_dist: None,
} }
} }
@ -298,17 +300,20 @@ impl PlayState for SessionState {
let client = self.client.borrow(); let client = self.client.borrow();
let player_entity = client.entity(); let player_entity = client.entity();
let fov_scaling = { let mut fov_scaling = 1.0;
if let Some(comp::CharacterState::ChargedRanged(cr)) = client if let Some(comp::CharacterState::ChargedRanged(cr)) = client
.state() .state()
.read_storage::<comp::CharacterState>() .read_storage::<comp::CharacterState>()
.get(player_entity) .get(player_entity)
{ {
1.0 - 3.0 * cr.charge_frac() / 4.0 fov_scaling -= 3.0 * cr.charge_frac() / 4.0;
} else { if self.saved_zoom_dist.is_none() {
1.0 self.saved_zoom_dist = Some(camera.get_distance());
camera.set_distance(0.0);
} }
}; } else if let Some(dist) = self.saved_zoom_dist.take() {
camera.set_distance(dist);
}
camera.set_fov((global_state.settings.graphics.fov as f32 * fov_scaling).to_radians()); camera.set_fov((global_state.settings.graphics.fov as f32 * fov_scaling).to_radians());
// Compute camera data // Compute camera data