Update the camera correctly each frame

This commit is contained in:
Jarrod Doyle 2024-05-12 09:50:33 +01:00
parent e030ee7179
commit 56e756d818
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,8 @@
mod camera;
mod renderer;
use std::time::Instant;
use anyhow::Result;
use crawl::winit::event::{Event, WindowEvent};
use renderer::VoxelRenderer;
@ -39,6 +41,7 @@ fn main() -> Result<()> {
let renderer = VoxelRenderer::new(&context, &camera_controller)?;
let passes: Vec<Box<dyn crawl::Pass>> = vec![Box::new(renderer)];
let mut last_render_time = Instant::now();
event_loop.run(|event, elwt| match event {
Event::WindowEvent { window_id, event } if window_id == context.window.id() => {
if context.handle_window_event(&event, elwt) {
@ -50,6 +53,13 @@ fn main() -> Result<()> {
}
if let WindowEvent::RedrawRequested = event {
let now = Instant::now();
let dt = now - last_render_time;
last_render_time = now;
camera_controller.update(dt);
camera_controller.update_buffer(&context);
if let Err(err) = context.render(passes.as_slice()) {
log::error!("{err:?}");
}