-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
81 lines (65 loc) · 1.55 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Camera.h"
#include "Config.h"
#include "GL/glut.h"
#include "vect3d.h"
const float Camera::RotateCount = 0.4f;
Camera::Camera()
:_fposx(0), _fposy(0), _fposz(0),
_fctrx(0), _fctry(0), _fctrz(0),
_fupx(0), _fupy(0), _fupz(0),
_bRotate(false),_fAngle(0)
{
}
void Camera::Rotating(bool bRotate)
{
_bRotate = bRotate;
}
void Camera::Put()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
const float fv = 0.1;
glFrustum(-fv, fv, -fv, fv, 1, 1000);
gluLookAt( _fposx, _fposy, _fposz,
_fctrx, _fctry, _fctrz,
_fupx, _fupy, _fupz
);
//gluPerspective(40,(GLfloat)WindowWidth/(GLfloat)WindowHeight,0.01,1000);
if(_bRotate)
{
_fAngle += GetInterval() / 1000.f * 360.f * RotateCount;
}
glRotatef(-_fAngle, 0, 1, 0);
}
void Camera::Set( float posx, float posy, float posz,
float cx, float cy, float cz,
float upx, float upy, float upz)
{
_fposx = posx; _fposy = posy; _fposz = posz;
_fctrx = cx; _fctry = cy; _fctrz = cz;
_fupx = upx; _fupy = upy; _fupz =upz;
}
void Camera::ZoomIn()
{
Vect3d vOrigViewVec( _fposx - _fctrx,
_fposy - _fctry,
_fposz - _fctrz);
vOrigViewVec *= 0.95;
_fposx = _fctrx + vOrigViewVec.x();
_fposy = _fctry + vOrigViewVec.y();
_fposz = _fctrz + vOrigViewVec.z();
}
void Camera::ZoomOut()
{
Vect3d vOrigViewVec( _fposx - _fctrx,
_fposy - _fctry,
_fposz - _fctrz);
vOrigViewVec *= 1.05;
_fposx = _fctrx + vOrigViewVec.x();
_fposy = _fctry + vOrigViewVec.y();
_fposz = _fctrz + vOrigViewVec.z();
}
void Camera::Rotate(float fAngle)
{
_fAngle += fAngle;
}