Skip to content

Commit

Permalink
light changing color
Browse files Browse the repository at this point in the history
  • Loading branch information
BarthPaleologue committed Sep 27, 2023
1 parent c635a17 commit 65bed1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/lights/DebugLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions core/lights/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <string>
#include "glm/ext.hpp"
#include "Observable.h"

class Light {
public:
Expand All @@ -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<float, float, float> onColorChanged;

private:
std::string _name;

Expand Down
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 65bed1e

Please sign in to comment.