-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_t_values.c
93 lines (84 loc) · 2.67 KB
/
set_t_values.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_s_values.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpauw <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/08 13:38:46 by mpauw #+# #+# */
/* Updated: 2018/06/27 16:21:03 by mpauw ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
/*
** Some preparations to get the first visible object for this pixel.
*/
static void get_value(t_scene scene, t_pixel *p)
{
t_3v dir;
t_p_info *pi;
p->c_per_src[0] = ft_zero_3v();
dir = p->coor;
dir = normalize(rotate_v(dir, (scene.cam)->rotation));
p->type = 0;
p->index_refract = 1.0;
get_reflections(p, scene, dir);
pi = p->pi_arr[0];
if (!(pi->vis_obj))
return ;
}
/*
** Initializing all variables in t_pixel.
*/
static void setup_pixel(t_pixel *p, t_scene scene, int i, int j)
{
if (scene.refl < 0)
scene.refl = 0;
if (!(p->c_per_src = (t_3v *)malloc(sizeof(t_3v)
* (scene.amount_light + 1))))
error(1);
if (!(p->pi_arr = (t_p_info **)malloc(sizeof(t_p_info *))))
error(1);
p->color = ft_zero_3v();
p->amount_p = 0;
p->amount_refl = 0;
p->has_vis_obj = 0;
(scene.cam)->pixel_set[j + scene.width * scene.max_anti_a * i] = 1;
(p->coor).v[0] = -(scene.width / 2);
(p->coor).v[1] = (double)((double)j / scene.max_anti_a - scene.width
/ 2.0);
(p->coor).v[2] = (double)(scene.height / 2.0 - (double)i
/ scene.max_anti_a);
get_value(scene, p);
}
/*
** Looping through pixels (based on grain size), finding visible object(s) per
** pixel.
*/
void *set_t_values(void *arg)
{
t_pixel *p;
t_event *e;
int i;
int j;
int factor;
e = (t_event *)arg;
factor = e->scene.max_anti_a;
i = ((e->scene.height * factor / THREADS) * e->scene.thread_id);
while (i < (e->scene.height * factor / THREADS) * (e->scene.thread_id + 1))
{
j = 0;
while (j < e->scene.width * factor)
{
if (!(e->scene.cam)->pixel_set[j + i * e->scene.width * factor])
{
p = &((e->scene.cam)->p_array[j + i * e->scene.width * factor]);
setup_pixel(p, e->scene, i, j);
}
j += e->scene.step_size;
}
i += e->scene.step_size;
}
(e->scene.cam)->init = 1;
return (NULL);
}