|
|
|
@ -28,6 +28,7 @@ pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
|
|
|
|
|
|
|
|
|
|
const NUM_INSTANCES_PER_ROW: u32 = 10;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct Camera {
|
|
|
|
|
eye: cgmath::Point3<f32>,
|
|
|
|
|
target: cgmath::Point3<f32>,
|
|
|
|
@ -47,7 +48,7 @@ impl Camera {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
|
|
|
|
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
|
|
|
|
struct CameraUniform {
|
|
|
|
|
view_proj: [[f32; 4]; 4],
|
|
|
|
|
}
|
|
|
|
@ -506,10 +507,10 @@ impl<'a> State<'a> {
|
|
|
|
|
|
|
|
|
|
fn resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) {
|
|
|
|
|
if new_size.width > 0 && new_size.height > 0 {
|
|
|
|
|
self.camera.aspect = self.config.width as f32 / self.config.height as f32;
|
|
|
|
|
self.size = new_size;
|
|
|
|
|
self.config.width = new_size.width;
|
|
|
|
|
self.config.height = new_size.height;
|
|
|
|
|
self.size = new_size;
|
|
|
|
|
self.camera.aspect = self.config.width as f32 / self.config.height as f32;
|
|
|
|
|
self.surface.configure(&self.device, &self.config);
|
|
|
|
|
self.depth_texture =
|
|
|
|
|
texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture");
|
|
|
|
@ -521,7 +522,9 @@ impl<'a> State<'a> {
|
|
|
|
|
|
|
|
|
|
fn update(&mut self) {
|
|
|
|
|
self.camera_controller.update_camera(&mut self.camera);
|
|
|
|
|
log::info!("{:?}", self.camera);
|
|
|
|
|
self.camera_uniform.update_view_proj(&self.camera);
|
|
|
|
|
log::info!("{:?}", self.camera_uniform);
|
|
|
|
|
self.queue.write_buffer(
|
|
|
|
|
&self.camera_buffer,
|
|
|
|
|
0,
|
|
|
|
@ -624,6 +627,7 @@ pub async fn run() {
|
|
|
|
|
|
|
|
|
|
// State::new uses async code, so we're going to wait for it to finish
|
|
|
|
|
let mut state = State::new(&window).await;
|
|
|
|
|
let mut surface_configured = false;
|
|
|
|
|
|
|
|
|
|
event_loop
|
|
|
|
|
.run(move |event, control_flow| {
|
|
|
|
@ -645,11 +649,17 @@ pub async fn run() {
|
|
|
|
|
..
|
|
|
|
|
} => control_flow.exit(),
|
|
|
|
|
WindowEvent::Resized(physical_size) => {
|
|
|
|
|
surface_configured = true;
|
|
|
|
|
state.resize(*physical_size);
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::RedrawRequested => {
|
|
|
|
|
// This tells winit that we want another frame after this one
|
|
|
|
|
state.window().request_redraw();
|
|
|
|
|
|
|
|
|
|
if !surface_configured {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.update();
|
|
|
|
|
match state.render() {
|
|
|
|
|
Ok(_) => {}
|
|
|
|
|