diff --git a/src/bin/flat/ifaces.rs b/src/bin/flat/ifaces.rs new file mode 100644 index 0000000..d28be75 --- /dev/null +++ b/src/bin/flat/ifaces.rs @@ -0,0 +1,29 @@ +use crate::types::{Hit, Location, Ray}; +use glam::Vec2; + +pub trait Traceable { + /// Traces a ray from a given starting point. `ray` is relative to the camera. + /// + /// Returns all objects the ray touched. `Hit::distance` is along the ray; it may be a rough estimate except, when two objects overlap the difference of corresponding `distance`s shall be correct. + fn trace(&self, camera: Location, ray: Ray) -> Vec; +} + +pub trait OptimizedTraceable: Traceable { + type State; + + /// Prepares tracing from a given starting point. `ray` is relative to the camera. + fn init(&self, camera: Location, ray: Ray) -> Self::State; + + /// Similar to [`Traceable::trace`] but allows stopping early. + fn trace(&self, state: Self::State) -> (Option, Vec); +} + +pub struct RayPath { + pub points: Vec, + pub end_dir: Vec2, +} + +pub trait DebugTraceable: Traceable { + /// Identical to [`Traceable::trace`], except also returns the ray path. + fn trace_dbg(&self, camera: Location, ray: Ray) -> (Vec, RayPath); +} diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index 235fa50..26cac12 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -14,6 +14,7 @@ use types::{Location, Object, Ray}; mod float_fun; mod fns; +mod ifaces; mod riemann; mod tube; mod types;