Преглед на файлове

Didn't committed changes in light.h/light.c...

Godzil преди 3 години
родител
ревизия
b3850ecf55
променени са 2 файла, в които са добавени 25 реда и са изтрити 0 реда
  1. 10 0
      source/include/light.h
  2. 15 0
      source/light.c

+ 10 - 0
source/include/light.h

@@ -10,12 +10,22 @@
 #ifndef THREEDENGINE_SOURCE_INCLUDE_LIGHT_H
 #define THREEDENGINE_SOURCE_INCLUDE_LIGHT_H
 
+#include <vector.h>
+#include <display.h>
+
 /***********************************************************************************************************************
  * Data types
  **********************************************************************************************************************/
+typedef struct light_t
+{
+    vec3_t direction;
+
+} light_t;
 
 /***********************************************************************************************************************
  * Prototypes
  **********************************************************************************************************************/
+colour_t applyLight(colour_t c, double lightLevel);
+
 
 #endif /* THREEDENGINE_SOURCE_INCLUDE_LIGHT_H */

+ 15 - 0
source/light.c

@@ -7,3 +7,18 @@
  * Created by Manoël Trapier on 06/03/2021.
  */
 
+#include <display.h>
+#include <vector.h>
+#include <light.h>
+
+colour_t applyLight(colour_t c, double lightLevel)
+{
+    if (lightLevel < 0) { lightLevel = 0; }
+    if (lightLevel > 1) { lightLevel = 1; }
+
+    uint8_t r = round(((c >> 16) & 0xFF) * lightLevel);
+    uint8_t g = round(((c >>  8) & 0xFF) * lightLevel);
+    uint8_t b = round(((c     ) & 0xFF) * lightLevel);
+
+    return MAKE_RGB(r, g, b);
+}