From 65bed1e65db37e71c0cdef45da3ffe671622b088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:12:13 +0200 Subject: [PATCH] light changing color --- core/lights/DebugLight.h | 3 +++ core/lights/Light.h | 5 +++++ main.cpp | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/core/lights/DebugLight.h b/core/lights/DebugLight.h index a3cc7d8..12f5934 100644 --- a/core/lights/DebugLight.h +++ b/core/lights/DebugLight.h @@ -20,6 +20,9 @@ class DebugLight { auto material = new StandardMaterial(); material->setLightingEnabled(false); material->setAmbientColor(light->color()); + light->onColorChanged.add([material](float r, float g, float b) { + material->setAmbientColor(r, g, b); + }); mesh->setMaterial(material); } diff --git a/core/lights/Light.h b/core/lights/Light.h index c67aeea..e34947b 100644 --- a/core/lights/Light.h +++ b/core/lights/Light.h @@ -8,6 +8,7 @@ #include #include "glm/ext.hpp" +#include "Observable.h" class Light { public: @@ -17,12 +18,16 @@ class Light { _color->x = r; _color->y = g; _color->z = b; + + onColorChanged.notifyObservers(_color->x, _color->y, _color->z); } inline glm::vec3 *color() { return _color; }; float intensity() const { return _intensity; }; + Observable onColorChanged; + private: std::string _name; diff --git a/main.cpp b/main.cpp index c933064..7d4a549 100644 --- a/main.cpp +++ b/main.cpp @@ -114,6 +114,11 @@ int main() { light4.transform()->setPosition( 0.0f, 10.0f * cosf(1.0f * elapsedTime), 10.0f * sinf(1.0f * elapsedTime) ); + light4.setColor( + 0.5f * cosf(1.0f * elapsedTime) + 0.5f, + 0.5f * sinf(1.0f * elapsedTime) + 0.5f, + 0.5f * cosf(1.0f * elapsedTime) + 0.5f + ); camera.setTarget(currentTarget->getMesh()->transform()->position()); camera.setMinRadius(currentTarget->getRadius());