moved colormode to projection added filename check
This commit is contained in:
parent
fc19ce7624
commit
785b542e52
@ -103,7 +103,7 @@ typedef struct s_fdf
|
|||||||
|
|
||||||
int interpolate_color(t_point_2d start,
|
int interpolate_color(t_point_2d start,
|
||||||
t_point_2d end, t_point_2d current);
|
t_point_2d end, t_point_2d current);
|
||||||
int get_color(char *str);
|
int parse_color_string(char *str);
|
||||||
int get_map_sizes(char *filename, t_map *map);
|
int get_map_sizes(char *filename, t_map *map);
|
||||||
void free_line_and_split(char **line, char ***split);
|
void free_line_and_split(char **line, char ***split);
|
||||||
int load_map_from_file(char *filename, t_fdf *fdf);
|
int load_map_from_file(char *filename, t_fdf *fdf);
|
||||||
@ -137,6 +137,9 @@ void close_hook(void *param);
|
|||||||
int get_gradient_color(double z, int z_max);
|
int get_gradient_color(double z, int z_max);
|
||||||
void project_parallel(t_fdf *fdf);
|
void project_parallel(t_fdf *fdf);
|
||||||
void project(t_fdf *fdf);
|
void project(t_fdf *fdf);
|
||||||
|
int get_pixel_color(t_fdf *fdf, t_point_3d point);
|
||||||
|
int check_filename(char *filename);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -19,6 +19,8 @@ int main(int argc, char *argv[])
|
|||||||
fdf = initialise_fdf();
|
fdf = initialise_fdf();
|
||||||
if (argc != 2 )
|
if (argc != 2 )
|
||||||
handle_error(fdf, "Usage: ./fdf <filename>");
|
handle_error(fdf, "Usage: ./fdf <filename>");
|
||||||
|
if(!check_filename(argv[1]))
|
||||||
|
handle_error(fdf, "Error: wrong file extension");
|
||||||
if (!parse_map(argv[1], fdf))
|
if (!parse_map(argv[1], fdf))
|
||||||
handle_error(fdf, "Error: failed to parse map");
|
handle_error(fdf, "Error: failed to parse map");
|
||||||
init_mlx(fdf);
|
init_mlx(fdf);
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "fdf.h"
|
#include "fdf.h"
|
||||||
|
|
||||||
int get_color(char *str)
|
int parse_color_string(char *str)
|
||||||
{
|
{
|
||||||
int color;
|
int color;
|
||||||
int i;
|
int i;
|
||||||
@ -62,12 +62,19 @@ int get_z_color(double z, int z_max)
|
|||||||
{
|
{
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int temp;
|
int blue;
|
||||||
|
|
||||||
temp = 255 * z / z_max;
|
red = 0;
|
||||||
red = temp;
|
green = 0;
|
||||||
green = 255 - temp;
|
blue = 0;
|
||||||
return (red << 24 | green << 16 | 0x00FF);
|
if(z < 0)
|
||||||
|
blue = 127;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
red = 255 * z / z_max;
|
||||||
|
green = 255 - red;
|
||||||
|
}
|
||||||
|
return (red << 24 | green << 16 | blue << 8 | 0x00FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_gradient_color(double z, int z_max)
|
int get_gradient_color(double z, int z_max)
|
||||||
@ -78,3 +85,13 @@ int get_gradient_color(double z, int z_max)
|
|||||||
|
|
||||||
return (colors[(int)(z * 12 / z_max)]);
|
return (colors[(int)(z * 12 / z_max)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_pixel_color(t_fdf *fdf, t_point_3d point)
|
||||||
|
{
|
||||||
|
if (fdf->colormode == COLOR_MODE_Z)
|
||||||
|
return (get_z_color(point.z, fdf->map->z_max));
|
||||||
|
else if (fdf->colormode == COLOR_MODE_GRADIENT)
|
||||||
|
return (get_gradient_color(point.z, fdf->map->z_max));
|
||||||
|
else
|
||||||
|
return (point.color);
|
||||||
|
}
|
||||||
|
|||||||
@ -19,13 +19,7 @@ bool fdf_put_pixel(t_fdf *fdf, t_point_2d point)
|
|||||||
if (point.x < 0 || point.x >= (int) fdf->img->width
|
if (point.x < 0 || point.x >= (int) fdf->img->width
|
||||||
|| point.y < 0 || point.y >= (int) fdf->img->height)
|
|| point.y < 0 || point.y >= (int) fdf->img->height)
|
||||||
return (false);
|
return (false);
|
||||||
if (fdf->colormode == COLOR_MODE_DEFAULT)
|
mlx_put_pixel(fdf->img, point.x, point.y, point.color);
|
||||||
color = point.color;
|
|
||||||
else if (fdf->colormode == COLOR_MODE_Z)
|
|
||||||
color = get_z_color(point.orig_z, fdf->map->z_max);
|
|
||||||
else if (fdf->colormode == COLOR_MODE_GRADIENT)
|
|
||||||
color = get_gradient_color(point.orig_z, fdf->map->z_max);
|
|
||||||
mlx_put_pixel(fdf->img, point.x, point.y, color);
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ void project_trimetric(t_fdf *fdf)
|
|||||||
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].orig_z = fdf->map->orig[i].z;
|
fdf->map->proj[i].orig_z = fdf->map->orig[i].z;
|
||||||
fdf->map->proj[i].color = fdf->map->rot[i].color;
|
fdf->map->proj[i].color = get_pixel_color(fdf, fdf->map->orig[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ void project_parallel(t_fdf *fdf)
|
|||||||
fdf->map->proj[i].x = fdf->map->rot[i].x * fdf->zoom + fdf->offset_x;
|
fdf->map->proj[i].x = fdf->map->rot[i].x * fdf->zoom + fdf->offset_x;
|
||||||
fdf->map->proj[i].y = fdf->map->rot[i].y * fdf->zoom + fdf->offset_y;
|
fdf->map->proj[i].y = fdf->map->rot[i].y * fdf->zoom + fdf->offset_y;
|
||||||
fdf->map->proj[i].orig_z = fdf->map->orig[i].z;
|
fdf->map->proj[i].orig_z = fdf->map->orig[i].z;
|
||||||
fdf->map->proj[i].color = fdf->map->orig[i].color;
|
fdf->map->proj[i].color = get_pixel_color(fdf, fdf->map->orig[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ void project_isometric(t_fdf *fdf)
|
|||||||
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].orig_z = fdf->map->orig[i].z;
|
fdf->map->proj[i].orig_z = fdf->map->orig[i].z;
|
||||||
fdf->map->proj[i].color = fdf->map->rot[i].color;
|
fdf->map->proj[i].color = get_pixel_color(fdf, fdf->map->orig[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,18 @@
|
|||||||
|
|
||||||
#include "fdf.h"
|
#include "fdf.h"
|
||||||
|
|
||||||
|
int check_filename(char *filename)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (filename[i])
|
||||||
|
i++;
|
||||||
|
if (i < 5 || ft_strncmp(&filename[i - 4], ".fdf", 4))
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
int load_map_from_file(char *filename, t_fdf *fdf)
|
int load_map_from_file(char *filename, t_fdf *fdf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -45,5 +57,5 @@ 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].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].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].z = ft_atoi(str[x]);
|
||||||
fdf->map->orig[y * fdf->map->width + x].color = get_color(str[x]);
|
fdf->map->orig[y * fdf->map->width + x].color = parse_color_string(str[x]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user