From 0e3c3cb0ebdb641f71d356aab98b8f2aca675d2a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 26 May 2023 15:48:45 +0200 Subject: light: intensity should be a 2d vector It's a vector in order to provide an approximation of area lighting without actually implementing them. --- src/light.cpp | 11 ++++++++--- src/light.hpp | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/light.cpp b/src/light.cpp index ed7c4ae1..ed9469f2 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -43,14 +43,19 @@ bool light::update(size_t, float) { return false; } bool light::is_dynamic() const { return true; } bool light::is_virtual() const { return true; } -float light::calc_intensity(float half_dist, light_falloff falloff) +Vector2 light::intensity(Vector2 half_dist, light_falloff falloff) { switch (falloff) { case light_falloff::linear: return 2 * half_dist; - case light_falloff::quadratic: return std::sqrt(2 * half_dist); - default: case light_falloff::constant: return 1; + case light_falloff::quadratic: return Vector2{std::sqrt(2 * half_dist.x()), std::sqrt(2 * half_dist.y())}; + default: case light_falloff::constant: return Vector2{1, 1}; } } +Vector2 light::intensity() const +{ + return intensity(half_dist, falloff); +} + } // namespace floormat diff --git a/src/light.hpp b/src/light.hpp index 15dbc7c6..e228c8b5 100644 --- a/src/light.hpp +++ b/src/light.hpp @@ -37,7 +37,8 @@ struct light final : entity bool is_dynamic() const override; bool is_virtual() const override; - static float calc_intensity(float half_dist, light_falloff falloff); + static Vector2 intensity(Vector2 half_dist, light_falloff falloff); + Vector2 intensity() const; friend struct world; }; -- cgit v1.2.3