-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol_light.c
65 lines (57 loc) · 1.85 KB
/
control_light.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* control_light.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpauw <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/09 14:12:15 by mpauw #+# #+# */
/* Updated: 2018/06/28 08:59:58 by mpauw ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
/*
** For every light, determine the influence it has on every pixel by calling
** set_light_per_pixel.
*/
static t_source *get_source(t_list *lst, int id)
{
t_list *s_lst;
t_source *src;
s_lst = lst;
while (s_lst && s_lst->content)
{
src = (t_source *)s_lst->content;
if (src->type && src->id == id)
return (src);
s_lst = s_lst->next;
}
return (NULL);
}
void *init_light_values(void *arg)
{
t_event *event;
t_list *s_lst;
event = (t_event*)arg;
s_lst = (event->scene).lights;
while (s_lst && s_lst->content)
{
event->src = (t_source *)s_lst->content;
if (event->src->type)
create_threads(event, set_light_per_pixel);
s_lst = s_lst->next;
}
return (NULL);
}
void change_light(t_event *event, int brighter)
{
t_source *src;
src = get_source((event->scene).lights, event->id_select);
if (!src)
return ;
if (brighter)
src->int_factor += 0.05;
else if (src->int_factor >= 0.05)
src->int_factor -= 0.05;
turn_on_lights(event);
}