From 15de1323504e3ae15a05438f98d20adbac568a0f Mon Sep 17 00:00:00 2001 From: XavierCS-dev Date: Mon, 11 Mar 2024 19:45:13 +0000 Subject: [PATCH] Update README and camera matrix --- README.md | 1 + src/engine/camera/camera.rs | 7 ++++++- src/main.rs | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0761d15..22e3170 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ - [ ] Hide main loop from user, or at least, make it easier to use - [ ] Event System - [ ] Provide a method to set a background image +- [ ] Fix camera stretching - [x] Further goals (0.2.0 release blockers) - [x] Implement Transformation2D diff --git a/src/engine/camera/camera.rs b/src/engine/camera/camera.rs index 2bac051..d405c66 100644 --- a/src/engine/camera/camera.rs +++ b/src/engine/camera/camera.rs @@ -25,7 +25,12 @@ impl Camera2D { let proj_mat = Matrix4::from_slice([ [1.0 / (aspect_ratio * (fov_rad / 2.0).tan()), 0.0, 0.0, 0.0], [0.0, 1.0 / ((fov_rad / 2.0).tan()), 0.0, 0.0], - [0.0, 0.0, far / (far - near), -(far * near) / (far - near)], + [ + 0.0, + 0.0, + 0.5 * far / (far - near), + -(far * near) / (far - near), + ], [0.0, 0.0, 0.0, 1.0], ]); let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { diff --git a/src/main.rs b/src/main.rs index dfb472b..98b5112 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use winit::{ fn main() { println!("Hello, world!"); - let (mut app, event_loop) = effect_engine::init_engine(PhysicalSize::new(800, 600), 90.0); + let (mut app, event_loop) = effect_engine::init_engine(PhysicalSize::new(800, 600), 45.0); let mut before = Instant::now(); let mut after = Instant::now(); let tex_id = TextureID("tree"); @@ -26,11 +26,12 @@ fn main() { .init_layer(layer_id, vec![tex, evil], PhysicalSize::new(32, 32)) .unwrap(); let position = Vector3::new(-0.5, -0.5, 0.0); - let ent = app.init_entity(position, evil_id, &mut layer); + let mut ent = app.init_entity(position, evil_id, &mut layer); let mut ent_good = app.init_entity(position, tex_id, &mut layer); EntitySystem2D::set_position(&mut ent_good, Vector3::new(0.0, 0.0, 0.0)); EntitySystem2D::set_rotation(&mut ent_good, 30.0); EntitySystem2D::set_scale(&mut ent_good, 0.25); + EntitySystem2D::set_scale(&mut ent, 0.5); let mut ents_owner = vec![ent, ent_good]; let mut ents = Vec::new(); for ent in ents_owner.iter() { @@ -40,7 +41,7 @@ fn main() { drop(ents); let mut layers = vec![layer]; let camera = app.camera_mut(); - Camera2DSystem::transform(camera, Vector3::new(-0.5, -0.5, 0.0)); + Camera2DSystem::transform(camera, Vector3::new(-1.0, -1.0, 0.0)); app.update_camera(); let mut rotation = 0.0;