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)]
|
#[derive(Default)]
|
||||||
pub struct Camera {
|
pub struct Camera3D {
|
||||||
projection: Mat4,
|
projection: Mat4,
|
||||||
|
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
rotation: Vec3,
|
rotation: Vec3,
|
||||||
|
aspect_ratio: f32,
|
||||||
|
fov: f32,
|
||||||
|
near: f32,
|
||||||
|
far: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Camera {
|
impl Camera3D {
|
||||||
pub fn new(projection: Mat4) -> Self {
|
pub fn new(aspect_ratio: f32, fov: f32, near: f32, far: f32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
projection,
|
projection: Mat4::perspective_rh(fov, aspect_ratio, near, far),
|
||||||
position: Vec3::ZERO,
|
position: Vec3::ZERO,
|
||||||
rotation: Vec3::ZERO,
|
rotation: Vec3::ZERO,
|
||||||
|
aspect_ratio,
|
||||||
|
fov,
|
||||||
|
near,
|
||||||
|
far,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +50,7 @@ impl Camera {
|
||||||
timer: &Timer,
|
timer: &Timer,
|
||||||
movement_speed: f32,
|
movement_speed: f32,
|
||||||
camera_sensitivity: f32,
|
camera_sensitivity: f32,
|
||||||
|
window_aspect_ratio: f32,
|
||||||
) {
|
) {
|
||||||
// Process camera rotation
|
// Process camera rotation
|
||||||
let camera_delta = camera_sensitivity * timer.delta_time();
|
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;
|
let tz = input_manager.get_virtual_input_state("move_forward") * movement_delta;
|
||||||
self.position += tz * forward;
|
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) {
|
pub fn set_projection(&mut self, projection: Mat4) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{error::Error, sync::Arc};
|
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::render::texture::Texture;
|
||||||
use crate::core::scene::Scene;
|
use crate::core::scene::Scene;
|
||||||
use crate::core::scene::SceneContext;
|
use crate::core::scene::SceneContext;
|
||||||
|
@ -21,7 +21,7 @@ use super::assets::square::Square;
|
||||||
|
|
||||||
pub struct MainSceneState {
|
pub struct MainSceneState {
|
||||||
square: Square,
|
square: Square,
|
||||||
camera: Camera,
|
camera: Camera3D,
|
||||||
texture: Texture,
|
texture: Texture,
|
||||||
speed: f32,
|
speed: f32,
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ impl Scene for MainScene {
|
||||||
scene_context.swapchain_format,
|
scene_context.swapchain_format,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let camera = Camera::new(Mat4::perspective_rh(
|
let camera = Camera3D::new(
|
||||||
std::f32::consts::FRAC_PI_2,
|
|
||||||
scene_context.aspect_ratio,
|
scene_context.aspect_ratio,
|
||||||
|
std::f32::consts::FRAC_PI_2,
|
||||||
0.01,
|
0.01,
|
||||||
1000.0,
|
1000.0,
|
||||||
));
|
);
|
||||||
|
|
||||||
let mut uploads = AutoCommandBufferBuilder::primary(
|
let mut uploads = AutoCommandBufferBuilder::primary(
|
||||||
scene_context.command_buffer_allocator.clone(),
|
scene_context.command_buffer_allocator.clone(),
|
||||||
|
@ -84,6 +84,7 @@ impl Scene for MainScene {
|
||||||
&scene_context.timer,
|
&scene_context.timer,
|
||||||
state.speed,
|
state.speed,
|
||||||
10.0,
|
10.0,
|
||||||
|
scene_context.aspect_ratio,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue