diff --git a/core/src/render/cam.rs b/core/src/render/cam.rs index d202991e..9dfe6931 100644 --- a/core/src/render/cam.rs +++ b/core/src/render/cam.rs @@ -63,25 +63,23 @@ pub struct FirstPerson { // Inherent impls // -impl Camera { +impl Camera<()> { /// Creates a camera with the given resolution. - pub fn new(res_x: u32, res_y: u32) -> Self - where - M: Default, - { - Self::with_mode(res_x, res_y, M::default()) - } - - /// Creates a camera with the given resolution and mode. - pub fn with_mode(res_x: u32, res_y: u32, mode: M) -> Self { + pub fn new(res_x: u32, res_y: u32) -> Self { Self { res: (res_x, res_y), - mode, - project: Default::default(), viewport: viewport(vec2(0, 0)..vec2(res_x, res_y)), + ..Default::default() } } + pub fn mode(self, mode: M) -> Camera { + let Self { res, project, viewport, .. } = self; + Camera { mode, res, project, viewport } + } +} + +impl Camera { /// Sets the viewport bounds of this camera. pub fn viewport(self, bounds: impl Into>) -> Self { let (w, h) = self.res; @@ -119,7 +117,9 @@ impl Camera { ..self } } +} +impl Camera { /// Renders the given geometry from the viewpoint of this camera. pub fn render( &self, diff --git a/demos/src/bin/crates.rs b/demos/src/bin/crates.rs index a6d5efbb..61e56314 100644 --- a/demos/src/bin/crates.rs +++ b/demos/src/bin/crates.rs @@ -36,7 +36,8 @@ fn main() { }, ); - let mut cam = Camera::::new(W, H) + let mut cam = Camera::new(W, H) + .mode(FirstPerson::default()) .viewport((10..W - 10, 10..H - 10)) .perspective(1.0, 0.1..1000.0); diff --git a/demos/src/bin/solids.rs b/demos/src/bin/solids.rs index baf9c504..a3789cb4 100644 --- a/demos/src/bin/solids.rs +++ b/demos/src/bin/solids.rs @@ -144,7 +144,8 @@ fn main() { bunny, ]; - let camera = Camera::with_mode(W, H, scale(vec3(1.0, -1.0, -1.0)).to()) + let cam = Camera::new(W, H) + .mode(scale(vec3(1.0, -1.0, -1.0)).to()) .perspective(1.5, 0.1..1000.0) .viewport(vec2(10, 10)..vec2(W - 10, H - 10)); @@ -170,7 +171,7 @@ fn main() { } let obj = &objs[carousel.idx % objs.len()]; - camera.render( + cam.render( &obj.faces, &obj.verts, &model_to_world, @@ -179,7 +180,6 @@ fn main() { &mut frame.buf, &frame.ctx, ); - Continue(()) }); }