-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ray.h
82 lines (59 loc) · 1.44 KB
/
Ray.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef RAY_H
#define RAY_H
#include "EigenIncludes.h"
#include "Geometry.h"
#include <cfloat>
#include <iostream>
using namespace Eigen;
class Ray
{
public:
Ray() {
};
Ray(Vector3d origin, Vector3d direction)
:origin(origin), direction(direction)
{
}
~Ray() {
};
Vector3d GetOrigin() const { return origin; }
Vector3d GetDirection() const {
return direction;
}
// If hit nothing distance == INIFINITY
double GetHitDistance() const
{
if (hit_coor.hasNaN()) return INFINITY;
return (hit_coor - origin).norm();
}
// From origin of this ray to a point
double GetDistance(const Vector3d& point) const
{
if (point.hasNaN()) return DBL_MAX;
return (point - origin).norm();
}
Vector3d GetPoint(double& distance) const { return distance * direction + origin; }
bool IsCloser(const Vector3d& point)
{
if (hit_coor.hasNaN()) return true;
return (GetDistance(point) < (hit_coor - origin).norm());
}
void SetClosestHit(const Vector3d& point, Geometry& hit_obj)
{
hit_coor = point;
this->hit_obj = &hit_obj;
}
const Vector3d& GetHitCoor() const
{
return hit_coor;
}
private:
Vector3d hit_coor = Vector3d(NAN,NAN,NAN);
public:
Geometry* hit_obj = nullptr;
public:
Vector3d origin;
Vector3d direction;
Color diffuse;
};
#endif