-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojection.c
52 lines (47 loc) · 1.92 KB
/
projection.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* projection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahamdaou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/31 10:02:43 by ahamdaou #+# #+# */
/* Updated: 2021/01/22 18:54:42 by ahamdaou ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static void projection(t_ray *ray, int col)
{
t_wall wall;
wall.correct_wall_distance =
ray->distance * cos(ray->ray_angle - g_player.rotation_angle);
if (wall.correct_wall_distance == 0)
return ;
wall.distance_proj_plane = (g_game.win_width / 2) / tan(FOV_ANGLE / 2);
wall.wall_strip_height =
(TILE_SIZE / wall.correct_wall_distance) * wall.distance_proj_plane;
wall.wall_top_pixel =
(g_game.win_height / 2 + g_player.look)
- ((wall.wall_strip_height / 2));
wall.wall_top_pixel = (wall.wall_top_pixel < 0) ? 0 : wall.wall_top_pixel;
wall.wall_bottom_pixel =
(g_game.win_height / 2 + g_player.look)
+ ((wall.wall_strip_height / 2));
wall.wall_bottom_pixel = (wall.wall_bottom_pixel > g_game.win_height) ?
g_game.win_height : wall.wall_bottom_pixel;
ceilling_projection(col, &wall);
settexture(ray);
wall_projection(col, ray, &wall);
floor_projection(col, &wall);
}
void render_projection_walls(void)
{
int col;
t_ray *ray;
col = -1;
while (++col < g_game.num_rays)
{
ray = rays()[col];
projection(ray, col);
}
}