translade code from macos to linux
This commit is contained in:
parent
6569da5710
commit
66634b039e
6 changed files with 50 additions and 39 deletions
14
inc/fdf.h
14
inc/fdf.h
|
@ -15,12 +15,11 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
# define HEIGHT 1000
|
||||
# define WIDTH 1000
|
||||
# define BPP 32
|
||||
# define ENDIAN 1
|
||||
# define COLOR1 2604805
|
||||
# define COLOR2 12518661
|
||||
# define HEIGHT 1300
|
||||
# define WIDTH 2500
|
||||
# define ENDIAN 0
|
||||
# define COLOR1 16515072
|
||||
# define COLOR2 252
|
||||
# define INIT_X 30
|
||||
# define INIT_Y -20
|
||||
# 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 int_to_color(int 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);
|
||||
|
||||
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 zoom_in(t_FDF *FDF);
|
||||
void zoom_out(t_FDF *FDF);
|
||||
void reset(t_FDF *FDF);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,11 +22,8 @@ t_FDF *FDF_init(char *path)
|
|||
pnt_init(FDF->map);
|
||||
FDF->w_height = HEIGHT;
|
||||
FDF->w_width = WIDTH;
|
||||
FDF->bpp = BPP;
|
||||
FDF->line_size = WIDTH;
|
||||
FDF->endian = ENDIAN;
|
||||
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,
|
||||
&FDF->bpp,
|
||||
|
|
|
@ -12,15 +12,9 @@ void put_pixel_to_image(t_line *line, t_swap *s, t_FDF *FDF)
|
|||
y = line->p1.x;
|
||||
x = line->p1.y;
|
||||
}
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x > FDF->w_width)
|
||||
x = FDF->w_width;
|
||||
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));
|
||||
if (x < 0 || y < 0 || x >= FDF->w_width || y >= FDF->w_height)
|
||||
return ;
|
||||
*(int *)((FDF->image_data + x * FDF->bpp / 8 + y * FDF->line_size)) =
|
||||
color_to_int(choose_color(line, s));
|
||||
}
|
||||
|
||||
|
|
29
src/main.c
29
src/main.c
|
@ -1,14 +1,30 @@
|
|||
#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)
|
||||
{
|
||||
t_FDF *FDF;
|
||||
// int i = 0;
|
||||
if (argc < 2)
|
||||
|
||||
if (argc < 2 && argc > 4)
|
||||
{
|
||||
print_help();
|
||||
return (0);
|
||||
}
|
||||
else if (argc < 4)
|
||||
{
|
||||
parse_input(argc, argv);
|
||||
}
|
||||
FDF = FDF_init(argv[1]);
|
||||
center(FDF->map);
|
||||
FDF->map->trnsf = initial_trnsf_mats(FDF);
|
||||
|
@ -16,14 +32,7 @@ int main(int argc, char **argv)
|
|||
mat4_mult_chain(FDF);
|
||||
transform(FDF->map->trnsf->fin, FDF->map);
|
||||
render(FDF);
|
||||
// sleep(10);
|
||||
// while (i < 360)
|
||||
// {
|
||||
// usleep(15000);
|
||||
// clock_rot(FDF);
|
||||
// i++;
|
||||
// }
|
||||
mlx_key_hook(FDF->mw->win, key_hook, FDF);
|
||||
mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF);
|
||||
mlx_loop(FDF->mw->mlx);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ t_map *map_init(char *path)
|
|||
map->scale[2] = 1;
|
||||
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);
|
||||
}
|
||||
tab_map = ft_strsplit(str_map, '\n');
|
||||
|
|
|
@ -6,7 +6,7 @@ void move(t_FDF *FDF)
|
|||
mat4_mult_chain(FDF);
|
||||
transform(FDF->map->trnsf->fin, FDF->map);
|
||||
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,
|
||||
&FDF->bpp,
|
||||
|
@ -17,37 +17,37 @@ void move(t_FDF *FDF)
|
|||
|
||||
void left_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->y_rot -= 2;
|
||||
FDF->map->y_rot -= 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
void right_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->y_rot += 2;
|
||||
FDF->map->y_rot += 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
void forw_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->x_rot += 2;
|
||||
FDF->map->x_rot += 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
void back_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->x_rot -= 2;
|
||||
FDF->map->x_rot -= 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
void clock_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->z_rot -= 2;
|
||||
FDF->map->z_rot -= 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
void aclock_rot(t_FDF *FDF)
|
||||
{
|
||||
FDF->map->z_rot += 2;
|
||||
FDF->map->z_rot += 1;
|
||||
move(FDF);
|
||||
}
|
||||
|
||||
|
@ -75,4 +75,15 @@ void zoom_out(t_FDF *FDF)
|
|||
FDF->map->scale[0] -= 1.0f / 100 * 20;
|
||||
FDF->map->scale[1] -= 1.0f / 100 * 20;
|
||||
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);
|
||||
}
|
Loading…
Add table
Reference in a new issue