Skip to content

Commit

Permalink
Remove unused function inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevcat committed Jul 3, 2022
1 parent a41a119 commit 5bbc69b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
39 changes: 15 additions & 24 deletions crates/fj-viewer/src/input/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Instant;

use fj_interop::mesh::Mesh;
use fj_math::Point;

Expand All @@ -24,24 +22,6 @@ pub struct Handler {
}

impl Handler {
/// Returns a new Handler.
///
/// # Examples
/// ```rust no_run
/// // Store initialization time for camera zoom calculations
/// let instant = std::time::Instant::now();
/// let input_handler = fj_viewer::input::Handler::new(instant);
/// ```
pub fn new(now: Instant) -> Self {
Self {
cursor: None,

movement: Movement::new(),
rotation: Rotation::new(),
zoom: Zoom::new(),
}
}

/// Returns the state of the cursor position.
pub fn cursor(&self) -> Option<Position> {
self.cursor
Expand All @@ -52,7 +32,6 @@ impl Handler {
&mut self,
event: Event,
screen_size: Size,
now: Instant,
mesh: &Mesh<Point<3>>,
camera: &mut Camera,
actions: &mut Actions,
Expand Down Expand Up @@ -112,12 +91,24 @@ impl Handler {
pub fn update(
&mut self,
delta_t: f64,
now: Instant,
camera: &mut Camera,
size: Size,
screen_size: Size,
mesh: &Mesh<Point<3>>,
) {
self.zoom.apply_to_camera(delta_t, camera);
let focus_point = camera.focus_point(screen_size, self.cursor(), mesh);
self.zoom.apply_to_camera(delta_t, focus_point, camera);
}
}

impl Default for Handler {
fn default() -> Self {
Self {
cursor: None,

movement: Movement::new(),
rotation: Rotation::new(),
zoom: Zoom::new(),
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions crates/fj-viewer/src/input/zoom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fj_math::{Transform, Vector};

use crate::camera::Camera;
use crate::camera::{Camera, FocusPoint};

pub struct Zoom {
accumulated_delta: f64,
Expand All @@ -18,11 +18,20 @@ impl Zoom {
self.accumulated_delta += delta;
}

pub fn apply_to_camera(&mut self, delta_t: f64, camera: &mut Camera) {
pub fn apply_to_camera(
&mut self,
delta_t: f64,
focus_point: FocusPoint,
camera: &mut Camera,
) {
let distance = match focus_point.0 {
Some(fp) => (fp - camera.position()).magnitude(),
None => camera.position().coords.magnitude(),
};
let displacement = self.accumulated_delta
* delta_t
* ZOOM_FACTOR
* camera.position().coords.magnitude().into_f64();
* distance.into_f64();
camera.translation = camera.translation
* Transform::translation(Vector::from([0.0, 0.0, -displacement]));

Expand Down
4 changes: 1 addition & 3 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn run(

let mut previous_time = Instant::now();

let mut input_handler = input::Handler::new(previous_time);
let mut input_handler = input::Handler::default();
let mut renderer = block_on(Renderer::new(&window))?;

let mut draw_config = DrawConfig::default();
Expand Down Expand Up @@ -182,7 +182,6 @@ pub fn run(
if let (Some(shape), Some(camera)) = (&shape, &mut camera) {
input_handler.update(
delta_t.as_secs_f64(),
now,
camera,
window.size(),
&shape.mesh,
Expand Down Expand Up @@ -213,7 +212,6 @@ pub fn run(
input_handler.handle_event(
event,
window.size(),
now,
&shape.mesh,
camera,
&mut actions,
Expand Down

0 comments on commit 5bbc69b

Please sign in to comment.