Fix camera control with stick
This commit is contained in:
parent
ba0d30f6d6
commit
b773002bdd
1 changed files with 9 additions and 8 deletions
|
@ -10,6 +10,7 @@ pub struct CameraControl {
|
||||||
arc: Deg<f32>,
|
arc: Deg<f32>,
|
||||||
|
|
||||||
mouse_position: (u32, u32),
|
mouse_position: (u32, u32),
|
||||||
|
stick_direction: Vector2<f32>,
|
||||||
|
|
||||||
rotation_start: Deg<f32>,
|
rotation_start: Deg<f32>,
|
||||||
arc_start: Deg<f32>,
|
arc_start: Deg<f32>,
|
||||||
|
@ -32,6 +33,7 @@ impl CameraControl {
|
||||||
arc: Deg(50.0),
|
arc: Deg(50.0),
|
||||||
|
|
||||||
mouse_position: (0, 0),
|
mouse_position: (0, 0),
|
||||||
|
stick_direction: Vector2::zero(),
|
||||||
|
|
||||||
rotation_start: Deg(0.0),
|
rotation_start: Deg(0.0),
|
||||||
arc_start: Deg(0.0),
|
arc_start: Deg(0.0),
|
||||||
|
@ -81,15 +83,14 @@ impl CameraControl {
|
||||||
self.mouse_position_start = None;
|
self.mouse_position_start = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stick_movement(
|
pub fn stick_direction(&mut self, stick: Vector2<f32>) {
|
||||||
&mut self,
|
self.stick_direction = stick;
|
||||||
stick: Vector2<f32>,
|
}
|
||||||
factors: Vector2<f32>,
|
|
||||||
view: &mut View,
|
pub fn stick_movement(&mut self, factors: Vector2<f32>, view: &mut View) -> Result<()> {
|
||||||
) -> Result<()> {
|
self.rotation = Deg((self.rotation.0 + (self.stick_direction.x * factors.x)) % 360.0);
|
||||||
self.rotation = Deg((self.rotation.0 + (stick.x * factors.x)) % 360.0);
|
|
||||||
self.arc = Deg(clamp(
|
self.arc = Deg(clamp(
|
||||||
self.arc.0 - (stick.y * factors.y),
|
self.arc.0 - (self.stick_direction.y * factors.y),
|
||||||
CameraControl::MIN_PITCH,
|
CameraControl::MIN_PITCH,
|
||||||
CameraControl::MAX_PITCH,
|
CameraControl::MAX_PITCH,
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue