-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
94 lines (79 loc) · 1.96 KB
/
Copy pathCamera.cpp
File metadata and controls
94 lines (79 loc) · 1.96 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
84
85
86
87
88
89
90
91
92
93
94
#include "Camera.h"
#include <iostream>
#include "Input.h"
Camera::Camera()
{
position = Vector3(0.0f, 0.0f, 100.0f);
}
Camera::~Camera()
{
}
void Camera::Update()
{
if (!Input::GetKey(Input::Key::Shift))
{
if (Input::GetKey(Input::Key::W))
{
rotation = Quaternion::AngleAxis(camRotSpeed, GetRight()) * GetRotation();
}
else if (Input::GetKey(Input::Key::S))
{
rotation = Quaternion::AngleAxis(-camRotSpeed, GetRight()) * GetRotation();
}
if (Input::GetKey(Input::Key::A))
{
rotation = Quaternion::AngleAxis(camRotSpeed, GetUp()) * GetRotation();
}
else if (Input::GetKey(Input::Key::D))
{
rotation = Quaternion::AngleAxis(-camRotSpeed, GetUp()) * GetRotation();
}
}
else // Panning
{
if (Input::GetKey(Input::Key::W))
{
position += GetUp() * camSpeed;
}
else if (Input::GetKey(Input::Key::S))
{
position += -GetUp() * camSpeed;
}
if (Input::GetKey(Input::Key::A))
{
position += -GetRight() * camSpeed;
}
else if (Input::GetKey(Input::Key::D))
{
position += GetRight() * camSpeed;
}
}
position += GetForward() * Input::GetMouseWheel() * 3.0f;
}
Quaternion Camera::GetRotation()
{
return rotation.Normalized();
}
Vector3 Camera::GetForward()
{
return Vector3(Vector3::Forward * GetRotation().Inversed());
}
Vector3 Camera::GetRight()
{
return Vector3(Vector3::Right * GetRotation().Inversed());
}
Vector3 Camera::GetUp()
{
return Vector3(Vector3::Up * GetRotation().Inversed());
}
Matrix4 Camera::GetProjection() const
{
return glm::perspective(1.6f, 1.0f, 0.5f, 10000.0f);
}
Matrix4 Camera::GetView() const
{
Matrix4 view =
Matrix4::TranslateMatrix(position) *
Matrix4::RotateMatrix(rotation);
return view.Inversed();
}