diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-27 20:51:26 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-27 20:51:59 +0100 |
commit | d3f8b55aa971d1ef00345e80bc40365927bf08e5 (patch) | |
tree | e540378ba74323f59c994daeb88e4f0d0c910fb4 /engine/src/lib.rs | |
parent | fe975af71dbb7c615a1e36920c6b8df3d41d1bdb (diff) |
feat(engine): add support for custom camera implementations
Diffstat (limited to 'engine/src/lib.rs')
-rw-r--r-- | engine/src/lib.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/engine/src/lib.rs b/engine/src/lib.rs index c4711f2..806d7ec 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -33,23 +33,29 @@ pub use glfw::window::Key; pub use glfw::WindowSize; #[derive(Debug)] -pub struct Engine +pub struct Engine<CameraT> { /// Objects have to be dropped before window. Otherwise, UB. objects: BTreeMap<ObjectId, Object>, light_source: Option<LightSource>, window: Window, - renderer: Renderer, + renderer: Renderer<CameraT>, delta_time: Duration, } -impl Engine +impl<CameraT> Engine<CameraT> +where + CameraT: Camera, { /// Creates and initializes a new engine. /// /// # Errors /// Will return `Err` if window creation or window configuration fails. - pub fn new(window_size: &WindowSize, window_title: &str) -> Result<Self, Error> + pub fn new( + window_size: &WindowSize, + window_title: &str, + camera: CameraT, + ) -> Result<Self, Error> { let window_builder = WindowBuilder::new(); @@ -66,10 +72,11 @@ impl Engine .map_err(Error::ConfigureWindowFailed)?; window.set_framebuffer_size_callback(move |new_window_size| { - Renderer::set_viewport(&Vec2::ZERO, &new_window_size); + Renderer::<CameraT>::set_viewport(&Vec2::ZERO, &new_window_size); }); - let renderer = Renderer::new(&window).map_err(Error::InitializeRendererFailed)?; + let renderer = + Renderer::new(&window, camera).map_err(Error::InitializeRendererFailed)?; Ok(Self { window, @@ -156,12 +163,12 @@ impl Engine } #[must_use] - pub fn camera(&self) -> &Camera + pub fn camera(&self) -> &CameraT { self.renderer.camera() } - pub fn camera_mut(&mut self) -> &mut Camera + pub fn camera_mut(&mut self) -> &mut CameraT { self.renderer.camera_mut() } |