Format camera.rs
This commit is contained in:
parent
5c3dd5ebeb
commit
47ab9cae65
|
@ -1,7 +1,7 @@
|
|||
use glam::{Mat4, Quat, Vec2, Vec3};
|
||||
use std::f32::consts::LN_2;
|
||||
use std::time::Instant;
|
||||
use winit::event::{ElementState, VirtualKeyCode};
|
||||
use std::f32::consts::LN_2;
|
||||
|
||||
pub trait Camera {
|
||||
fn get_eye(&self) -> [f32; 4];
|
||||
|
@ -36,9 +36,9 @@ pub struct Flycam {
|
|||
|
||||
// constants
|
||||
// camera movement
|
||||
turn_sensitivity: f32, // coefficient for mouse_dx/dy -> euler_x/y
|
||||
thrust_mag: f32, // coefficient for thrust acceleration vector
|
||||
damping_coeff: f32, // coefficient for damping acceleration vector
|
||||
turn_sensitivity: f32, // coefficient for mouse_dx/dy -> euler_x/y
|
||||
thrust_mag: f32, // coefficient for thrust acceleration vector
|
||||
damping_coeff: f32, // coefficient for damping acceleration vector
|
||||
// camera frustum
|
||||
aspect: f32,
|
||||
fovy: f32,
|
||||
|
@ -133,8 +133,8 @@ impl Flycam {
|
|||
fn update_orientation(&mut self, dt: f32) {
|
||||
let t = self.turn_sensitivity;
|
||||
|
||||
self.euler_x -= t * self.mouse_dy; // mouse +y = 2D plane down = look down = 3d space -x
|
||||
self.euler_y -= t * self.mouse_dx; // mouse +x = 2D plane right = look to the right = 3d space -y
|
||||
self.euler_x -= t * self.mouse_dy; // mouse +y = 2D plane down = look down = 3d space -x
|
||||
self.euler_y -= t * self.mouse_dx; // mouse +x = 2D plane right = look to the right = 3d space -y
|
||||
|
||||
self.mouse_dx = 0.0;
|
||||
self.mouse_dy = 0.0;
|
||||
|
@ -165,10 +165,10 @@ impl Flycam {
|
|||
fn get_thrust_acc(&self) -> glam::Vec3 {
|
||||
let axis = Self::key_axis;
|
||||
|
||||
let thruster_cam_x = axis(self.is_left_pressed, self.is_right_pressed);
|
||||
let thruster_cam_y = axis(self.is_cam_down_pressed, self.is_cam_up_pressed);
|
||||
let thruster_cam_z = -axis(self.is_backward_pressed, self.is_forward_pressed); // forward is -z
|
||||
let thruster_world_y = axis(self.is_world_down_pressed, self.is_world_up_pressed);
|
||||
let thruster_cam_x = axis(self.is_left_pressed, self.is_right_pressed);
|
||||
let thruster_cam_y = axis(self.is_cam_down_pressed, self.is_cam_up_pressed);
|
||||
let thruster_cam_z = -axis(self.is_backward_pressed, self.is_forward_pressed); // forward is -z
|
||||
let thruster_world_y = axis(self.is_world_down_pressed, self.is_world_up_pressed);
|
||||
|
||||
let thrusters_cam = Vec3::new(thruster_cam_x, thruster_cam_y, thruster_cam_z);
|
||||
let thrusters_world = Vec3::new(0.0, thruster_world_y, 0.0);
|
||||
|
@ -190,15 +190,15 @@ impl Flycam {
|
|||
fn key_axis(negative: bool, positive: bool) -> f32 {
|
||||
if negative {
|
||||
if positive {
|
||||
0.0 // positive + negative cancel out
|
||||
0.0 // positive + negative cancel out
|
||||
} else {
|
||||
-1.0 // negative only
|
||||
-1.0 // negative only
|
||||
}
|
||||
} else {
|
||||
if positive {
|
||||
1.0 // positive only
|
||||
1.0 // positive only
|
||||
} else {
|
||||
0.0 // neutral
|
||||
0.0 // neutral
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue