camera: Change camera to Camera3D
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m38s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m38s
This commit is contained in:
parent
3a562fb6eb
commit
f8b81f3269
2 changed files with 25 additions and 9 deletions
|
@ -20,19 +20,27 @@ const OPENGL_TO_VULKAN_Y_AXIS_FLIP: Mat4 = Mat4 {
|
|||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Camera {
|
||||
pub struct Camera3D {
|
||||
projection: Mat4,
|
||||
|
||||
position: Vec3,
|
||||
rotation: Vec3,
|
||||
aspect_ratio: f32,
|
||||
fov: f32,
|
||||
near: f32,
|
||||
far: f32,
|
||||
}
|
||||
|
||||
impl Camera {
|
||||
pub fn new(projection: Mat4) -> Self {
|
||||
impl Camera3D {
|
||||
pub fn new(aspect_ratio: f32, fov: f32, near: f32, far: f32) -> Self {
|
||||
Self {
|
||||
projection,
|
||||
projection: Mat4::perspective_rh(fov, aspect_ratio, near, far),
|
||||
position: Vec3::ZERO,
|
||||
rotation: Vec3::ZERO,
|
||||
aspect_ratio,
|
||||
fov,
|
||||
near,
|
||||
far,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +50,7 @@ impl Camera {
|
|||
timer: &Timer,
|
||||
movement_speed: f32,
|
||||
camera_sensitivity: f32,
|
||||
window_aspect_ratio: f32,
|
||||
) {
|
||||
// Process camera rotation
|
||||
let camera_delta = camera_sensitivity * timer.delta_time();
|
||||
|
@ -70,6 +79,12 @@ impl Camera {
|
|||
|
||||
let tz = input_manager.get_virtual_input_state("move_forward") * movement_delta;
|
||||
self.position += tz * forward;
|
||||
|
||||
if self.aspect_ratio != window_aspect_ratio {
|
||||
self.aspect_ratio = window_aspect_ratio;
|
||||
self.projection =
|
||||
Mat4::perspective_rh(self.fov, self.aspect_ratio, self.near, self.far);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_projection(&mut self, projection: Mat4) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{error::Error, sync::Arc};
|
||||
|
||||
use crate::core::render::primitives::camera::Camera;
|
||||
use crate::core::render::primitives::camera::Camera3D;
|
||||
use crate::core::render::texture::Texture;
|
||||
use crate::core::scene::Scene;
|
||||
use crate::core::scene::SceneContext;
|
||||
|
@ -21,7 +21,7 @@ use super::assets::square::Square;
|
|||
|
||||
pub struct MainSceneState {
|
||||
square: Square,
|
||||
camera: Camera,
|
||||
camera: Camera3D,
|
||||
texture: Texture,
|
||||
speed: f32,
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ impl Scene for MainScene {
|
|||
scene_context.swapchain_format,
|
||||
)?;
|
||||
|
||||
let camera = Camera::new(Mat4::perspective_rh(
|
||||
std::f32::consts::FRAC_PI_2,
|
||||
let camera = Camera3D::new(
|
||||
scene_context.aspect_ratio,
|
||||
std::f32::consts::FRAC_PI_2,
|
||||
0.01,
|
||||
1000.0,
|
||||
));
|
||||
);
|
||||
|
||||
let mut uploads = AutoCommandBufferBuilder::primary(
|
||||
scene_context.command_buffer_allocator.clone(),
|
||||
|
@ -84,6 +84,7 @@ impl Scene for MainScene {
|
|||
&scene_context.timer,
|
||||
state.speed,
|
||||
10.0,
|
||||
scene_context.aspect_ratio,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue