From 43714bd116945573e7e4c854445462afa7f9b1b4 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 11 Apr 2022 22:13:57 +0800 Subject: Implement ray3, timer and a simple viewport scanner. Fix bitmap wrong pixel sequence. Remove default constructor of bitmap. Add pixel mixture method. --- ray.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ray.h (limited to 'ray.h') diff --git a/ray.h b/ray.h new file mode 100644 index 0000000..3281c6e --- /dev/null +++ b/ray.h @@ -0,0 +1,36 @@ +// +// 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()) {} + + vec3 source() const { + return source_; + } + + vec3 direction() const { + return direction_; + } + + template + vec3 at(U t) const { + return source_ + direction_ * t; + } +}; + +using ray3d = ray3; + +#endif //RT_RAY_H -- cgit v1.2.3