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/image.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/image.rs')
| -rw-r--r-- | racer-tracer/src/image.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/racer-tracer/src/image.rs b/racer-tracer/src/image.rs index 48e81ee..502a15a 100644 --- a/racer-tracer/src/image.rs +++ b/racer-tracer/src/image.rs @@ -15,3 +15,82 @@ impl Image { } } } + +// TODO: SubImage and Image can probably be the same struct +impl From<&Image> for SubImage { + fn from(image: &Image) -> Self { + SubImage { + x: 0, + y: 0, + width: image.width, + height: image.height, + samples: image.samples_per_pixel, + screen_width: image.width, + screen_height: image.height, + } + } +} + +pub struct SubImage { + pub x: usize, + pub y: usize, + pub screen_width: usize, + pub screen_height: usize, + pub width: usize, + pub height: usize, + pub samples: usize, +} + +pub trait QuadSplit { + fn quad_split(&self) -> [SubImage; 4]; +} + +impl QuadSplit for SubImage { + fn quad_split(&self) -> [SubImage; 4] { + let half_w = self.width / 2; + let half_h = self.height / 2; + + [ + // Top Left + SubImage { + x: self.x, + y: self.y, + width: half_w, + height: half_h, + samples: self.samples, + screen_width: self.screen_width, + screen_height: self.screen_height, + }, + // Top Right + SubImage { + x: self.x + half_w, + y: self.y, + width: half_w, + height: half_h, + samples: self.samples, + screen_width: self.screen_width, + screen_height: self.screen_height, + }, + // Bottom Left + SubImage { + x: self.x, + y: self.y + half_h, + width: half_w, + height: half_h, + samples: self.samples, + screen_width: self.screen_width, + screen_height: self.screen_height, + }, + // Bottom Right + SubImage { + x: self.x + half_w, + y: self.y + half_h, + width: half_w, + height: half_h, + samples: self.samples, + screen_width: self.screen_width, + screen_height: self.screen_height, + }, + ] + } +} |
