-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.cpp
253 lines (209 loc) · 4.57 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
Author : Jeremiah Wilson
Course : CSCI 375
Assignment : Camera
Description: Implementation of Camera class
*/
/************************************************************/
// System includes
#include <cstdlib>
/************************************************************/
// Local includes
#include "Vector3.h"
#include "Camera.h"
#include "ShaderProgram.h"
#include "Transform.h"
/************************************************************/
Camera::Camera ()
{
}
Camera::Camera (Vector3 backVec, Vector3 eyePoint, Vector3 upVec, Vector3 rightVec)
{
//Got a warning initializing these along with the others
m_camera.setPosition (eyePoint);
Math::Matrix3 camera (rightVec, upVec, backVec);
m_camera.setOrientation (camera);
m_startPointMatrix = m_camera.getOrientation ();
m_startPoint = eyePoint;
}
Camera::~Camera ()
{
}
/************************************************************/
void
Camera::yaw (float angleDegrees)
{
m_camera.yaw (angleDegrees);
}
void
Camera::pitch (float angleDegrees)
{
m_camera.pitch (angleDegrees);
}
void
Camera::roll (float angleDegrees)
{
m_camera.roll (angleDegrees);
}
void
Camera::moveLocalRight (float distance)
{
m_camera.moveRight (distance);
}
void
Camera::moveLocalUp (float distance)
{
m_camera.moveUp (distance);
}
void
Camera::moveLocalBack (float distance)
{
m_camera.moveBack (distance);
}
void
Camera::setBackVec (const float x, const float y, const float z)
{
Vector3 back (x, y, z);
back.negate ();
this->m_camera.setBack (back);
this->m_startPointMatrix.setBack (back);
}
void
Camera::setBackVec (const Vector3 v)
{
Vector3 vec (v);
vec.negate ();
this->m_camera.setBack (vec);
this->m_startPointMatrix.setBack (vec);
}
void
Camera::setEyePoint (const float x, const float y, const float z)
{
Vector3 eye (x, y, z);
m_camera.setPosition (eye);
if (first)
{
this->m_startPoint = eye;
first = false;
}
}
void
Camera::setEyePoint (const Vector3 v)
{
m_camera.setPosition (v);
if (first){
this->m_startPoint.set (v.x, v.y, v.z);
first = false;
}
}
void
Camera::setUpVec (const float x, const float y, const float z)
{
Vector3 up (x, y, z);
this->m_camera.setUp (up);
this->m_startPointMatrix.setUp (up);
}
void
Camera::setUpVec (const Vector3 v)
{
this->m_camera.setUp (v);
this->m_startPointMatrix.setUp (v);
}
void
Camera::setRightVec (const Vector3 v)
{
this->m_camera.setRight (v);
this->m_startPointMatrix.setRight (v);
}
void
Camera::setRightVec (const float x, const float y, const float z)
{
Vector3 right (x, y, z);
this->m_camera.setRight (right);
this->m_startPointMatrix.setRight (right);
}
Vector3
Camera::getRightVec ()
{
return m_camera.getRight ();
}
Vector3
Camera::getBackVec ()
{
return m_camera.getBack ();
}
Vector3
Camera::getEyePoint ()
{
return m_camera.getPosition ();
}
Vector3
Camera::getUpVec ()
{
return m_camera.getUp ();
}
Math::Transform
Camera::getViewMatrix ()
{
Math::Transform view;
Vector3 at (m_camera.getBack ().x + m_camera.getPosition ().x, m_camera.getBack ().y + m_camera.getPosition ().y, m_camera.getBack ().z + m_camera.getPosition ().z);
Vector3 eye (m_camera.getPosition ());
Vector3 up (m_camera.getUp ());
Vector3 back = eye - at;
back.normalize ();
Vector3 right = up.cross(back);
right.normalize ();
eye.negate ();
Math::Matrix3 rotScale (right, up, back);
rotScale.transpose ();
view.setOrientation (rotScale);
Vector3 translation = rotScale * eye;
//Vector3 translation = -eye;
view.setPosition (translation);
return view;
}
Math::Matrix4
Camera::getPrespectiveProjectionMatrix ()
{
m_projectionMatrix.setToPerspectiveProjection(m_verticalFov, m_aspectRatio, m_nearZ, m_farZ);
return m_projectionMatrix;
}
Math::Matrix4
Camera::getOrthographicProjectionMatrix ()
{
m_projectionMatrix.setToOrthographicProjection(-right, right, -top, top, m_nearZ, m_farZ);
return m_projectionMatrix;
}
void
Camera::reset ()
{
setEyePoint (m_startPoint);
m_camera.setRight (m_startPointMatrix.getRight ());
m_camera.setUp (m_startPointMatrix.getUp ());
m_camera.setBack (m_startPointMatrix.getBack ());
}
bool
Camera::isPrespective()
{
return m_projectionMatrix.isPrespective();
}
void
Camera::zoom(float deltaFov)
{
if (deltaFov > 0 && m_verticalFov > glm::radians(120.0f))
{
}
else if (deltaFov < 0 && m_verticalFov < glm::radians(1.0f))
{
}
else
{
m_verticalFov += deltaFov;
}
}
void
Camera::resetAspectRatio(int width, int height)
{
m_aspectRatio = (float) ((float)width / (float)height);
}
/************************************************************/