-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamara.cpp
56 lines (50 loc) · 1.43 KB
/
Camara.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
#include <string>
#include <iostream>
#include "Camara.h"
#include "Utils/PlanoVista.h"
#include "Utils/ShadeRec.h"
void Camara::calcularUVW() {
w = ojo - lookat;
w.normalizar();
Vector3D up(0, 1, 0);
u = up ^ w;
u.normalizar();
v = w ^ u;
}
Vector3D Camara::getDireccion(Vector3D p) {
Vector3D tmp = v * p.y;
Vector3D tmp2 = w * 500;
Vector3D dir = u * p.x + tmp - tmp2;
dir.normalizar();
return dir;
}
void Camara::renderizarEscena(Mundo m, const std::string& path, int i) {
PlanoVista pv(m.pv);
Rayo rayo;
Vector3D pp;
Vector3D color;
int n = 1;
int depth = 0;
rayo.o = ojo;
m.pImg = new CImg<BYTE>(pv.hres, pv.vres, 1, 3);
CImgDisplay dis_img((*m.pImg), "", 3, false, true);
std::cout << "Rendering frame " << i << "...\n";
int r, c, p = 0, q = 0;
for (r = 0; r < pv.vres; r++) {
for (c = 0; c < pv.hres; c++) {
color.set(0,0,0);
pp.x = pv.tamPixel * (c - 0.5 * pv.hres + (q + 0.5) );
pp.y = pv.tamPixel * (r - 0.5 * pv.vres + (p + 0.5) );
rayo.d = getDireccion(pp);
color = color + m.pTracer->trace_ray(rayo, depth);
m.mostrarPixel(r, c, color);
dis_img.render((*m.pImg));
dis_img.paint();
}
}
while (!dis_img.is_closed()) {
dis_img.wait();
}
auto s = path + "render" + std::to_string(i) + ".bmp";
m.pImg->save(s.c_str());
}