diff --git a/src/Controller.cpp b/src/Controller.cpp index 24ced32..43f8346 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -114,6 +114,8 @@ void Controller::run() { Scene scene(&shaderProgram); scene.addEntity(dragon); scene.addEntity(lightSource); + + scene.updateLight(0, lightSource.getPosition(), glm::vec3(1.0f)); camera->translate(glm::vec3(0.0f, 0.0f, 7.5f)); @@ -134,7 +136,7 @@ void Controller::run() { scene.drawScene(camera->getViewProj(), camera->getPosition()); #ifdef _DEBUG - renderImGui(scene.getEntities().data()); + renderImGui(scene.getEntities()); #endif glfwSwapBuffers(gameWindow->getGLFWwindow()); @@ -188,7 +190,7 @@ void Controller::updateWindowSize() { } #ifdef _DEBUG -void Controller::renderImGui(Entity *entity) { +void Controller::renderImGui(std::vector *entites) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); @@ -203,7 +205,7 @@ void Controller::renderImGui(Entity *entity) { ImGui::SliderFloat2("Position", translation, -4.0, 4.0); static float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - entity->setPosition(glm::vec3(translation[0], 0.0f, translation[1])); + entites->operator[](0).setPosition(glm::vec3(translation[0], 0.0f, translation[1])); //entity->setRotation() // color picker diff --git a/src/Controller.h b/src/Controller.h index f21f7b6..833ad2c 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -27,7 +27,7 @@ private: void updateWindowSize(); - void renderImGui(Entity *entity); + void renderImGui(std::vector *entites); Window *gameWindow; EventHandler *gameEventHandler; diff --git a/src/Light.cpp b/src/Light.cpp index cbb9ac1..629a30f 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -5,8 +5,6 @@ PointLight::PointLight(ShaderProgram *shaderProgram) : Light(shaderProgram) { - isActive = false; - } void PointLight::update() { diff --git a/src/Light.h b/src/Light.h index ab2c4d7..af17fcd 100644 --- a/src/Light.h +++ b/src/Light.h @@ -13,6 +13,10 @@ public: virtual void update() = 0; void setActive(bool active) { isActive = active; } + void setColor(glm::vec3 color) { + lightColor = color; + update(); + } void setShaderProgram(ShaderProgram *shaderProgram) { this->shaderProgram = shaderProgram; update(); @@ -25,7 +29,7 @@ protected: ShaderProgram *shaderProgram; - bool isActive; + bool isActive = false; // Color glm::vec3 lightColor = glm::vec3(1.0f, 1.0f, 1.0f); @@ -46,6 +50,7 @@ public: this->position = position; update(); } + void setId(unsigned int id) { lightId = id; } void update(); diff --git a/src/Scene.cpp b/src/Scene.cpp index d5a40f6..61cc42a 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -10,11 +10,10 @@ Scene::Scene(ShaderProgram *shaderProgram) : shaderProgram(shaderProgram) { for(unsigned int i = 0; i < NUM_POINT_LIGHTS; i++) { + pointLights[i].setId(i); pointLights[i].setShaderProgram(shaderProgram); } - pointLights[0].setActive(true); - } void Scene::addEntity(Entity entity) { @@ -31,7 +30,13 @@ void Scene::removeEntity(uint32_t id) { } } - std::cout << "[Warning] No Entity found with ID " << id << std::endl; + std::cout << "[Warning] Entity with ID " << id << " could not be removed." << std::endl; +} + +void Scene::updateLight(unsigned int lightId, glm::vec3 position, glm::vec3 color) { + pointLights[lightId].setActive(true); + pointLights[lightId].setPosition(position); + pointLights[lightId].setColor(color); } void Scene::drawScene(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) { diff --git a/src/Scene.h b/src/Scene.h index 20ca2c8..29f7d6c 100644 --- a/src/Scene.h +++ b/src/Scene.h @@ -16,7 +16,9 @@ public: void addEntity(Entity entity); void removeEntity(uint32_t id); - std::vector getEntities() { return entities; } + void updateLight(unsigned int lightId, glm::vec3 position, glm::vec3 color); + + std::vector * getEntities() { return &entities; } void drawScene(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);