mirror of
https://github.com/hannobraun/Fornjot
synced 2025-08-26 12:06:34 +00:00
Simplify
This commit is contained in:
parent
fde836bc7d
commit
c12e7dfd5e
@ -1,4 +1,4 @@
|
||||
use super::{movement::Movement, rotation::Rotation, zoom::Zoom, InputEvent};
|
||||
use super::{movement, rotation::Rotation, zoom::Zoom, InputEvent};
|
||||
use crate::camera::{Camera, FocusPoint};
|
||||
|
||||
/// Input handling abstraction
|
||||
@ -16,7 +16,7 @@ impl InputHandler {
|
||||
) {
|
||||
match event {
|
||||
InputEvent::Translation { previous, current } => {
|
||||
Movement::apply(previous, current, focus_point, camera);
|
||||
movement::apply(previous, current, focus_point, camera);
|
||||
}
|
||||
InputEvent::Rotation { angle_x, angle_y } => {
|
||||
Rotation::apply(angle_x, angle_y, focus_point, camera);
|
||||
|
@ -5,29 +5,25 @@ use crate::{
|
||||
screen::NormalizedScreenPosition,
|
||||
};
|
||||
|
||||
pub struct Movement;
|
||||
pub fn apply(
|
||||
previous: NormalizedScreenPosition,
|
||||
current: NormalizedScreenPosition,
|
||||
focus_point: FocusPoint,
|
||||
camera: &mut Camera,
|
||||
) {
|
||||
let previous = camera.cursor_to_model_space(previous);
|
||||
let cursor = camera.cursor_to_model_space(current);
|
||||
|
||||
impl Movement {
|
||||
pub fn apply(
|
||||
previous: NormalizedScreenPosition,
|
||||
current: NormalizedScreenPosition,
|
||||
focus_point: FocusPoint,
|
||||
camera: &mut Camera,
|
||||
) {
|
||||
let previous = camera.cursor_to_model_space(previous);
|
||||
let cursor = camera.cursor_to_model_space(current);
|
||||
let d1 = Point::distance_to(&camera.position(), &cursor);
|
||||
let d2 = Point::distance_to(&camera.position(), &focus_point.0);
|
||||
|
||||
let d1 = Point::distance_to(&camera.position(), &cursor);
|
||||
let d2 = Point::distance_to(&camera.position(), &focus_point.0);
|
||||
let diff = (cursor - previous) * d2 / d1;
|
||||
let offset = camera.camera_to_model().transform_vector(&diff);
|
||||
|
||||
let diff = (cursor - previous) * d2 / d1;
|
||||
let offset = camera.camera_to_model().transform_vector(&diff);
|
||||
|
||||
camera.translation = camera.translation
|
||||
* Transform::translation(Vector::from([
|
||||
offset.x,
|
||||
offset.y,
|
||||
Scalar::ZERO,
|
||||
]));
|
||||
}
|
||||
camera.translation = camera.translation
|
||||
* Transform::translation(Vector::from([
|
||||
offset.x,
|
||||
offset.y,
|
||||
Scalar::ZERO,
|
||||
]));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user