diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-23 22:38:12 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-23 22:38:12 +0200 |
commit | c846fe5e269a827b3c324fb66b75be3fabc56a57 (patch) | |
tree | b8204121ae095b62078e157afe1f2df0ec7290df /engine/src/renderer | |
parent | 386aad9dac7c22cabb0f1bbba33d248c40bb0310 (diff) |
feat(engine): add camera
Diffstat (limited to 'engine/src/renderer')
-rw-r--r-- | engine/src/renderer/mod.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index d577054..aa828fe 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -4,7 +4,7 @@ use std::process::abort; use cstr::cstr; use glfw::WindowSize; -use crate::matrix::Matrix; +use crate::camera::Camera; use crate::object::Object; use crate::opengl::buffer::{ ArrayKind as ArrayBufferKind, @@ -18,7 +18,7 @@ use crate::opengl::shader::Program as ShaderProgram; use crate::opengl::vertex_array::{PrimitiveKind, VertexArray}; use crate::opengl::{clear_buffers, BufferClearMask}; use crate::projection::new_perspective; -use crate::vector::{Vec2, Vec3}; +use crate::vector::Vec2; use crate::vertex::Vertex; pub fn initialize(window: &glfw::Window) -> Result<(), Error> @@ -104,6 +104,7 @@ fn opengl_debug_message_cb( pub fn render<'obj>( objects: impl IntoIterator<Item = &'obj Object>, window_size: &WindowSize, + camera: &Camera, ) { clear_buffers(BufferClearMask::COLOR); @@ -111,15 +112,7 @@ pub fn render<'obj>( for obj in objects { obj.renderable().shader_program.activate(); - let mut view = Matrix::new_identity(); - - view.translate(&Vec3 { - x: 0.0, - y: 0.0, - z: -3.0, - }); - - apply_transformation_matrices(obj, &view, window_size); + apply_transformation_matrices(obj, camera, window_size); obj.renderable().vertex_arr.bind(|vert_arr_curr_bound| { if let Some(index_info) = &obj.renderable().index_info { @@ -217,7 +210,7 @@ pub enum Error fn apply_transformation_matrices( object: &Object, - view: &Matrix<f32, 4, 4>, + camera: &Camera, window_size: &WindowSize, ) { @@ -226,10 +219,12 @@ fn apply_transformation_matrices( .shader_program .set_uniform_matrix_4fv(cstr!("model"), &object.transform().as_matrix()); + let view = camera.transform().as_matrix(); + object .renderable() .shader_program - .set_uniform_matrix_4fv(cstr!("view"), view); + .set_uniform_matrix_4fv(cstr!("view"), &view); #[allow(clippy::cast_precision_loss)] let projection = new_perspective( |