-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathray_tracing.c
56 lines (51 loc) · 1.83 KB
/
ray_tracing.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ray_tracing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajaehaer <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/17 19:02:14 by ajaehaer #+# #+# */
/* Updated: 2019/03/27 20:26:34 by ajaehaer ### ########.fr */
/* */
/* ************************************************************************** */
#include "engine_render.h"
static void get_rays(t_ray *rays, t_camera camera, int width, int height)
{
int i;
int n_rays;
t_4x4matrix rotation;
i = -1;
n_rays = width * height;
rotation = matrix_mul(
get_rotation_matrix_x(-camera.polar_angle),
get_rotation_matrix_z(-camera.azimuthal_angle));
while (++i < n_rays)
{
rays[i].origin = camera.position;
rays[i].direction = normalize(
vector_matrix_mul(
(t_vector){
-(i % width - width / 2),
camera.focus,
-(i / width - height / 2),
0.},
rotation));
}
}
void ray_tracing(t_render *render)
{
int i;
i = -1;
clear_pixels_buffer(render);
get_rays(render->rays, render->camera,
render->window_width, render->window_height);
while (++i < render->window_width * render->window_height &&
render->path_tracing == 0)
{
render->pixels[i].color = vector_sum(
render->pixels[i].color,
trace_ray(render, render->rays[i], 5));
render->pixels[i].divider += 1;
}
}