-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ray.hh
77 lines (57 loc) · 1.2 KB
/
Ray.hh
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
/*
Author: dok
Desc: Basic Ray class
*/
#ifndef Ray_hh
#define Ray_hh
#include "Vector.hh"
#include "Point.hh"
/* todo: use heap allocation?
*
*/
class Ray
{
private:
Point origin;
Vector dir;
public:
/*----------------------- Constructors ----------------*/
Ray(const Point& point, const Vector& direction){ // parameter constructor
origin = point;
dir = direction;
dir.Normalize();
}
Ray(float x, float y, float z, float u, float v, float w) // parameter constructor
{
origin = Point(x,y,z);
dir = Vector(u,v,w);
}
Ray(const Ray &ray){
origin = Point();
dir = Vector();
origin += ray.origin;
dir += ray.dir;
}
Ray(){ // default constructor
origin = Point(0,0,0);
dir = Vector(0,0,0);
}
/*------------------- Accessors ------------*/
Point Origin()const{
return origin;
}
Vector Direction()const{
return dir;
}
Point& Origin(){
return origin;
}
Vector& Direction(){
return dir;
}
/*--------------- Ray Functions -----------*/
Point PointOn(float t){
return origin + t*dir;
}
};
#endif