-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcamera.cpp
106 lines (74 loc) · 1.77 KB
/
rtcamera.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
#include "rtcamera.h"
RTCamera::RTCamera()
{
}
RTCamera::RTCamera(RTPoint e,RTPoint look_at,RTVector up,double fovy){
//campo de visão
this->e=e;
this->fovy=fovy;
//base ortonormal
RTVector viewDirection = (look_at*1.0);
this->w=viewDirection;
this->w.normalize();
this->u=(up*w);
this->u.normalize();
this->v=(w*u);
this->v.normalize();
}
RTRay RTCamera::generateRay(int i, int j, double offseti, double offsetj){
int width=RTFilm::getInstance()->getWidth();
int height=RTFilm::getInstance()->getHeight();
double aux = 2.0 * tan(fovy / 2.0) / width;
double a = ( j+offsetj + 0.5 - height / 2.0 );
double b = ( i+offseti + 0.5 - width / 2.0 );
RTVector dir=this->w+(((this->v*aux)*a)+((this->u*aux)*b));
dir.normalize();
return RTRay(e,dir);
/* double fov = this->fovy*M_PI/180.0;
double x_range = tan(fov / 2.0) * width / height;
double b = tan(fov / 2.0) * (height/2.0 - i) / (height / 2.0);
double a = x_range * (j - width/2.0) / (width / 2.0);
RTVector dirRay=((w*-1.0)+(u*a)+(v*b));
dirRay.normalize();
*/
}
RTPoint RTCamera::getE() const
{
return e;
}
void RTCamera::setE(const RTPoint &value)
{
e = value;
}
double RTCamera::getFovy() const
{
return fovy;
}
void RTCamera::setFovy(double value)
{
fovy = value;
}
RTVector RTCamera::getW() const
{
return w;
}
void RTCamera::setW(const RTVector &value)
{
w = value;
}
RTVector RTCamera::getU() const
{
return u;
}
void RTCamera::setU(const RTVector &value)
{
u = value;
}
RTVector RTCamera::getV() const
{
return v;
}
void RTCamera::setV(const RTVector &value)
{
v = value;
}