-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.cpp
34 lines (27 loc) · 1009 Bytes
/
Light.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Light.h"
static light_t light =
{
.direction = { 0, 0, 1 }
};
void init_light(vec3_t direction)
{
light.direction = direction;
}
vec3_t get_light_direction(void)
{
return light.direction;
}
///////////////////////////////////////////////////////////////////////////////
// Change color based on a percentage factor to represent light intensity
///////////////////////////////////////////////////////////////////////////////
uint32_t light_apply_intensity(uint32_t original_color, float percentage_factor)
{
if (percentage_factor < 0) percentage_factor = 0;
if (percentage_factor > 1) percentage_factor = 1;
uint32_t a = (original_color & 0xFF000000);
uint32_t r = (original_color & 0x00FF0000) * percentage_factor;
uint32_t g = (original_color & 0x0000FF00) * percentage_factor;
uint32_t b = (original_color & 0x000000FF) * percentage_factor;
uint32_t new_color = a | (r & 0x00FF0000) | (g & 0x0000FF00) | (b & 0x000000FF);
return new_color;
}