Update the camera correctly each frame
This commit is contained in:
parent
e030ee7179
commit
56e756d818
10
src/main.rs
10
src/main.rs
|
@ -1,6 +1,8 @@
|
||||||
mod camera;
|
mod camera;
|
||||||
mod renderer;
|
mod renderer;
|
||||||
|
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crawl::winit::event::{Event, WindowEvent};
|
use crawl::winit::event::{Event, WindowEvent};
|
||||||
use renderer::VoxelRenderer;
|
use renderer::VoxelRenderer;
|
||||||
|
@ -39,6 +41,7 @@ fn main() -> Result<()> {
|
||||||
let renderer = VoxelRenderer::new(&context, &camera_controller)?;
|
let renderer = VoxelRenderer::new(&context, &camera_controller)?;
|
||||||
let passes: Vec<Box<dyn crawl::Pass>> = vec![Box::new(renderer)];
|
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_loop.run(|event, elwt| match event {
|
||||||
Event::WindowEvent { window_id, event } if window_id == context.window.id() => {
|
Event::WindowEvent { window_id, event } if window_id == context.window.id() => {
|
||||||
if context.handle_window_event(&event, elwt) {
|
if context.handle_window_event(&event, elwt) {
|
||||||
|
@ -50,6 +53,13 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let WindowEvent::RedrawRequested = event {
|
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()) {
|
if let Err(err) = context.render(passes.as_slice()) {
|
||||||
log::error!("{err:?}");
|
log::error!("{err:?}");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue