-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRay.cpp
More file actions
93 lines (75 loc) · 2.21 KB
/
Copy pathRay.cpp
File metadata and controls
93 lines (75 loc) · 2.21 KB
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
83
84
85
86
87
88
89
90
91
92
93
#include "Ray.h"
#include <math.h>
// Default constructor - creates a ray at the origin heading (0,0,0)
Ray::Ray() {
m_origin = Vector();
m_direction = Vector();
setInverse();
}
// Create a ray at a specified point heading towards (0,0,0)
Ray::Ray(Vector ray_origin) {
m_origin = ray_origin;
m_direction = Vector();
setInverse();
}
// Create a ray at a specified point heading in a given direction
Ray::Ray(Vector ray_origin, Vector direction) {
m_origin = ray_origin;
m_direction = direction;
setInverse();
}
// Setter: set the origin point of the ray with given X, Y, and Z values
void Ray::setOrigin(float x, float y, float z) {
m_origin = Vector(x, y, z);
}
// Setter: set the origin point of the ray with a given Vector
void Ray::setOrigin(Vector new_origin) {
m_origin = new_origin;
}
// Setter: set the direction of the ray with given X, Y, and Z values
void Ray::setDirection(float x, float y, float z) {
m_direction = Vector(x, y, z);
setInverse();
}
// Setter: set the direction of the ray with a given Vector
void Ray::setDirection(Vector new_direction) {
m_direction = new_direction;
setInverse();
}
// Private Setter: set the inverse direction of the given direction
void Ray::setInverse() {
m_direction_inverse = Vector(powf(m_direction.getX(), -1.0f), powf(m_direction.getY(), -1.0f),
powf(m_direction.getZ(), -1.0f));
m_signx = ((int)m_direction_inverse.getX() < 0);
m_signy = ((int)m_direction_inverse.getY() < 0);
m_signz = ((int)m_direction_inverse.getZ() < 0);
}
// Setter: set the maximum depth of the ray
void Ray::setMaxDepth(int new_max_depth) {
m_max_depth = new_max_depth;
}
// Getter: get the origin point of the ray
Vector Ray::getOrigin() const {
return m_origin;
}
// Getter: get the direction of the ray
Vector Ray::getDirection() const {
return m_direction;
}
// Getter: get the inverse direction of the ray
Vector Ray::getInverseDirection() const {
return m_direction_inverse;
}
int Ray::getSignX() {
return m_signx;
}
int Ray::getSignY() {
return m_signy;
}
int Ray::getSignZ() {
return m_signz;
}
// Getter: get the maximum depth of the ray
int Ray::getMaxDepth() {
return m_max_depth;
}