-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
81 lines (69 loc) · 1.64 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 <glm\gtc\matrix_transform.hpp>
#include "Camera.h"
#include "Shader.h"
#include "RenderingEngine.h"
float Camera::speed = 0.05f;
vec3 Camera::YAxis = vec3(0.0f, 1.0f, 0.0f);
Camera::Camera() : KeyCallback(), EngineObject(), ViewProjMat("ViewProj"), EyePos("EyePos")
{
_pos = vec3(0, 0, 0);
forward = vec3(0, 0, -1);
up = vec3(0, 1, 0);
FoV = 90.0f;
Aspect = 1.333f;
View = mat4();
projection = perspective( FoV, Aspect, 0.1f, 100000.0f);
}
void Camera::update(ThreadManager& mgr)
{
}
void Camera::render(Shader& s, RenderingEngine::RenderState firstPass)
{
View = projection * lookAt(_pos, _pos + normalize(forward), normalize(up));
s.setUniform(ViewProjMat, &View[0][0]);
s.setUniform(EyePos, &_pos[0]);
}
void Camera::setFoV(float fov)
{
FoV = fov;
projection = perspective(FoV, Aspect, 0.1f, 100.0f);
}
void Camera::setAspect(float aspect)
{
Aspect = aspect;
projection = perspective(FoV, Aspect, 0.1f, 100.0f);
}
Camera::~Camera()
{
}
void Camera::onMouseMove(double dY, double dX)
{
//computing X rotation
XAngle += dX * - speed * 0.01;
YAngle += dY * - speed * 0.01;
vec3 HorizontalAxis = normalize(cross(YAxis, forward));
//rotate forward
forward = normalize(vec3(
cos(XAngle) * sin(YAngle),
sin(XAngle),
cos(XAngle) * cos(YAngle)));
up = normalize(cross(forward, HorizontalAxis));
}
void Camera::onCallback(char button, char action, char mods)
{
switch (button)
{
case 65:
_pos += normalize(cross(up, forward)) * speed;
break;
case 68:
_pos += normalize(cross(forward, up)) * speed;
break;
case 83:
_pos -= speed * forward; //not working
break;
case 87:
_pos += speed * forward; //not working
break;
}
}