fixed some norm errors
This commit is contained in:
parent
54c6cfb9a3
commit
68e9533b91
48
MLX42.supp
Normal file
48
MLX42.supp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/libnvidia*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/libdbus*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/libglfw*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/libX11*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/dri*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
obj:/usr/lib/x86_64-linux-gnu/libLLVM*
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
<MLX42>
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:_dl_open
|
||||||
|
}
|
||||||
@ -26,8 +26,7 @@
|
|||||||
# define SUCCESS 1
|
# define SUCCESS 1
|
||||||
# define FAILURE 0
|
# define FAILURE 0
|
||||||
|
|
||||||
# define WRONG_LINE_LENGTH "Error: wrong line length. \
|
# define WRONG_LINE_LENGTH "Error: wrong line length.\n"
|
||||||
Expected %d, got %d in line nr %d\n"
|
|
||||||
# define MALLOC_ERROR "Error: malloc failed\n"
|
# define MALLOC_ERROR "Error: malloc failed\n"
|
||||||
# define FILE_ERROR "Error: could not open file %s\n"
|
# define FILE_ERROR "Error: could not open file %s\n"
|
||||||
# define USAGE_ERROR "Usage: %s <filename>\n"
|
# define USAGE_ERROR "Usage: %s <filename>\n"
|
||||||
@ -59,7 +58,7 @@ typedef struct s_point_2d
|
|||||||
|
|
||||||
typedef struct s_map
|
typedef struct s_map
|
||||||
{
|
{
|
||||||
t_point_3d *original;
|
t_point_3d *orig;
|
||||||
t_point_3d *rot;
|
t_point_3d *rot;
|
||||||
t_point_2d *proj;
|
t_point_2d *proj;
|
||||||
int width;
|
int width;
|
||||||
@ -113,5 +112,6 @@ t_fdf *initialise_fdf(void);
|
|||||||
bool clean_fdf(t_fdf *fdf);
|
bool clean_fdf(t_fdf *fdf);
|
||||||
void get_z_max(t_fdf *fdf);
|
void get_z_max(t_fdf *fdf);
|
||||||
int init_mlx(t_fdf *fdf);
|
int init_mlx(t_fdf *fdf);
|
||||||
|
void set_map_point(t_fdf *fdf, int x, int y, char **str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
while (i < alle punten)
|
|
||||||
{
|
|
||||||
x' = (x - y) / SQRT2;
|
|
||||||
y' = (x + y - 2 * z) / SQRT6;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -16,7 +16,7 @@ bool clean_fdf(t_fdf *fdf)
|
|||||||
{
|
{
|
||||||
if (fdf->map)
|
if (fdf->map)
|
||||||
{
|
{
|
||||||
free(fdf->map->original);
|
free(fdf->map->orig);
|
||||||
free(fdf->map->rot);
|
free(fdf->map->rot);
|
||||||
free(fdf->map->proj);
|
free(fdf->map->proj);
|
||||||
free(fdf->map);
|
free(fdf->map);
|
||||||
|
|||||||
@ -16,30 +16,24 @@ int get_color(char *str)
|
|||||||
{
|
{
|
||||||
int color;
|
int color;
|
||||||
int i;
|
int i;
|
||||||
|
char *color_str;
|
||||||
|
|
||||||
color = 0;
|
color = 0;
|
||||||
i = 0;
|
i = 1;
|
||||||
if (str[i] && str[i] == '-')
|
color_str = ft_strchr(str, ',');
|
||||||
i++;
|
if (!color_str || *++color_str != '0' || *++color_str != 'x')
|
||||||
while (str[i] && ft_isdigit(str[i]))
|
return (0xFFFFFFFF);
|
||||||
i++;
|
while (color_str[i])
|
||||||
i++;
|
|
||||||
if (str[i] == '0' && str[i + 1] == 'x')
|
|
||||||
i += 2;
|
|
||||||
while (str[i])
|
|
||||||
{
|
{
|
||||||
if (ft_isdigit(str[i]))
|
if (ft_isdigit(color_str[i]))
|
||||||
color = color * 16 + str[i] - '0';
|
color = color * 16 + color_str[i] - '0';
|
||||||
else if (str[i] >= 'a' && str[i] <= 'f')
|
else if (ft_tolower(color_str[i]) >= 'a'
|
||||||
color = color * 16 + str[i] - 'a' + 10;
|
&& ft_tolower(color_str[i]) <= 'f')
|
||||||
else if (str[i] >= 'A' && str[i] <= 'F')
|
color = color * 16 + ft_tolower(color_str[i]) - 'a' + 10;
|
||||||
color = color * 16 + str[i] - 'A' + 10;
|
|
||||||
else
|
else
|
||||||
break ;
|
break ;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (color == 0)
|
|
||||||
return (0xFFFFFFFF);
|
|
||||||
return ((color << 8) + 0xFF);
|
return ((color << 8) + 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,10 @@ void fdf_draw_line_low(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
t_point_2d delta_point;
|
t_point_2d delta_point;
|
||||||
|
|
||||||
delta_point.x = end.x - start.x;
|
delta_point.x = end.x - start.x;
|
||||||
delta_point.y = end.y - start.y;
|
delta_point.y = abs(end.y - start.y);
|
||||||
yi = 1;
|
yi = 1;
|
||||||
if (delta_point.y < 0)
|
if (end.y - start.y < 0)
|
||||||
{
|
|
||||||
yi = -1;
|
yi = -1;
|
||||||
delta_point.y = -delta_point.y;
|
|
||||||
}
|
|
||||||
delta = 2 * delta_point.y - delta_point.x;
|
delta = 2 * delta_point.y - delta_point.x;
|
||||||
current = start;
|
current = start;
|
||||||
while (current.x <= end.x)
|
while (current.x <= end.x)
|
||||||
@ -58,14 +55,11 @@ void fdf_draw_line_high(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
t_point_2d current;
|
t_point_2d current;
|
||||||
t_point_2d delta_point;
|
t_point_2d delta_point;
|
||||||
|
|
||||||
delta_point.x = end.x - start.x;
|
delta_point.x = abs(end.x - start.x);
|
||||||
delta_point.y = end.y - start.y;
|
delta_point.y = end.y - start.y;
|
||||||
xi = 1;
|
xi = 1;
|
||||||
if (delta_point.x < 0)
|
if (end.x - start.x < 0)
|
||||||
{
|
|
||||||
xi = -1;
|
xi = -1;
|
||||||
delta_point.x = -delta_point.x;
|
|
||||||
}
|
|
||||||
delta = 2 * delta_point.x - delta_point.y;
|
delta = 2 * delta_point.x - delta_point.y;
|
||||||
current = start;
|
current = start;
|
||||||
while (current.y <= end.y)
|
while (current.y <= end.y)
|
||||||
|
|||||||
@ -20,6 +20,7 @@ int fdf_hooks(t_fdf *fdf)
|
|||||||
mlx_resize_hook(fdf->mlx, resize_hook, fdf);
|
mlx_resize_hook(fdf->mlx, resize_hook, fdf);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize_hook(int width, int height, void *param)
|
void resize_hook(int width, int height, void *param)
|
||||||
{
|
{
|
||||||
t_fdf *fdf;
|
t_fdf *fdf;
|
||||||
@ -43,7 +44,6 @@ void draw_hook(void *param)
|
|||||||
t_fdf *fdf;
|
t_fdf *fdf;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
fdf = (t_fdf *)param;
|
fdf = (t_fdf *)param;
|
||||||
if (fdf->last_width != fdf->mlx->width
|
if (fdf->last_width != fdf->mlx->width
|
||||||
|| fdf->last_height != fdf->mlx->height)
|
|| fdf->last_height != fdf->mlx->height)
|
||||||
@ -67,6 +67,7 @@ void draw_hook(void *param)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_hook(mlx_key_data_t keydata, void *param)
|
void key_hook(mlx_key_data_t keydata, void *param)
|
||||||
{
|
{
|
||||||
t_fdf *fdf;
|
t_fdf *fdf;
|
||||||
|
|||||||
@ -27,10 +27,10 @@ void copy_map(t_fdf *fdf)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (i < fdf->map->width * fdf->map->height)
|
while (i < fdf->map->width * fdf->map->height)
|
||||||
{
|
{
|
||||||
fdf->map->rot[i].x = fdf->map->original[i].x;
|
fdf->map->rot[i].x = fdf->map->orig[i].x;
|
||||||
fdf->map->rot[i].y = fdf->map->original[i].y;
|
fdf->map->rot[i].y = fdf->map->orig[i].y;
|
||||||
fdf->map->rot[i].z = fdf->map->original[i].z * fdf->z_scale;
|
fdf->map->rot[i].z = fdf->map->orig[i].z * fdf->z_scale;
|
||||||
fdf->map->rot[i].color = fdf->map->original[i].color;
|
fdf->map->rot[i].color = fdf->map->orig[i].color;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ int get_map_sizes(char *filename, t_map *map)
|
|||||||
width = ft_count_words(line, ' ');
|
width = ft_count_words(line, ' ');
|
||||||
free(line);
|
free(line);
|
||||||
if (map->width != 0 && map->width != width)
|
if (map->width != 0 && map->width != width)
|
||||||
return (ft_printf(WRONG_LINE_LENGTH, map->width, width, map->height), 0);
|
return (ft_printf(WRONG_LINE_LENGTH), 0);
|
||||||
else if (map->width == 0)
|
else if (map->width == 0)
|
||||||
map->width = width;
|
map->width = width;
|
||||||
map->height++;
|
map->height++;
|
||||||
|
|||||||
@ -20,8 +20,8 @@ void get_z_max(t_fdf *fdf)
|
|||||||
fdf->map->z_max = 0;
|
fdf->map->z_max = 0;
|
||||||
while (i < fdf->map->width * fdf->map->height)
|
while (i < fdf->map->width * fdf->map->height)
|
||||||
{
|
{
|
||||||
if (fdf->map->original[i].z > fdf->map->z_max)
|
if (fdf->map->orig[i].z > fdf->map->z_max)
|
||||||
fdf->map->z_max = fdf->map->original[i].z;
|
fdf->map->z_max = fdf->map->orig[i].z;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,18 +30,17 @@ t_fdf *initialise_fdf(void)
|
|||||||
fdf->angle_y = 0;
|
fdf->angle_y = 0;
|
||||||
fdf->angle_z = 0;
|
fdf->angle_z = 0;
|
||||||
fdf->zoom = 0;
|
fdf->zoom = 0;
|
||||||
|
fdf->animate_z = 0;
|
||||||
fdf->offset_x = WIDTH / 2;
|
fdf->offset_x = WIDTH / 2;
|
||||||
fdf->offset_y = HEIGHT / 2;
|
fdf->offset_y = HEIGHT / 2;
|
||||||
fdf->z_scale = 0.1;
|
fdf->z_scale = 0.1;
|
||||||
fdf->last_width = WIDTH;
|
fdf->last_width = WIDTH;
|
||||||
fdf->last_height = HEIGHT;
|
fdf->last_height = HEIGHT;
|
||||||
fdf->map->original = NULL;
|
fdf->map->orig = NULL;
|
||||||
fdf->map->rot = NULL;
|
fdf->map->rot = NULL;
|
||||||
fdf->map->proj = NULL;
|
fdf->map->proj = NULL;
|
||||||
fdf->map->width = 0;
|
fdf->map->width = 0;
|
||||||
fdf->map->height = 0;
|
fdf->map->height = 0;
|
||||||
fdf->map->z_max = 0;
|
fdf->map->z_max = 0;
|
||||||
|
|
||||||
|
|
||||||
return (fdf);
|
return (fdf);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,15 +14,17 @@
|
|||||||
|
|
||||||
int parse_map(char *filename, t_fdf *fdf)
|
int parse_map(char *filename, t_fdf *fdf)
|
||||||
{
|
{
|
||||||
|
int map_size;
|
||||||
|
|
||||||
if (!get_map_sizes(filename, fdf->map))
|
if (!get_map_sizes(filename, fdf->map))
|
||||||
handle_error(fdf, "Error: failed to get map sizes");
|
handle_error(fdf, "Error: failed to get map sizes");
|
||||||
fdf->map->original = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
map_size = fdf->map->width * fdf->map->height;
|
||||||
fdf->map->rot = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
fdf->map->orig = malloc(map_size * sizeof(t_point_3d));
|
||||||
fdf->map->proj = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_2d));
|
fdf->map->rot = malloc(map_size * sizeof(t_point_3d));
|
||||||
if (!fdf->map->original || !fdf->map->rot || !fdf->map->proj)
|
fdf->map->proj = malloc(map_size * sizeof(t_point_2d));
|
||||||
|
if (!fdf->map->orig || !fdf->map->rot || !fdf->map->proj)
|
||||||
handle_error(fdf, MALLOC_ERROR);
|
handle_error(fdf, MALLOC_ERROR);
|
||||||
if (!read_map(filename, fdf))
|
if (!read_map(filename, fdf))
|
||||||
handle_error(fdf, "Error: failed to read map");
|
handle_error(fdf, "Error: failed to read map");
|
||||||
|
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,11 +20,13 @@ void project_isometric(t_fdf *fdf)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (fdf->zoom == 0)
|
if (fdf->zoom == 0)
|
||||||
fdf->zoom = fmin(fdf->mlx->width / fdf->map->width, fdf->mlx->height / fdf->map->height) / SQRT2;
|
fdf->zoom = fmin(fdf->mlx->width / fdf->map->width,
|
||||||
|
fdf->mlx->height / fdf->map->height) / SQRT2;
|
||||||
while (i < fdf->map->width * fdf->map->height)
|
while (i < fdf->map->width * fdf->map->height)
|
||||||
{
|
{
|
||||||
x = (fdf->map->rot[i].x - fdf->map->rot[i].y) / SQRT2;
|
x = (fdf->map->rot[i].x - fdf->map->rot[i].y) / SQRT2;
|
||||||
y = (fdf->map->rot[i].x + fdf->map->rot[i].y - 2 * fdf->map->rot[i].z) / SQRT6;
|
y = (fdf->map->rot[i].x + fdf->map->rot[i].y
|
||||||
|
- 2 * fdf->map->rot[i].z) / SQRT6;
|
||||||
fdf->map->proj[i].x = x * fdf->zoom + fdf->offset_x;
|
fdf->map->proj[i].x = x * fdf->zoom + fdf->offset_x;
|
||||||
fdf->map->proj[i].y = y * fdf->zoom + fdf->offset_y;
|
fdf->map->proj[i].y = y * fdf->zoom + fdf->offset_y;
|
||||||
fdf->map->proj[i].color = fdf->map->rot[i].color;
|
fdf->map->proj[i].color = fdf->map->rot[i].color;
|
||||||
|
|||||||
@ -20,7 +20,6 @@ int read_map(char *filename, t_fdf *fdf)
|
|||||||
int x;
|
int x;
|
||||||
char **split;
|
char **split;
|
||||||
|
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
handle_error(NULL, FILE_ERROR);
|
handle_error(NULL, FILE_ERROR);
|
||||||
@ -33,16 +32,18 @@ int read_map(char *filename, t_fdf *fdf)
|
|||||||
break ;
|
break ;
|
||||||
split = ft_split(line, ' ');
|
split = ft_split(line, ' ');
|
||||||
while (split[x])
|
while (split[x])
|
||||||
{
|
set_map_point(fdf, x++, y, split);
|
||||||
fdf->map->original[y * fdf->map->width + x].x = x - fdf->map->width / 2;
|
|
||||||
fdf->map->original[y * fdf->map->width + x].y = fdf->map->height / 2 - y;
|
|
||||||
fdf->map->original[y * fdf->map->width + x].z = ft_atoi(split[x]);
|
|
||||||
fdf->map->original[y * fdf->map->width + x].color = get_color(split[x]);
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
free_line_and_split(&line, &split);
|
free_line_and_split(&line, &split);
|
||||||
y--;
|
y--;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_map_point(t_fdf *fdf, int x, int y, char **str)
|
||||||
|
{
|
||||||
|
fdf->map->orig[y * fdf->map->width + x].x = x - fdf->map->width / 2;
|
||||||
|
fdf->map->orig[y * fdf->map->width + x].y = fdf->map->height / 2 - y;
|
||||||
|
fdf->map->orig[y * fdf->map->width + x].z = ft_atoi(str[x]);
|
||||||
|
fdf->map->orig[y * fdf->map->width + x].color = get_color(str[x]);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user