-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCamera.cpp
More file actions
97 lines (88 loc) · 2.24 KB
/
Camera.cpp
File metadata and controls
97 lines (88 loc) · 2.24 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
95
96
97
#include "Camera.h"
Camera::Camera()
{
this->position = Point3D::Create(0, 0, 0);
this->rotation = Point3D::Create(0, 0, 0);
leftPressed = false;
rightPressed = false;
aPressed = false;
wPressed = false;
sPressed = false;
dPressed = false;
}
Camera::Camera(Point3D position, Point3D rotation)
{
this->position = position;
this->rotation = rotation;
leftPressed = false;
rightPressed = false;
aPressed = false;
wPressed = false;
sPressed = false;
dPressed = false;
}
void Camera::HandleKeyDown(WPARAM wParam)
{
if (wParam == VK_LEFT)
leftPressed = true;
if (wParam == VK_RIGHT)
rightPressed = true;
if (wParam == 0x41) // A Key
aPressed = true;
if (wParam == 0x57) // W key
wPressed = true;
if (wParam == 0x53) // S Key
sPressed = true;
if (wParam == 0x44) // D key
dPressed = true;
}
void Camera::HandleKeyUp(WPARAM wParam)
{
if (wParam == VK_LEFT)
leftPressed = false;
if (wParam == VK_RIGHT)
rightPressed = false;
if (wParam == 0x41) // A Key
aPressed = false;
if (wParam == 0x57) // W key
wPressed = false;
if (wParam == 0x53) // S Key
sPressed = false;
if (wParam == 0x44) // D key
dPressed = false;
}
void Camera::Logic(double elapsedTime)
{
if (wPressed)
{
this->position.z += 10000 * cos(this->rotation.y) * elapsedTime;
this->position.x += 10000 * sin(this->rotation.y) * elapsedTime;
}
if (sPressed)
{
this->position.z -= 10000 * cos(this->rotation.y) * elapsedTime;
this->position.x -= 10000 * sin(this->rotation.y) * elapsedTime;
}
if (aPressed)
{
this->position.z += 10000 * sin(this->rotation.y) * elapsedTime;
this->position.x -= 10000 * cos(this->rotation.y) * elapsedTime;
}
if (dPressed)
{
this->position.z -= 10000 * sin(this->rotation.y) * elapsedTime;
this->position.x += 10000 * cos(this->rotation.y) * elapsedTime;
}
if (leftPressed)
this->rotation.y -= elapsedTime;
if (rightPressed)
this->rotation.y += elapsedTime;
}
Point3D Camera::GetPosition()
{
return position;
}
Point3D Camera::GetRotation()
{
return rotation;
}