Movement limits
parent
ceeeb6e268
commit
5afea588bb
|
@ -1,7 +1,6 @@
|
||||||
use cgmath::Point3;
|
|
||||||
use winit::event::{MouseButton, MouseScrollDelta, WindowEvent};
|
use winit::event::{MouseButton, MouseScrollDelta, WindowEvent};
|
||||||
|
|
||||||
use crate::camera::{Camera, DEFAULT_CAMERA_ZOOM};
|
use crate::camera::Camera;
|
||||||
|
|
||||||
const MAX_ZOOM_LEVEL: f32 = 15.0;
|
const MAX_ZOOM_LEVEL: f32 = 15.0;
|
||||||
|
|
||||||
|
@ -11,6 +10,7 @@ pub struct CameraController {
|
||||||
cursor_start: (f32, f32),
|
cursor_start: (f32, f32),
|
||||||
movement: (f32, f32),
|
movement: (f32, f32),
|
||||||
is_moving: bool,
|
is_moving: bool,
|
||||||
|
movement_level: (f32, f32),
|
||||||
zoom_level: f32,
|
zoom_level: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ impl CameraController {
|
||||||
cursor_start: (0.0, 0.0),
|
cursor_start: (0.0, 0.0),
|
||||||
movement: (0.0, 0.0),
|
movement: (0.0, 0.0),
|
||||||
is_moving: false,
|
is_moving: false,
|
||||||
|
movement_level: (0.0, 0.0),
|
||||||
zoom_level: 1.0,
|
zoom_level: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +45,7 @@ impl CameraController {
|
||||||
self.cursor_start = (position.x as f32, position.y as f32);
|
self.cursor_start = (position.x as f32, position.y as f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.movement = match self.is_moving {
|
let (x, y) = match self.is_moving {
|
||||||
true => {
|
true => {
|
||||||
let x = -self.cursor_start.0 + position.x as f32;
|
let x = -self.cursor_start.0 + position.x as f32;
|
||||||
let x = x * 0.000001;
|
let x = x * 0.000001;
|
||||||
|
@ -69,6 +70,8 @@ impl CameraController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.movement = (x, y);
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
WindowEvent::MouseWheel { delta, .. } => match delta {
|
WindowEvent::MouseWheel { delta, .. } => match delta {
|
||||||
|
@ -99,11 +102,21 @@ impl CameraController {
|
||||||
camera.eye -= forward_norm * self.speed;
|
camera.eye -= forward_norm * self.speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
camera.eye.x += self.movement.0;
|
self.movement_level.0 += self.movement.0;
|
||||||
camera.eye.y += self.movement.1;
|
self.movement_level.1 += self.movement.1;
|
||||||
|
|
||||||
|
if self.movement_level.0 > -1.0 && self.movement_level.0 < 1.0 {
|
||||||
|
camera.eye.x += self.movement.0;
|
||||||
camera.target.x += self.movement.0;
|
camera.target.x += self.movement.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.movement_level.1 > -1.0 && self.movement_level.1 < 1.0 {
|
||||||
|
camera.eye.y += self.movement.1;
|
||||||
camera.target.y += self.movement.1;
|
camera.target.y += self.movement.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.movement_level.0 = self.movement_level.0.clamp(-1.0, 1.0);
|
||||||
|
self.movement_level.1 = self.movement_level.1.clamp(-1.0, 1.0);
|
||||||
|
|
||||||
self.forward = 0.0;
|
self.forward = 0.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,7 @@ use pollster::FutureExt;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{ElementState, WindowEvent},
|
event::{ElementState, WindowEvent},
|
||||||
keyboard::{Key, KeyCode, NamedKey},
|
keyboard::Key,
|
||||||
platform::modifier_supplement::KeyEventExtModifierSupplement,
|
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue