camera: fix camera movement
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m11s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m11s
This commit is contained in:
parent
f835941432
commit
998aa68da1
10 changed files with 83 additions and 103 deletions
|
@ -5,7 +5,7 @@ use crate::core::render::texture::Texture;
|
|||
use crate::core::scene::Scene;
|
||||
use crate::core::scene::SceneContext;
|
||||
use egui_winit_vulkano::{Gui, egui};
|
||||
use glam::{Mat4, Vec3};
|
||||
use glam::Mat4;
|
||||
use vulkano::{
|
||||
command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryCommandBufferAbstract,
|
||||
|
@ -36,48 +36,36 @@ impl Scene for MainScene {
|
|||
self.state.is_some()
|
||||
}
|
||||
|
||||
fn load(&mut self, scene_context: &SceneContext) {
|
||||
fn load(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>> {
|
||||
let square = Square::new(
|
||||
&scene_context.device,
|
||||
&scene_context.memory_allocator,
|
||||
scene_context.swapchain_format,
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
let camera = Camera::new(
|
||||
Mat4::look_at_rh(
|
||||
Vec3::new(0.3, 0.3, 1.0),
|
||||
Vec3::new(0.0, 0.0, 0.0),
|
||||
Vec3::new(0.0, -1.0, 0.0),
|
||||
),
|
||||
Mat4::perspective_rh_gl(
|
||||
std::f32::consts::FRAC_PI_2,
|
||||
scene_context.aspect_ratio,
|
||||
0.01,
|
||||
100.0,
|
||||
),
|
||||
);
|
||||
let camera = Camera::new(Mat4::perspective_rh_gl(
|
||||
std::f32::consts::FRAC_PI_2,
|
||||
scene_context.aspect_ratio,
|
||||
0.01,
|
||||
1000.0,
|
||||
));
|
||||
|
||||
let mut uploads = AutoCommandBufferBuilder::primary(
|
||||
scene_context.command_buffer_allocator.clone(),
|
||||
scene_context.graphics_queue.queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
let texture = Texture::from_file(
|
||||
&scene_context.device,
|
||||
&scene_context.memory_allocator,
|
||||
&mut uploads,
|
||||
"res/textures/wooden-crate.jpg",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
let _ = uploads
|
||||
.build()
|
||||
.unwrap()
|
||||
.execute(scene_context.graphics_queue.clone())
|
||||
.unwrap();
|
||||
.build()?
|
||||
.execute(scene_context.graphics_queue.clone())?;
|
||||
|
||||
self.state = Some(MainSceneState {
|
||||
square,
|
||||
|
@ -85,10 +73,12 @@ impl Scene for MainScene {
|
|||
texture,
|
||||
speed: 50.0,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, scene_context: &SceneContext) {
|
||||
let state = self.state.as_mut().unwrap();
|
||||
fn update(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>> {
|
||||
let state = self.state.as_mut().ok_or("State not found")?;
|
||||
state.camera.update(
|
||||
&scene_context.input_manager,
|
||||
&scene_context.timer,
|
||||
|
@ -96,12 +86,7 @@ impl Scene for MainScene {
|
|||
10.0,
|
||||
);
|
||||
|
||||
state.camera.set_projection(Mat4::perspective_rh_gl(
|
||||
std::f32::consts::FRAC_PI_2,
|
||||
scene_context.aspect_ratio,
|
||||
0.01,
|
||||
100.0,
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(
|
||||
|
@ -111,7 +96,7 @@ impl Scene for MainScene {
|
|||
scene_context: &SceneContext,
|
||||
gui: &mut Gui,
|
||||
) -> Result<Box<dyn GpuFuture>, Box<dyn Error>> {
|
||||
let state = self.state.as_ref().unwrap();
|
||||
let state = self.state.as_ref().ok_or("State not found")?;
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
scene_context.command_buffer_allocator.clone(),
|
||||
|
@ -174,6 +159,12 @@ impl Scene for MainScene {
|
|||
"Delta time: {:?}",
|
||||
scene_context.timer.delta_time()
|
||||
));
|
||||
|
||||
ui.label(format!(
|
||||
"Position: {:?}, Rotation: {:?}",
|
||||
state.camera.get_position(),
|
||||
state.camera.get_rotation()
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue