From 60f6a0b7783d6d3684f22f8def3c1097963aa3ff Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 17 Aug 2024 13:43:45 +0200 Subject: refactor(engine): remove position field from Camera component --- engine/src/renderer/opengl.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'engine/src/renderer/opengl.rs') diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index 5c7435c..a90c069 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -115,20 +115,16 @@ fn render( query: Query>>, point_light_query: Query<(PointLight,)>, directional_lights: Query<(DirectionalLight,)>, - camera_query: Query<(Camera,)>, + camera_query: Query<(Camera, Position)>, window: Single, global_light: Single, mut gl_objects: Local, mut actions: Actions, ) { - let Some(camera) = camera_query.iter().find_map(|(camera,)| { - if !camera.current { - return None; - } - - Some(camera) - }) else { + let Some((camera, camera_pos)) = + camera_query.iter().find(|(camera, _)| camera.current) + else { #[cfg(feature = "debug")] tracing::warn!("No current camera. Nothing will be rendered"); return; @@ -196,6 +192,7 @@ fn render( }, shader_program, &camera, + &camera_pos, window.size().expect("Failed to get window size"), ); @@ -210,7 +207,7 @@ fn render( .map(|(dir_light,)| &**dir_light) .collect::>() .as_slice(), - &camera, + &camera_pos, ); for texture in &material.textures { @@ -430,6 +427,7 @@ fn apply_transformation_matrices( transformation: Transformation, gl_shader_program: &mut GlShaderProgram, camera: &Camera, + camera_pos: &Position, window_size: Dimens, ) { @@ -438,7 +436,7 @@ fn apply_transformation_matrices( &create_transformation_matrix(transformation), ); - let view = create_view(camera); + let view = create_view(camera, camera_pos); gl_shader_program.set_uniform_matrix_4fv(cstr!("view"), &view); @@ -460,7 +458,7 @@ fn apply_light( gl_shader_program: &mut GlShaderProgram, point_lights: &[PointLightHolder], directional_lights: &[&DirectionalLight], - camera: &Camera, + camera_pos: &Position, ) where PointLightHolder: Deref, { @@ -559,7 +557,7 @@ fn apply_light( gl_shader_program.set_uniform_1fv(cstr!("material.shininess"), material.shininess); - gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera.position); + gl_shader_program.set_uniform_vec_3fv(cstr!("view_pos"), &camera_pos.position); } fn set_light_attenuation_uniforms( @@ -656,11 +654,11 @@ fn create_light_uniform_name( } } -fn create_view(camera: &Camera) -> Matrix +fn create_view(camera: &Camera, camera_pos: &Position) -> Matrix { let mut view = Matrix::new(); - view.look_at(&camera.position, &camera.target, &camera.global_up); + view.look_at(&camera_pos.position, &camera.target, &camera.global_up); view } -- cgit v1.2.3-18-g5258