From 3167ec992f1f81b2252a2db3642fff943c4f14bf Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Fri, 13 Jan 2023 19:09:10 +0100 Subject: =?UTF-8?q?=E2=9C=A8=20Add=20realtime=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Preview quality is crude but works good enough. - Add scaling to render function. This helps to make the preview faster because we can use the same result for several pixels. - You can move around the camera a bit with wasd, super basic. - Press R to start/stop rendering the scene. --- racer-tracer/src/camera.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'racer-tracer/src/camera.rs') diff --git a/racer-tracer/src/camera.rs b/racer-tracer/src/camera.rs index 2c7be12..45d2919 100644 --- a/racer-tracer/src/camera.rs +++ b/racer-tracer/src/camera.rs @@ -33,9 +33,25 @@ impl Camera { } pub fn get_ray(&self, u: f64, v: f64) -> Ray { + let upper_left_corner = self.origin + self.vertical / 2.0 + - self.horizontal / 2.0 + - Vec3::new(0.0, 0.0, self.focal_length); + Ray::new( self.origin, - self.upper_left_corner + u * self.horizontal - v * self.vertical - self.origin, + upper_left_corner + u * self.horizontal - v * self.vertical - self.origin, ) } + + // TODO: Add support for rotation + + // TODO: Use forward facing vector + pub fn go_forward(&mut self, go: f64) { + self.origin += Vec3::new(0.0, 0.0, go); + } + + // TODO: Use right facing vector + pub fn go_right(&mut self, go: f64) { + self.origin += Vec3::new(go, 0.0, 0.0); + } } -- cgit v1.2.3