-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint3.hpp
44 lines (35 loc) · 825 Bytes
/
point3.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "vec3.hpp"
template <typename FloatT> struct ray3;
template <typename FloatT>
struct point3
{
using vec_type = vec3<FloatT>;
using ray_type = ray3<FloatT>;
static const point3 Origin;
const FloatT x, y, z;
point3(FloatT x_, FloatT y_, FloatT z_)
: x(x_), y(y_), z(z_)
{}
point3 operator +(const vec_type& v) const
{
return {
x + v.x,
y + v.y,
z + v.z
};
}
vec_type operator -(const point3& rhs) const
{
return {
x - rhs.x,
y - rhs.y,
z - rhs.z
};
}
ray_type rayThrough(const point3& p) const;
point3 atDistanceToward(const point3& p, FloatT distance) const
{
return *this + (p - *this).unit() * distance;
}
};