From 899f81eed6c221dce22333ad03704b12d7634a54 Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Sun, 8 Jan 2023 17:51:44 +0100 Subject: =?UTF-8?q?=F0=9F=8C=8D=20Add=20Geometry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created a trait for all geometry that has to implement a hit function. Depending on if the ray hits or not it returns an option with the color. - Add support for multiple samples per pixel Current issues: - Using cooperative multitasking which isn't that helpful in this situation since it's like running without async but without overhead. Should switch to rayon. - All data gets copied once per job. Will decide later what to do (copy or put locks and share data between jobs). --- racer-tracer/src/util.rs | 57 ++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) (limited to 'racer-tracer/src/util.rs') diff --git a/racer-tracer/src/util.rs b/racer-tracer/src/util.rs index e223c67..196b82d 100644 --- a/racer-tracer/src/util.rs +++ b/racer-tracer/src/util.rs @@ -1,43 +1,18 @@ -pub fn hsv_to_rgb(h: f64, s: f64, v: f64) -> u32 { - let s: f64 = s / 100.0; - let v: f64 = v / 100.0; - let c: f64 = s * v; - let mut a: f64 = h / 60.0; - a %= 2.0f64; - let x: f64 = c * (1f64 - (a - 1f64).abs()); - let m: f64 = v - c; +use rand::Rng; +/* +// For later use +fn degrees_to_radians(degrees: f64) -> f64 { + degrees * std::f64::consts::PI / 180.0 +}*/ - let r: f64; - let g: f64; - let b: f64; - if (0.0..60.0).contains(&h) { - r = c; - g = x; - b = 0.0; - } else if (60.0..120.0).contains(&h) { - r = x; - g = c; - b = 0.0; - } else if (120.0..180.0).contains(&h) { - r = 0.0; - g = c; - b = x; - } else if (180.0..240.0).contains(&h) { - r = 0.0; - g = x; - b = c; - } else if (240.0..300.0).contains(&h) { - r = x; - g = 0.0; - b = c; - } else { - r = c; - g = 0.0; - b = x; - } - - let red: u32 = ((r + m) * 255.0) as u32; - let green: u32 = ((g + m) * 255.0) as u32; - let blue: u32 = ((b + m) * 255.0) as u32; - ((red as u32) << 16) | ((green as u32) << 8) | blue as u32 +pub fn random_double() -> f64 { + let mut rng = rand::thread_rng(); + rng.gen::() } + +/* +// For later use +pub fn random_double_range(min: f64, max: f64) -> f64 { + let mut rng = rand::thread_rng(); + rng.gen_range(min..max) +}*/ -- cgit v1.2.3