-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
60 lines (48 loc) · 1.12 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
#include "Camera.h"
#include <glm/gtc/matrix_transform.hpp>
Camera::Camera(const vec3& positionVector, const vec3& scaleVector) : SceneObject(positionVector, scaleVector), fieldOfView(glm::radians(90.0f)), zNear(0.1f), zFar(100.0f)
{
}
Camera::~Camera()
{
}
float Camera::GetFieldOfView() const
{
return fieldOfView;
}
float Camera::GetNearPosition() const
{
return zNear;
}
float Camera::GetFarPosition() const
{
return zFar;
}
mat4 Camera::GetViewMatrix() const
{
return glm::lookAt(position, position + this->Forward(), Up());
}
mat4 Camera::GetProjectionMatrix(float aspectRatio) const
{
return glm::perspective(fieldOfView, aspectRatio, zNear, zFar);
}
void Camera::ZoomIn(float angle)
{
fieldOfView -= angle;
if (fieldOfView < glm::radians(1.0f))
fieldOfView = glm::radians(1.0f);
if (fieldOfView > glm::radians(120.0f))
fieldOfView = glm::radians(120.0f);
}
void Camera::ZoomOut(float angle)
{
ZoomIn(-angle);
}
void Camera::SetClippingPlanes(float zNear, float zFar)
{
if (zNear > 0 && zFar > zNear)
{
this->zNear = zNear;
this->zFar = zFar;
}
}