diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-05-14 19:58:40 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-05-14 19:58:40 -0400 |
commit | 7d174816febeed6977a7e90be5c80e9b99b11df9 (patch) | |
tree | 12b41ae02f03bf5bcaef84690f0a8824d71c7183 /vec3.h | |
parent | af1740bde341ef7703696cb7fd26d66cd8a37462 (diff) |
many changes, more controls
Diffstat (limited to 'vec3.h')
-rw-r--r-- | vec3.h | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; } } |