-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.cpp
More file actions
executable file
·57 lines (43 loc) · 1.14 KB
/
Copy pathcamera.cpp
File metadata and controls
executable file
·57 lines (43 loc) · 1.14 KB
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
#include"camera.h"
#include<cmath>
#include<GLUT/glut.h>
Camera::Camera() :
theta_(3.14159f/2.f),
phi_(0),
r_(0.6)
{
}
void Camera::Init(float theta, float phi, float r)
{
theta_ = theta;
phi_ = phi;
r_ = r;
// constraint theta to a range
if (theta_ < 3.14159f * 0.1f)
theta_ = 3.14159f * 0.1f;
else if (theta_ > 3.14159f * 0.9f)
theta_ = 3.14159f * 0.9f;
Vector3Df pos = SphericalToXYZ();
glLoadIdentity();
gluLookAt(pos.x, pos.y, pos.z, 0, 0, 0, 0, 0, 1);
}
void Camera::UpdateAngles(float dtheta, float dphi)
{
theta_ += dtheta;
// constraint theta to a range
if (theta_ < 3.14159f * 0.1f)
theta_ = 3.14159f * 0.1f;
else if (theta_ > 3.14159f * 0.9f)
theta_ = 3.14159f * 0.9f;
phi_ += dphi;
Vector3Df pos = SphericalToXYZ();
glLoadIdentity();
gluLookAt(pos.x, pos.y, pos.z, 0, 0, 0, 0, 0, 1);
}
Vector3Df Camera::SphericalToXYZ()
{
float x = r_ * sin(theta_) * cos(phi_);
float y = r_ * sin(theta_) * sin(phi_);
float z = r_ * cos(theta_);
return Vector3Df(x,y,z);
}