-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
53 lines (44 loc) · 873 Bytes
/
Copy pathCamera.cpp
File metadata and controls
53 lines (44 loc) · 873 Bytes
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
/* Camera (viewer) class, based on spherical coordinates.
* Here, we're really only moving the camera backwards,
* but there's functionality for movement should the case arise.
*/
using namespace std;
#include "Camera.h"
#define PI 3.14159265358979
Camera::Camera()
{
reset();
}
Camera::~Camera() {}
void Camera::draw()
{
gluLookAt(x,y,z,0.0,0.0,0.0,0.0,1.0,0.0);
}
void Camera::reset()
{
r = 50.0f;
az = 0.0f;
inc = PI/2;
updateXYZ();
print();
}
void Camera::translate(float dr, float daz, float dinc)
{
r += dr;
az = fmodf(az + daz, PI*2);
inc = fmodf(inc + dinc, PI*2);
updateXYZ();
print();
}
void Camera::updateXYZ()
{
x = r*sin(az)*sin(inc);
y = r*cos(inc);
z = r*cos(az)*sin(inc);
}
void Camera::print()
{
#ifdef DEBUG
printf("New camera:\nx: %f\ny: %f\nz: %f\nr: %f\ninc: %f\naz: %f\n", x, y, z, r, inc, az);
#endif
}