-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
executable file
·66 lines (55 loc) · 1.24 KB
/
camera.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
#include "camera.h"
Camera::Camera(float radius,const glm::vec3 ¢er,int mode)
: _m(NONE),
_w(0),
_h(0),
_p(0,0),
_c(glmToVec3(center)),
_r(radius),
_t(),
_f(45.0f),
_d(mode),
_up(0,0,0),
_right(0,0,0),
_view(0,0,0),
_zmin(0),
_zmax(0) {
}
void Camera::initialize(int w,int h,bool replace) {
const float tmp1 = 100.0f;
const float tmp2 = 3.0f;
int wo2 = w/2;
int ho2 = h/2;
int rad = wo2<ho2 ? wo2 : ho2;
// data initialization
_m = NONE;
_w = w;
_h = h;
_t = TrackBall(rad*2,Vec2f(wo2,ho2));
_f = 45.0f;
// projection transformations
if(_d==PERSP) {
_matp = glmToMat4(glm::perspective(_f,(float)_w/(float)_h,_r/tmp1,_r*tmp1));
} else {
_matp = glmToMat4(glm::ortho((float)(-_w),(float)_w,(float)(-_h),(float)_h,0.0f,_r*100.0f));
}
if(!replace)
return;
// camera transformations
_matm = glmToMat4(glm::lookAt(glm::vec3(_c[0],_c[1],_c[2]+tmp2*_r),
glm::vec3(_c[0],_c[1],_c[2]),
glm::vec3(0.0,1.0,0.0)));
// update params
updateCamVectors(_matm);
updateCamDists(_matm);
}
void Camera::setFovy(float f) {
_f = f;
initialize(_w,_h,false);
}
void Camera::setMode(int m) {
if(_d!=m) {
_d = m;
initialize(_w,_h,false);
}
}