From e46e1c4033b9d96325de3295eb442a5b1fa19f19 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 23:31:47 +0800 Subject: Global diffuse lighting. (gamma not corrected) Some operations on pixel. Make ray3 support copy semantic. Fix vec3 operands does not filter out vec3-vec3 as parameters. random_uv_gen generating random unit vectors. --- ray.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'ray.h') diff --git a/ray.h b/ray.h index 5a68557..db28d0f 100644 --- a/ray.h +++ b/ray.h @@ -10,11 +10,22 @@ // A ray is a half-line, starts from a 3d point, along the direction of a unit vector, to the infinity template class ray3 { - const vec3 source_; - const vec3 direction_; // unit vector + vec3 source_; + vec3 direction_; // unit vector public: + ~ray3() = default; + ray3() = delete; + + ray3(const ray3 &other) = default; + + ray3 &operator=(const ray3 &other) { + source_ = other.source_; + direction_ = other.direction_; + return *this; + } + ray3(const vec3 &source, const vec3 &direction) : source_(source), direction_(direction.unit_vec()) {} // Get the source point from where the ray emits. @@ -32,6 +43,11 @@ public: vec3 at(U t) const { return source_ + direction_ * t; } + + // Get a ray starts from zero and directs to undefined direction. + static ray3 null() { + return ray3{vec3::zero(), vec3::zero()}; + } }; using ray3d = ray3; -- cgit v1.2.3