Bam! Camera movement, pure jank implementation but on the right track
This commit is contained in:
@@ -3,6 +3,7 @@ use winit::event::{MouseScrollDelta, VirtualKeyCode, ElementState};
|
||||
use winit::dpi::{PhysicalPosition, LogicalPosition};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::f32::consts::FRAC_PI_2;
|
||||
use crate::render::OPENGL_TO_WGPU_MATRIX;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Camera {
|
||||
@@ -28,8 +29,8 @@ impl Camera {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calc_matrix(&self) -> Matrix4<f32> {
|
||||
Matrix4::look_at_dir(
|
||||
pub fn calc_matrix(&self, projection: cgmath::Matrix4<f32>) -> Matrix4<f32> {
|
||||
let mx_view = Matrix4::look_at_dir(
|
||||
self.position,
|
||||
Vector3::new(
|
||||
self.yaw.0.cos(),
|
||||
@@ -37,7 +38,9 @@ impl Camera {
|
||||
self.yaw.0.sin(),
|
||||
).normalize(),
|
||||
Vector3::unit_y(),
|
||||
)
|
||||
);
|
||||
let mx_correction = OPENGL_TO_WGPU_MATRIX;
|
||||
mx_correction * projection * mx_view
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +126,7 @@ impl CameraController {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_camera(&mut self, camera: &mut Camera, dt: Duration) {
|
||||
|
||||
|
||||
let dt = dt.as_secs_f32();
|
||||
pub fn update_camera(&mut self, camera: &mut Camera, dt: f32) {
|
||||
|
||||
// Move forward/backward and left/right
|
||||
let (yaw_sin, yaw_cos) = camera.yaw.0.sin_cos();
|
||||
|
||||
Reference in New Issue
Block a user