-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.cpp
193 lines (157 loc) · 6.23 KB
/
view.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "view.h"
#include <iostream>
inline void pv(vec3d v) { std::cout << "<" << v.x << ", " << v.y << ", " << v.z << ">"; }
namespace view
{
perspectiveViewWindow::perspectiveViewWindow(point start, point middle, F64 angleT, F64 angleP, resolution _res, dimensions _dim, UInt64 subs) :
viewWindow(middle, angleT, angleP, _res, _dim, subs > 0 ? subs : 1),
startPoint(start)
{
dist = std::uniform_real_distribution<F64>(-dim.first/(res.first*subdivisions), dim.second/(res.second*subdivisions));
vectors = new vec3d*[res.first*subdivisions];
for (UInt64 i = 0; i < res.first*subdivisions; i++)
{
vectors[i] = new vec3d[res.second*subdivisions];
}
vec3d vertDir(cos(angleTheta)*cos(anglePhi), sin(angleTheta)*cos(anglePhi), sin(anglePhi));
vec3d horizDir(cos(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(anglePhi+PI/2)); //same vec rotated 90 degs
for (UInt64 t = 0; t < res.first*subdivisions; t++)
{
for (UInt64 s = 0; s < res.second*subdivisions; s++)
{
F64 subPixelVert = (F64)(t) - (res.first*subdivisions)/2;
F64 subPixelHoriz = (F64)(s) - (res.second*subdivisions)/2;
subPixelVert *= (dim.first/2)/(res.first*subdivisions/2);
subPixelHoriz *= (dim.second/2)/(res.second*subdivisions/2);
subPixelVert += dist(gen);
subPixelHoriz += dist(gen);
vec3d endPoint = vec3d(windowMiddle) + subPixelVert*vertDir + subPixelHoriz*horizDir;
//pv(endPoint); std::cout << std::endl;
vectors[t][s] = (endPoint-startPoint).unit();
//pv(vectors[t][s]); std::cout << std::endl;
}
}
}
perspectiveViewWindow::perspectiveViewWindow(F64 distBehind, point middle, F64 angleT, F64 angleP, resolution _res, dimensions _dim, UInt64 subs) :
viewWindow(middle, angleT, angleP, _res, _dim, subs > 0 ? subs : 1)
{
dist = std::uniform_real_distribution<F64>(-dim.first/(res.first*subdivisions), dim.second/(res.second*subdivisions));
vectors = new vec3d*[res.first*subdivisions];
for (UInt64 i = 0; i < res.first*subdivisions; i++)
{
vectors[i] = new vec3d[res.second*subdivisions];
}
vec3d vertDir(cos(angleTheta)*cos(anglePhi), sin(angleTheta)*cos(anglePhi), sin(anglePhi));
vec3d horizDir(cos(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(anglePhi+PI/2)); //same vec rotated 90 degs
startPoint = (vec3d)middle+vertDir.cross(horizDir)*distBehind;
for (UInt64 t = 0; t < res.first*subdivisions; t++)
{
for (UInt64 s = 0; s < res.second*subdivisions; s++)
{
F64 subPixelVert = (F64)(t) - (res.first*subdivisions)/2;
F64 subPixelHoriz = (F64)(s) - (res.second*subdivisions)/2;
subPixelVert *= (dim.first/2)/(res.first*subdivisions/2);
subPixelHoriz *= (dim.second/2)/(res.second*subdivisions/2);
subPixelVert += dist(gen);
subPixelHoriz += dist(gen);
vec3d endPoint = vec3d(windowMiddle) + subPixelVert*vertDir + subPixelHoriz*horizDir;
//pv(endPoint); std::cout << std::endl;
vectors[t][s] = (endPoint-startPoint).unit();
//pv(vectors[t][s]); std::cout << std::endl;
}
}
}
perspectiveViewWindow::~perspectiveViewWindow()
{
for (UInt64 i = 0; i < res.first*subdivisions; i++)
{
delete[] vectors[i];
}
delete[] vectors;
}
ray3d *** perspectiveViewWindow::rays()
{
ray3d *** rays = new ray3d**[res.first];
for (UInt64 i = 0; i < res.first; i++)
{
rays[i] = new ray3d*[res.second];
for(UInt64 j = 0; j < res.second; j++)
{
rays[i][j] = new ray3d[subdivisions*subdivisions];
}
}
for (UInt64 t = 0; t < res.first; t++)
{
for (UInt64 s = 0; s < res.second; s++)
{
for (UInt64 sub = 0; sub < subdivisions*subdivisions; sub++)
{
rays[t][s][sub] = ray3d(startPoint, vectors[t*subdivisions+sub/subdivisions][s*subdivisions+sub%subdivisions]);
}
}
}
return rays;
}
orthographicViewWindow::orthographicViewWindow(point middle, F64 angleT, F64 angleP, resolution _res, dimensions _dim, UInt64 subs) :
viewWindow(middle, angleT, angleP, _res, _dim, subs > 0 ? subs : 1)
{
dist = std::uniform_real_distribution<F64>(-dim.first/(res.first*subdivisions), dim.second/(res.second*subdivisions));
startPoints = new point*[res.first*subdivisions];
for (UInt64 i = 0; i < res.first*subdivisions; i++)
{
startPoints[i] = new point[res.second*subdivisions];
}
//vec3d vertDir(cos(angleTheta)*cos(anglePhi), sin(angleTheta)*cos(anglePhi), sin(anglePhi));
//vec3d horizDir(cos(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(anglePhi+PI/2)); //same vec rotated 90 degs
vec3d vertDir(cos(angleTheta)*cos(anglePhi), sin(angleTheta)*cos(anglePhi), sin(anglePhi));
vec3d horizDir(cos(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(angleTheta+PI/2)*cos(anglePhi+PI/2), sin(anglePhi+PI/2)); //same vec rotated 90 degs
direction = -1*vertDir.cross(horizDir).unit();
v3d::pv(direction);
for (UInt64 t = 0; t < res.first*subdivisions; t++)
{
for (UInt64 s = 0; s < res.second*subdivisions; s++)
{
F64 subPixelVert = (F64)(t) - (res.first*subdivisions)/2;
F64 subPixelHoriz = (F64)(s) - (res.second*subdivisions)/2;
subPixelVert *= (dim.first/2)/(res.first*subdivisions/2);
subPixelHoriz *= (dim.second/2)/(res.second*subdivisions/2);
subPixelVert += dist(gen);
subPixelHoriz += dist(gen);
vec3d startPoint = vec3d(windowMiddle) + subPixelVert*vertDir + subPixelHoriz*horizDir;
startPoints[t][s] = (point)startPoint;
}
}
}
orthographicViewWindow::~orthographicViewWindow()
{
for (UInt64 i = 0; i < res.first*subdivisions; i++)
{
delete[] startPoints[i];
}
delete[] startPoints;
}
ray3d *** orthographicViewWindow::rays()
{
ray3d *** rays = new ray3d**[res.first];
for (UInt64 i = 0; i < res.first; i++)
{
rays[i] = new ray3d*[res.second];
for(UInt64 j = 0; j < res.second; j++)
{
rays[i][j] = new ray3d[subdivisions*subdivisions];
}
}
for (UInt64 t = 0; t < res.first; t++)
{
for (UInt64 s = 0; s < res.second; s++)
{
for (UInt64 sub = 0; sub < subdivisions*subdivisions; sub++)
{
rays[t][s][sub] = ray3d(startPoints[t*subdivisions+sub/subdivisions][s*subdivisions+sub%subdivisions], direction);
//pr(rays[t][s][sub]); std::cout << std::endl;
}
}
}
return rays;
}
}