diff --git a/Cargo.lock b/Cargo.lock index 4ba98f86..58fc3bb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1669,6 +1669,7 @@ dependencies = [ "eframe", "egui", "kdtree", + "nalgebra", "rand", "scene", "tracing 1.0.0", diff --git a/pathtracer-gui/Cargo.toml b/pathtracer-gui/Cargo.toml index 1f491420..af261ba2 100644 --- a/pathtracer-gui/Cargo.toml +++ b/pathtracer-gui/Cargo.toml @@ -8,6 +8,7 @@ clap = { version = "4.5.4", features = ["derive"] } eframe = { version = "0.27.2", default-features = false, features = ["default_fonts", "x11", "glow"] } egui = "0.27.2" kdtree = { version = "1.0.0", path = "../kdtree" } +nalgebra = { version = "0.32.5", default-features = false } rand = { version = "0.8.5", default-features = false, features = ["std", "small_rng"] } scene = { version = "1.0.0", path = "../scene" } tracing = { version = "1.0.0", path = "../tracing" } diff --git a/pathtracer-gui/src/main.rs b/pathtracer-gui/src/main.rs index dd0cf080..a6512e79 100644 --- a/pathtracer-gui/src/main.rs +++ b/pathtracer-gui/src/main.rs @@ -1,6 +1,8 @@ use clap::Parser; use eframe::egui; +use egui::Vec2; use kdtree::{build::build_kdtree, build_sah::SahKdTreeBuilder}; +use nalgebra::Vector3; use scene::Scene; use std::{str, sync::Arc}; use tracing::pathtracer::Pathtracer; @@ -24,6 +26,7 @@ struct Args { } struct PathtracerGui { + size: Vec2, last_meta: Option, texture: Option, workers: Workers, @@ -32,6 +35,7 @@ struct PathtracerGui { impl PathtracerGui { fn new(workers: Workers) -> Self { Self { + size: Vec2::new(512.0, 512.0), last_meta: None, texture: None, workers, @@ -56,10 +60,27 @@ impl eframe::App for PathtracerGui { } }); + let mut translation = Vector3::zeros(); + if ui.input(|i| i.key_pressed(egui::Key::ArrowUp)) { + translation.y = 0.1; + } + if ui.input(|i| i.key_pressed(egui::Key::ArrowDown)) { + translation.y = -0.1; + } + if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft)) { + translation.x = -0.1; + } + if ui.input(|i| i.key_pressed(egui::Key::ArrowRight)) { + translation.x = 0.1; + } + if resize { - let width = ui.available_size().x as u32; - let height = ui.available_size().y as u32; - self.workers.send(width, height); + self.size = ui.available_size(); + } + + if resize || translation != Vector3::zeros() { + self.workers + .send(self.size.x as u32, self.size.y as u32, translation); } if let Some(texture) = &self.texture { diff --git a/pathtracer-gui/src/workers.rs b/pathtracer-gui/src/workers.rs index 382d41b4..6b1e962a 100644 --- a/pathtracer-gui/src/workers.rs +++ b/pathtracer-gui/src/workers.rs @@ -7,6 +7,7 @@ use std::{ time, }; +use nalgebra::Vector3; use rand::{rngs::SmallRng, SeedableRng}; use scene::camera::{Camera, Pinhole}; use tracing::{image_buffer::ImageBuffer, pathtracer::Pathtracer, raylogger::RayLogger}; @@ -100,7 +101,8 @@ impl Workers { } } - pub fn send(&self, width: u32, height: u32) { + pub fn send(&mut self, width: u32, height: u32, translation: Vector3) { + self.camera = self.camera.translate(&translation); self.settings .as_ref() .unwrap() diff --git a/scene/src/camera.rs b/scene/src/camera.rs index 0b2f297c..377a9848 100644 --- a/scene/src/camera.rs +++ b/scene/src/camera.rs @@ -26,6 +26,16 @@ impl Camera { fov_degrees, } } + + pub fn translate(&self, v: &Vector3) -> Self { + Camera { + position: self.position + v, + direction: self.direction, + up: self.up, + right: self.right, + fov_degrees: self.fov_degrees, + } + } } #[derive(Clone, Debug)]