-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalcul_ray.c
91 lines (83 loc) · 2.84 KB
/
calcul_ray.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* calcul_ray.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaemjeon <jaemjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 15:59:53 by jaemjeon #+# #+# */
/* Updated: 2022/11/13 10:02:35 by jaemjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include <math.h>
void calcul_texture_x_point(t_ray *ray)
{
if (ray->hit_wall_side == EA)
ray->hit_texture_point = ray->hit_idx_y + 1 - ray->hit_point.y;
else if (ray->hit_wall_side == WE)
ray->hit_texture_point = ray->hit_point.y - ray->hit_idx_y;
else if (ray->hit_wall_side == SO)
ray->hit_texture_point = ray->hit_point.x - ray->hit_idx_x;
else
ray->hit_texture_point = ray->hit_idx_x + 1 - ray->hit_point.x;
}
void calcul_hitpoint_dist(t_ray *ray, int last_step, \
t_vector2 *side_dist, t_vector2 *delta_dist)
{
if (last_step == 0)
ray->ray_length = side_dist->x - delta_dist->x;
else
ray->ray_length = side_dist->y - delta_dist->y;
}
void calcul_drawpixel(t_game *game, t_ray *ray, int idx_x)
{
const double ratio_wall = 5 / (ray->wall_distance * 6);
t_vector2 *const wall_line = &game->wall_line[idx_x];
t_vector2_d *const wall_pixel = &game->wall_pixel[idx_x];
wall_line->x = game->info.screen_y / 2 \
- ratio_wall * game->info.screen_y \
- game->player.vertical_dist_pixel;
wall_line->y = game->info.screen_y / 2 \
+ ratio_wall * game->info.screen_y \
- game->player.vertical_dist_pixel;
wall_pixel->x = ceil(wall_line->x);
wall_pixel->y = ceil(wall_line->y);
set_range_int(&wall_pixel->x, 0, game->info.screen_y);
set_range_int(&wall_pixel->y, 0, game->info.screen_y);
}
void get_hit_wall_side(t_ray *ray, int last_step)
{
if (last_step == 0)
{
if (ray->cast_angle < 90 || 270 <= ray->cast_angle)
ray->hit_wall_side = WE;
else
ray->hit_wall_side = EA;
}
else
{
if (ray->cast_angle < 180)
ray->hit_wall_side = NO;
else
ray->hit_wall_side = SO;
}
}
int ray_travel(t_ray *ray, t_vector2 *step, \
t_vector2 *side_dist, t_vector2 *delta_dist)
{
int last_step;
if (side_dist->y < side_dist->x)
{
side_dist->y += delta_dist->y;
ray->hit_idx_y += step->y;
last_step = 1;
}
else
{
side_dist->x += delta_dist->x;
ray->hit_idx_x += step->x;
last_step = 0;
}
return (last_step);
}