diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-13 19:09:10 +0100 |
|---|---|---|
| committer | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-13 19:09:10 +0100 |
| commit | 3167ec992f1f81b2252a2db3642fff943c4f14bf (patch) | |
| tree | 8761e4f6eb0866ee41824289a59a4d22945d37fc /racer-tracer/src/camera.rs | |
| parent | 9d44f7ab04e6f6979e0eebc24f8fb439a23a3865 (diff) | |
| download | racer-tracer-3167ec992f1f81b2252a2db3642fff943c4f14bf.tar.gz racer-tracer-3167ec992f1f81b2252a2db3642fff943c4f14bf.tar.xz racer-tracer-3167ec992f1f81b2252a2db3642fff943c4f14bf.zip | |
✨ Add realtime preview
- 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.
Diffstat (limited to 'racer-tracer/src/camera.rs')
| -rw-r--r-- | racer-tracer/src/camera.rs | 18 |
1 files changed, 17 insertions, 1 deletions
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); + } } |
