correction z negatifs pour colros

This commit is contained in:
hugogogo
2021-07-24 16:36:44 +02:00
parent 04ef5aab68
commit 331e1f3388
193 changed files with 23 additions and 6095 deletions

View File

@@ -76,10 +76,10 @@ void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z)
color = 0xffffff;
z -= (z * fdf->zoom) / fdf->offset;
z /= fdf->altitude;
if (fdf->max_z)
if (z > fdf->min_z && fdf->z_amplitude)
{
color = color ^ (((0xff / fdf->max_z) * z) << 8 );
color = color ^ ((0xff / fdf->max_z) * z);
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 16);
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 0);
}
draw_pixel(fdf, new_x, new_y, color);
}

View File

@@ -18,6 +18,7 @@ t_fdf *init_fdf(t_fdf *fdf)
fdf->offset = 50;
fdf->margin = 50;
fdf->altitude = 3;
fdf->z_amplitude = fdf->max_z - fdf->min_z;
fdf->map_size_x = (fdf->map_width - 1) * fdf->offset + 1;
fdf->map_size_y = (fdf->map_height - 1) * fdf->offset + 1;
fdf->win_size_x = fdf->map_size_x + 2 * fdf->margin;

View File

@@ -1,31 +1,35 @@
#include "fdf.h"
void z_amplitude(t_fdf*fdf, int i)
{
if (i > fdf->max_z)
fdf->max_z = i;
if (i < fdf->min_z)
fdf->min_z = i;
}
int **split_to_map(t_fdf *fdf, char *raw)
{
int i;
int j;
int z;
int **map;
map = ft_calloc(fdf->map_height, sizeof(map));
i = -1;
z = 0;
while (++i < fdf->map_height)
{
map[i] = ft_calloc(fdf->map_width, sizeof(*map));
j = -1;
while (++j < fdf->map_width)
{
while (!ft_isdigit(*raw))
while (*raw == ' ' || *raw == '!')
raw++;
map[i][j] = ft_atoi(raw);
while (ft_isdigit(*raw))
while (ft_isdigit(*raw) || *raw == '-')
raw++;
if (map[i][j] > z)
z = map[i][j];
z_amplitude(fdf, map[i][j]);
}
}
fdf->max_z = z;
return (map);
}
@@ -39,6 +43,8 @@ int size_width(char *raw)
{
while (raw[i] == ' ')
i++;
if (raw[i] == '-')
i++;
while (ft_isdigit(raw[i]))
i++;
j++;
@@ -69,5 +75,7 @@ int **parse_map(t_fdf *fdf, int fd)
}
fdf->map_height = height;
fdf->map_width = size_width(raw);
fdf->min_z = 0;
fdf->max_z = 0;
return (split_to_map(fdf, raw));
}