-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRay.cpp
87 lines (76 loc) · 1.48 KB
/
Ray.cpp
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
#include "Ray.h"
Ray::Ray(){
d = vector<float>(4,0);
p = vector<float>(4,0);
d[3] = p[3] = 1;
}
Ray::Ray(vector<float> d, vector<float> p){
this->d = d;
this->p = p;
a = b = c = 0;
for(int i=0; i<3; ++i){
a += d[i] * d[i];
b += p[i] * d[i];
c += p[i] * p[i];
}
}
// Ray Ray::multiply(Matrix &m, bool inverse){
// Ray r (
// inverse ? m.Inv_Vec_Mul(this->d) : m.Vec_Mul(this->d),
// inverse ? m.Inv_Vec_Mul(this->p) : m.Vec_Mul(this->p)
// );
// return r;
// }
void Ray::set_d(vector<float> d){
a = b = 0;
for(int i=0; i<3; ++i){
this->d[i] = d[i];
a += d[i] * d[i];
b += p[i] * d[i];
// c += p[i] * p[i];
}
}
void Ray::set_p(vector<float> p){
b = c = 0;
for(int i=0; i<3; ++i){
this->p[i] = p[i];
// a += d[i] * d[i];
b += p[i] * d[i];
c += p[i] * p[i];
}
}
std::tuple<float, float, float> Ray::get_abc(){
return std::make_tuple(a,b,c);
}
vector<float> Ray::get_point(float t){
vector<float> ret(4,1);
for(int i=0; i<3; ++i){
ret[i] = p[i] + t*d[i];
}
return ret;
}
void Ray::add_offset(vector<float> &o)
{
b = c = 0;
for (int i = 0; i < 3; i++)
{
p[i] += o[i];
b += p[i]*d[i];
c += p[i]*p[i];
}
}
void Ray::add_dirn(vector<float> &dn)
{
a = b = 0;
for (int i = 0; i < 3; i++)
{
d[i] += dn[i];
a += d[i]*d[i];
b += p[i]*d[i];
}
}
void Ray::print(){
cout << "d "; for(auto i : d) cout << i << " "; cout << endl;
cout << "p "; for(auto i : p) cout << i << " "; cout << endl;
// cout << "a " << a << " b " << b << " c " << c << endl;
}