From 7d174816febeed6977a7e90be5c80e9b99b11df9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 14 May 2024 19:58:40 -0400 Subject: many changes, more controls --- vec3.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'vec3.h') diff --git a/vec3.h b/vec3.h index 46367d2..b648ce3 100644 --- a/vec3.h +++ b/vec3.h @@ -94,6 +94,10 @@ struct vec3 { auto rpara = v * -std::sqrt(std::fabs(1.0 - rperp.length_squared())); return rperp + rpara; } + + static vec3 random() { + return vec3(randomN(), randomN(), randomN()); + } }; // point3 is just an alias for vec3, but useful for geometric clarity in the code. @@ -125,7 +129,7 @@ inline constexpr vec3 unit_vector(const vec3& v) { inline vec3 randomUnitSphere() { for (;;) { - if (auto p = vec3(randomN(), randomN(), randomN()) * 2 - vec3(1, 1, 1); p.length_squared() < 1) + if (auto p = vec3::random() * 2 - vec3(1, 1, 1); p.length_squared() < 1) return p; } } -- cgit v1.2.3