aboutsummaryrefslogtreecommitdiffstats
path: root/vec3.h
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2024-05-14 19:58:40 -0400
committerClyne Sullivan <clyne@bitgloo.com>2024-05-14 19:58:40 -0400
commit7d174816febeed6977a7e90be5c80e9b99b11df9 (patch)
tree12b41ae02f03bf5bcaef84690f0a8824d71c7183 /vec3.h
parentaf1740bde341ef7703696cb7fd26d66cd8a37462 (diff)
many changes, more controls
Diffstat (limited to 'vec3.h')
-rw-r--r--vec3.h6
1 files changed, 5 insertions, 1 deletions
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;
}
}