// // Created by Keuin on 2022/4/11. // #ifndef RT_RAY_H #define RT_RAY_H #include "vec.h" // 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 public: ray3() = delete; ray3(const vec3 &source, const vec3 &direction) : source_(source), direction_(direction.unit_vec()) {} // Get the source point from where the ray emits. vec3 source() const { return source_; } // Get the unit vector along the ray's direction. vec3 direction() const { return direction_; } // Compute the point this ray reaches at the time `t`. template vec3 at(U t) const { return source_ + direction_ * t; } }; using ray3d = ray3; #endif //RT_RAY_H