translade code from macos to linux

This commit is contained in:
Gregory 2017-03-15 11:23:05 +02:00
parent 6569da5710
commit 66634b039e
6 changed files with 50 additions and 39 deletions

View file

@ -15,12 +15,11 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
# define HEIGHT 1000 # define HEIGHT 1300
# define WIDTH 1000 # define WIDTH 2500
# define BPP 32 # define ENDIAN 0
# define ENDIAN 1 # define COLOR1 16515072
# define COLOR1 2604805 # define COLOR2 252
# define COLOR2 12518661
# define INIT_X 30 # define INIT_X 30
# define INIT_Y -20 # define INIT_Y -20
# define INIT_Z -45 # define INIT_Z -45
@ -155,7 +154,7 @@ t_color color_init(int red, int green, int blue);
t_color color_lerp(t_color c1, t_color c2, float step); t_color color_lerp(t_color c1, t_color c2, float step);
t_color int_to_color(int c); t_color int_to_color(int c);
int color_to_int(t_color c); int color_to_int(t_color c);
t_color choose_color(t_line *line, t_swap *s, t_FDF *FDF); t_color choose_color(t_line *line, t_swap *s);
void first_color(t_pnt *pnt, float z, t_map *map); void first_color(t_pnt *pnt, float z, t_map *map);
t_mw *mlx_and_win_ptr_init(int x, int y); t_mw *mlx_and_win_ptr_init(int x, int y);
@ -175,5 +174,6 @@ void scale_up_z(t_FDF *FDF);
void scale_down_z(t_FDF *FDF); void scale_down_z(t_FDF *FDF);
void zoom_in(t_FDF *FDF); void zoom_in(t_FDF *FDF);
void zoom_out(t_FDF *FDF); void zoom_out(t_FDF *FDF);
void reset(t_FDF *FDF);
#endif #endif

View file

@ -22,11 +22,8 @@ t_FDF *FDF_init(char *path)
pnt_init(FDF->map); pnt_init(FDF->map);
FDF->w_height = HEIGHT; FDF->w_height = HEIGHT;
FDF->w_width = WIDTH; FDF->w_width = WIDTH;
FDF->bpp = BPP;
FDF->line_size = WIDTH;
FDF->endian = ENDIAN;
FDF->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT); FDF->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT);
FDF->image = mlx_new_image(FDF->mw->mlx, FDF->w_height, FDF->w_height); FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT);
FDF->image_data = mlx_get_data_addr( FDF->image_data = mlx_get_data_addr(
FDF->image, FDF->image,
&FDF->bpp, &FDF->bpp,

View file

@ -12,15 +12,9 @@ void put_pixel_to_image(t_line *line, t_swap *s, t_FDF *FDF)
y = line->p1.x; y = line->p1.x;
x = line->p1.y; x = line->p1.y;
} }
if (x < 0) if (x < 0 || y < 0 || x >= FDF->w_width || y >= FDF->w_height)
x = 0; return ;
if (x > FDF->w_width) *(int *)((FDF->image_data + x * FDF->bpp / 8 + y * FDF->line_size)) =
x = FDF->w_width; color_to_int(choose_color(line, s));
if (y < 0)
y = 0;
if (y > FDF->w_height)
y = FDF->w_height;
*((int *)FDF->image_data + x + y * FDF->w_width) = color_to_int(
choose_color(line, s, FDF));
} }

View file

@ -1,14 +1,30 @@
#include "fdf.h" #include "fdf.h"
void parse_input(int ac, char **av)
{
if (ac == 2 && ft_strstr(av[1], "--help"))
{
print_help();
}
if (ac == 4 && ft_strstr(av[1], "--heatmap"))
{
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
t_FDF *FDF; t_FDF *FDF;
// int i = 0;
if (argc < 2) if (argc < 2 && argc > 4)
{ {
print_help(); print_help();
return (0); return (0);
} }
else if (argc < 4)
{
parse_input(argc, argv);
}
FDF = FDF_init(argv[1]); FDF = FDF_init(argv[1]);
center(FDF->map); center(FDF->map);
FDF->map->trnsf = initial_trnsf_mats(FDF); FDF->map->trnsf = initial_trnsf_mats(FDF);
@ -16,14 +32,7 @@ int main(int argc, char **argv)
mat4_mult_chain(FDF); mat4_mult_chain(FDF);
transform(FDF->map->trnsf->fin, FDF->map); transform(FDF->map->trnsf->fin, FDF->map);
render(FDF); render(FDF);
// sleep(10); mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF);
// while (i < 360)
// {
// usleep(15000);
// clock_rot(FDF);
// i++;
// }
mlx_key_hook(FDF->mw->win, key_hook, FDF);
mlx_loop(FDF->mw->mlx); mlx_loop(FDF->mw->mlx);
return (0); return (0);
} }

View file

@ -75,7 +75,7 @@ t_map *map_init(char *path)
map->scale[2] = 1; map->scale[2] = 1;
if (!(str_map = to_str_map(path))) if (!(str_map = to_str_map(path)))
{ {
ft_putstr("Wrong path to a map! For help help put \"fdf --help\""); ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n");
quit(0); quit(0);
} }
tab_map = ft_strsplit(str_map, '\n'); tab_map = ft_strsplit(str_map, '\n');

View file

@ -6,7 +6,7 @@ void move(t_FDF *FDF)
mat4_mult_chain(FDF); mat4_mult_chain(FDF);
transform(FDF->map->trnsf->fin, FDF->map); transform(FDF->map->trnsf->fin, FDF->map);
mlx_destroy_image(FDF->mw->mlx, FDF->image); mlx_destroy_image(FDF->mw->mlx, FDF->image);
FDF->image = mlx_new_image(FDF->mw->mlx, FDF->w_height, FDF->w_height); FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT);
FDF->image_data = mlx_get_data_addr( FDF->image_data = mlx_get_data_addr(
FDF->image, FDF->image,
&FDF->bpp, &FDF->bpp,
@ -17,37 +17,37 @@ void move(t_FDF *FDF)
void left_rot(t_FDF *FDF) void left_rot(t_FDF *FDF)
{ {
FDF->map->y_rot -= 2; FDF->map->y_rot -= 1;
move(FDF); move(FDF);
} }
void right_rot(t_FDF *FDF) void right_rot(t_FDF *FDF)
{ {
FDF->map->y_rot += 2; FDF->map->y_rot += 1;
move(FDF); move(FDF);
} }
void forw_rot(t_FDF *FDF) void forw_rot(t_FDF *FDF)
{ {
FDF->map->x_rot += 2; FDF->map->x_rot += 1;
move(FDF); move(FDF);
} }
void back_rot(t_FDF *FDF) void back_rot(t_FDF *FDF)
{ {
FDF->map->x_rot -= 2; FDF->map->x_rot -= 1;
move(FDF); move(FDF);
} }
void clock_rot(t_FDF *FDF) void clock_rot(t_FDF *FDF)
{ {
FDF->map->z_rot -= 2; FDF->map->z_rot -= 1;
move(FDF); move(FDF);
} }
void aclock_rot(t_FDF *FDF) void aclock_rot(t_FDF *FDF)
{ {
FDF->map->z_rot += 2; FDF->map->z_rot += 1;
move(FDF); move(FDF);
} }
@ -76,3 +76,14 @@ void zoom_out(t_FDF *FDF)
FDF->map->scale[1] -= 1.0f / 100 * 20; FDF->map->scale[1] -= 1.0f / 100 * 20;
move(FDF); move(FDF);
} }
void reset(t_FDF *FDF)
{
FDF->map->z_rot = 0;
FDF->map->y_rot = 0;
FDF->map->x_rot = 0;
FDF->map->scale[0] = 1;
FDF->map->scale[1] = 1;
FDF->map->scale[2] = 1;
move(FDF);
}