Skip to content

Commit

Permalink
Make rotation work without a focus point
Browse files Browse the repository at this point in the history
Close #140
  • Loading branch information
hannobraun committed Apr 26, 2022
1 parent 18ec64d commit 75bc2c9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/fj-viewer/src/input/rotation.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
use nalgebra::{Rotation3, Translation, Vector};
use nalgebra::{Point, Rotation3, Translation, Vector};

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

pub struct Rotation {
active: bool,
focus_point: FocusPoint,
}

impl Rotation {
pub fn new() -> Self {
Self {
active: false,
focus_point: FocusPoint::none(),
}
}

pub fn start(&mut self, focus_point: FocusPoint) {
self.active = true;
self.focus_point = focus_point;
}

pub fn stop(&mut self) {
self.focus_point = FocusPoint::none();
self.active = false;
}

pub fn apply(&self, diff_x: f64, diff_y: f64, camera: &mut Camera) {
if let Some(focus_point) = self.focus_point.0 {
if self.active {
let rotate_around =
self.focus_point.0.unwrap_or_else(Point::origin);

let f = 0.005;

let angle_x = diff_y * f;
let angle_y = diff_x * f;

let trans = Translation::from(focus_point.coords);
let trans = Translation::from(rotate_around);

let rot_x = Rotation3::from_axis_angle(&Vector::x_axis(), angle_x);
let rot_y = Rotation3::from_axis_angle(&Vector::y_axis(), angle_y);
Expand Down

0 comments on commit 75bc2c9

Please sign in to comment.