-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlights.cpp
More file actions
119 lines (110 loc) · 3.22 KB
/
lights.cpp
File metadata and controls
119 lines (110 loc) · 3.22 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <lights.hpp>
#include <algorithm>
#include <GLFW/glfw3.h>
LightManager::LightManager() {
for (int i = 0; i < MAX_LIGHTS; i++)
{
this->lightStates[i] = true; // all ON by default
}
}
void LightManager::initFromScene(vector<GameObject*>& sceneObjects) {
this->lights.clear();
for (GameObject* obj : sceneObjects) {
if(obj->lightID != -1) {
this->lights.push_back(obj);
}
}
// sort the lights but their lightID
std::sort(this->lights.begin(), this->lights.end(),
[](GameObject* a, GameObject* b) {
return a->lightID < b->lightID;
});
//this->lightStates = vector<bool>(this->lights.size(), true); // all ON by default
return;
}
void LightManager::toggleLight(int lightIndex) {
if (lightIndex >= 0 && lightIndex < MAX_LIGHTS) {
this->lightStates[lightIndex] = !this->lightStates[lightIndex]; // toggle
}
}
glm::vec3 LightManager::getLightPosition(int lightIndex) {
if (lightIndex >= 0 && lightIndex < this->lights.size()) {
return glm::vec3(this->lights[lightIndex]->objectCenter);
}
return glm::vec3(1, 1, 1);
}
void setLights(LightManager& lightManager, GLFWwindow* window,vector<bool>& keyPressed) {
// Toggle ith light with key 'i'
// light 1 num 1
if(glfwGetKey(window,GLFW_KEY_1) == GLFW_PRESS && !keyPressed[0]) {
lightManager.toggleLight(0);
keyPressed[0] = true;
}
else if (glfwGetKey(window, GLFW_KEY_1) == GLFW_RELEASE) {
keyPressed[0] = false;
}
// light 2 num 2
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && !keyPressed[1]) {
lightManager.toggleLight(1);
keyPressed[1] = true;
}
else if (glfwGetKey(window, GLFW_KEY_2) == GLFW_RELEASE) {
keyPressed[1] = false;
}
// light 3 num 3
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS && !keyPressed[2]) {
lightManager.toggleLight(2);
keyPressed[2] = true;
}
else if (glfwGetKey(window, GLFW_KEY_3) == GLFW_RELEASE) {
keyPressed[2] = false;
}
// light 4 num 4
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS && !keyPressed[3]) {
lightManager.toggleLight(3);
keyPressed[3] = true;
}
else if (glfwGetKey(window, GLFW_KEY_4) == GLFW_RELEASE) {
keyPressed[3] = false;
}
// light 5 num 5
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS && !keyPressed[4]) {
lightManager.toggleLight(4);
keyPressed[4] = true;
}
else if (glfwGetKey(window, GLFW_KEY_5) == GLFW_RELEASE) {
keyPressed[4] = false;
}
// light 6 num 6
if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS && !keyPressed[5]) {
lightManager.toggleLight(5);
keyPressed[5] = true;
}
else if (glfwGetKey(window, GLFW_KEY_6) == GLFW_RELEASE) {
keyPressed[5] = false;
}
// light 7 num 7
if (glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS && !keyPressed[6]) {
lightManager.toggleLight(6);
keyPressed[6] = true;
}
else if (glfwGetKey(window, GLFW_KEY_7) == GLFW_RELEASE) {
keyPressed[6] = false;
}
// light 8 num 8
if (glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS && !keyPressed[7]) {
lightManager.toggleLight(7);
keyPressed[7] = true;
}
else if (glfwGetKey(window, GLFW_KEY_8) == GLFW_RELEASE) {
keyPressed[7] = false;
}
// light 9 num 9
if (glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS && !keyPressed[8]) {
lightManager.toggleLight(8);
keyPressed[8] = true;
}
else if (glfwGetKey(window, GLFW_KEY_9) == GLFW_RELEASE) {
keyPressed[8] = false;
}
}