Repository navigation
Expand file tree
/
Copy pathcamera.cpp
More file actions
83 lines (63 loc) · 1.75 KB
/
Copy pathcamera.cpp
File metadata and controls
83 lines (63 loc) · 1.75 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
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
#include<memory>
#include "camera.h"
#include "controller.h"
std::shared_ptr<CCamera> CCamera::current_attached_camera = nullptr;
glm::mat4 & CCamera::GetProjection()
{
this->_last_get_projection =
glm::perspective(
glm::radians(this->m_perspectiveInfo.fov),
this->m_perspectiveInfo.aspect,
this->m_perspectiveInfo.zNear,
this->m_perspectiveInfo.zFar);
return this->_last_get_projection;
}
glm::mat4 & CCamera::GetModelView()
{
return this->_last_get_modelview;
}
glm::mat4 & CCamera::GetMVP()
{
this->_last_get_mvp = this->GetProjection() * this->GetModelView();
return this->_last_get_mvp;
}
void CCamera::setupControls()
{
}
std::shared_ptr<FrameEventHandler> CCamera::CreateController()
{
auto controller = std::shared_ptr<FrameEventHandler>(new FrameEventHandler());
return controller;
}
CCamera::CCamera()
{
}
glm::mat4 & CFpsCamera::GetModelView()
{
float ryall = glm::radians(this->yall);
float rpitch = glm::radians(this->pitch);
glm::vec3 looktarget(
-sin(ryall)*cos(rpitch) + this->position.x,
sin(rpitch) + this->position.y,
-cos(ryall)*cos(rpitch) + this->position.z);
auto mv = glm::lookAt(this->position, looktarget, glm::vec3(0, 1, 0));
this->_last_get_modelview = mv;
return _last_get_modelview;
}
std::shared_ptr<FrameEventHandler> CFpsCamera::CreateController()
{
auto controller = std::shared_ptr<CFpsCameraController>(new CFpsCameraController);
controller->camera = this;
return std::static_pointer_cast<FrameEventHandler>(controller);
}
PerspectiveInfo::PerspectiveInfo()
{
this->fov = 60;
this->aspect = 1.33;
this->zFar = 1000;
this->zNear = 0.1;
}
FpsCamera camera::CreateFpsCamera()
{
return FpsCamera(new CFpsCamera);
}