-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
56 lines (53 loc) · 1.4 KB
/
Camera.cpp
File metadata and controls
56 lines (53 loc) · 1.4 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
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "Header.h"
#include "Struct_cam.h"
void MoveCamera(Camera& camera) {
float angle = -camera.zAlfa / 180 * M_PI;
float speed = 0;
if (GetKeyState(VK_SPACE) < 0) {
camera.z -= 5.0f;
}
if (GetKeyState(VK_SHIFT) < 0) {
camera.z += 5.0f;
}
if (GetKeyState(VK_UP) < 0) {
camera.xAlfa = ++camera.xAlfa > 180 ? 180 : camera.xAlfa;
speed = 2.0;
}
if (GetKeyState(VK_DOWN) < 0) {
camera.xAlfa = --camera.xAlfa < 0 ? 0 : camera.xAlfa;
speed = -2.0;
}
if (GetKeyState(VK_LEFT) < 0) {
++camera.zAlfa;
speed = 2.0;
angle -= M_PI * 0.5;
}
if (GetKeyState(VK_RIGHT) < 0) {
--camera.zAlfa;
speed = 2.0;
angle += M_PI * 0.5;
}
if (GetKeyState('W') < 0) {
speed = 2.0;
}
if (GetKeyState('S') < 0) {
speed = -2.0;
}
if (GetKeyState('A') < 0) {
speed = 2.0;
angle -= M_PI * 0.5;
}
if (GetKeyState('D') < 0) {
speed = 2.0;
angle += M_PI * 0.5;
}
if (speed != 0) {
camera.pos.x += sin(angle) * speed;
camera.pos.y += cos(angle) * speed;
}
glRotatef(-camera.xAlfa, 1, 0, 0);
glRotatef(-camera.zAlfa, 0, 0, 1);
glTranslatef(-camera.pos.x, -camera.pos.y, camera.z);
}