-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.c
50 lines (45 loc) · 1.65 KB
/
render.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sadamant <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/13 13:32:17 by sadamant #+# #+# */
/* Updated: 2018/03/14 21:36:32 by sadamant ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
static double constrain_cov(t_player *p)
{
if (p->cov < ((-M_PI / 2) + p->fov))
p->cov += (2 * M_PI);
if (p->cov > (2.5 * M_PI) - p->fov / 2)
p->cov -= (2 * M_PI);
return (p->cov);
}
/*
** goes through the entire window and if there's a wall intersection,
** finds the distance of wall to player, and draws the wall.
*/
void render(t_env *e)
{
t_ray *rh;
t_ray *rv;
int x;
double angle;
x = 0;
e->p->cov = constrain_cov(e->p);
angle = e->p->cov + (e->p->fov / 2);
while (angle > e->p->cov - (e->p->fov / 2))
{
rv = cast_vertical(e->world, e->p, angle);
rh = cast_horizontal(e->world, e->p, angle);
e->r = (rh->s < rv->s) ? rh : rv;
draw_wallpiece(e, e->t, e->r, x++);
free(rh);
free(rv);
angle -= e->p->fov / WINDOW_W;
}
print_image(e);
}