-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCamera.cpp
125 lines (107 loc) · 2.52 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "all.hpp"
#include "Camera.hpp"
Camera::Camera(void) : pos_(0.0f, 0.0f, 900.0f), rot_(0.0f, 0.0f, 0.0f)
{
}
void Camera::reset_cam_menu(void)
{
pos_.x = 0.0f;
pos_.y = 0.0f;
pos_.z = 900.0f;
posn_.x = 0.0f;
posn_.y = 0.0f;
posn_.z = -1.0f;
}
void Camera::reset_cam_game(float const & x, float const & y)
{
pos_.x = 0.0f;
pos_.y = (x + y) * (DEMI/1.5);
pos_.z = 1200.0f;
posn_.x = 0.0f;
posn_.y = 0.0f;
posn_.z = -1.0f;
}
void Camera::initialize(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, LARGEUR_ECRAN/HAUTEUR_ECRAN, 1.0f, 10000.0f);
gluLookAt(pos_.x, pos_.y, pos_.z,
posn_.x, posn_.y, posn_.z,
0.0f, 1.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void Camera::initializeN(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, LARGEUR_ECRAN/HAUTEUR_ECRAN, 1.0f, 10000.0f);
gluLookAt(pos_.x, pos_.y, pos_.z,0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void Camera::initialize(float const & a, float const & b)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, LARGEUR_ECRAN/HAUTEUR_ECRAN, 1.0f, 10000.0f);
pos_.x = a + b;
gluLookAt(pos_.x, pos_.y, pos_.z,
posn_.x, pos_.y, posn_.z,
0.0f, 1.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void Camera::update(gdl::GameClock const & gameClock, gdl::Input & input)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(pos_.x, pos_.y, pos_.z,
posn_.x, posn_.y, posn_.z,
0.0f, 1.0f, 0.0f);
(void) gameClock;
(void) input;
}
void Camera::getKeys(gdl::GameClock const & gameClock, gdl::Input & input)
{
if (input.isKeyDown(gdl::Keys::W) == true)
this->pos_.y += 25;
if (input.isKeyDown(gdl::Keys::S) == true)
this->pos_.y -= 25;
if (input.isKeyDown(gdl::Keys::A) == true)
this->pos_.x -= 25;
if (input.isKeyDown(gdl::Keys::D) == true)
this->pos_.x += 25;
this->update(gameClock, input);
}
Pos3f Camera::getPos(void) const
{
return this->pos_;
}
Pos3f Camera::getPosn(void) const
{
return this->posn_;
}
Pos3f Camera::getRot(void) const
{
return this->rot_;
}
void Camera::setPos(Pos3f const & pos)
{
this->pos_ = pos;
}
void Camera::setPosn(Pos3f const & posn)
{
this->posn_ = posn;
}
void Camera::setRot(Pos3f const & rot)
{
this->rot_ = rot;
}