optimisation when close to wall

This commit is contained in:
kinou-p 2022-06-06 21:33:47 +02:00
parent 537c73b02c
commit ae3d45cbba
2 changed files with 16 additions and 6 deletions

View File

@ -122,9 +122,12 @@ void draw_ray3d(t_data *img, ray ray)
int texture_size = 64; int texture_size = 64;
line_height = img->map.size * 960 / ray.dist; line_height = img->map.size * 960 / ray.dist;
if (line_height > 5000) //if (line_height > 5000)
line_height = 5000; // line_height = 5000;
line_offset = 256 - line_height / 2; //if (line_height > 5000)
// line_height = 5000;
//printf("ray dist= %f line height= %f\n", ray.dist, line_height);
line_offset = 256 - ((int)line_height) / 2;
double gap = 1; double gap = 1;
double myy = 0; double myy = 0;
y = 0; y = 0;
@ -132,8 +135,15 @@ void draw_ray3d(t_data *img, ray ray)
myy = 0; myy = 0;
gap = (texture_size / line_height); gap = (texture_size / line_height);
mx = ((int)ray.mp) % texture_size; mx = ((int)ray.mp) % texture_size;
while (y < line_height - 8) if (line_height > 512)
{ {
line_offset = 0;
myy = gap * ((line_height - 512) / 2);
}
while (y < line_height - 8 && y < 512)
{
//if (line_height > 512)
// int diff = line_height - 512 \ 2;
myy += gap; myy += gap;
my = (int)myy;//gap; my = (int)myy;//gap;
ray.pixel = ((my) * texture_size + mx)* 3 + 1; ray.pixel = ((my) * texture_size + mx)* 3 + 1;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */ /* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
/* Updated: 2022/05/20 14:11:29 by apommier ### ########.fr */ /* Updated: 2022/06/06 21:31:30 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,7 +30,7 @@ unsigned char *get_texture(int type)
swap = get_next_line(fd); swap = get_next_line(fd);
} }
close(fd); close(fd);
printf("count= %d\n", count); //printf("count= %d\n", count);
ret = ft_calloc(sizeof(char), count); ret = ft_calloc(sizeof(char), count);
fd = open("./sprite/brick_wall.ppm", O_RDONLY); fd = open("./sprite/brick_wall.ppm", O_RDONLY);
if (!ret) if (!ret)