summaryrefslogtreecommitdiff
path: root/ray.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-13 23:31:47 +0800
committerKeuin <[email protected]>2022-04-13 23:31:47 +0800
commite46e1c4033b9d96325de3295eb442a5b1fa19f19 (patch)
tree27a3976278b006b9dc862ba9fdd7cde338ce43e4 /ray.h
parent25ee3cfafea166f2dd155c07b5d43ba90d5bd994 (diff)
Global diffuse lighting. (gamma not corrected)
Some operations on pixel<T>. Make ray3 support copy semantic. Fix vec3 operands does not filter out vec3-vec3 as parameters. random_uv_gen generating random unit vectors.
Diffstat (limited to 'ray.h')
-rw-r--r--ray.h20
1 files changed, 18 insertions, 2 deletions
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<typename T>
class ray3 {
- const vec3<T> source_;
- const vec3<T> direction_; // unit vector
+ vec3<T> source_;
+ vec3<T> direction_; // unit vector
public:
+ ~ray3() = default;
+
ray3() = delete;
+
+ ray3(const ray3<T> &other) = default;
+
+ ray3<T> &operator=(const ray3<T> &other) {
+ source_ = other.source_;
+ direction_ = other.direction_;
+ return *this;
+ }
+
ray3(const vec3<T> &source, const vec3<T> &direction) : source_(source), direction_(direction.unit_vec()) {}
// Get the source point from where the ray emits.
@@ -32,6 +43,11 @@ public:
vec3<T> at(U t) const {
return source_ + direction_ * t;
}
+
+ // Get a ray starts from zero and directs to undefined direction.
+ static ray3<T> null() {
+ return ray3<T>{vec3<T>::zero(), vec3<T>::zero()};
+ }
};
using ray3d = ray3<double>;