Compare commits
No commits in common. "d11133f122cb6dd6e758edf19ce486f8cf7f1e85" and "b551e2bc55c4e59a37437e475955a1f5eb81d144" have entirely different histories.
d11133f122
...
b551e2bc55
13
inc/fdf.h
13
inc/fdf.h
@ -19,7 +19,6 @@
|
|||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <errno.h>
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "MLX42.h"
|
# include "MLX42.h"
|
||||||
|
|
||||||
@ -75,25 +74,19 @@ typedef struct s_fdf
|
|||||||
double angle_x;
|
double angle_x;
|
||||||
double angle_y;
|
double angle_y;
|
||||||
double angle_z;
|
double angle_z;
|
||||||
double animate_z;
|
|
||||||
double zoom;
|
double zoom;
|
||||||
int offset_x;
|
int offset_x;
|
||||||
int offset_y;
|
int offset_y;
|
||||||
int last_width;
|
|
||||||
int last_height;
|
|
||||||
double z_scale;
|
double z_scale;
|
||||||
} t_fdf;
|
} t_fdf;
|
||||||
|
|
||||||
int interpolate_color(t_point_2d start, t_point_2d end, t_point_2d current);
|
|
||||||
int get_color(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 read_map(char *filename, t_fdf *fdf);
|
int read_map(char *filename, t_map *map);
|
||||||
int parse_map(char *filename, t_fdf *fdf);
|
int parse_map(char *filename, t_fdf *fdf);
|
||||||
void print_map(t_map *map);
|
void print_map(t_map *map);
|
||||||
void copy_map(t_fdf *fdf);
|
void copy_map(t_fdf *fdf);
|
||||||
void fdf_apply_rotation(t_fdf *fdf);
|
void fdf_apply_rotation(t_fdf *fdf);
|
||||||
void handle_error(t_fdf *fdf, char *error);
|
|
||||||
|
|
||||||
void rotate_x(t_point_3d **points, double angle, int size);
|
void rotate_x(t_point_3d **points, double angle, int size);
|
||||||
void rotate_y(t_point_3d **points, double angle, int size);
|
void rotate_y(t_point_3d **points, double angle, int size);
|
||||||
@ -102,12 +95,10 @@ bool fdf_put_pixel(mlx_image_t *img, t_point_2d point);
|
|||||||
void fdf_draw_line(mlx_image_t *img, t_point_2d start,
|
void fdf_draw_line(mlx_image_t *img, t_point_2d start,
|
||||||
t_point_2d end);
|
t_point_2d end);
|
||||||
int fdf_hooks(t_fdf *fdf);
|
int fdf_hooks(t_fdf *fdf);
|
||||||
void resize_hook(int width, int height, void *param);
|
|
||||||
|
|
||||||
void draw_hook(void *param);
|
void draw_hook(void *param);
|
||||||
void key_hook(mlx_key_data_t keydata, void *param);
|
void key_hook(mlx_key_data_t keydata, void *param);
|
||||||
void fdf_set_background(mlx_image_t *img, int color);
|
void fdf_set_background(mlx_image_t *img, int color);
|
||||||
void fdf_project_isometric(t_fdf *fdf);
|
void fdf_project_isometric(t_map *map);
|
||||||
double deg2rad(double deg);
|
double deg2rad(double deg);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 27f7d3e9e02cccf7092f3101b939d381198a595b
|
Subproject commit a6830f9b33e2f87a7675ff193a2879c816c55693
|
||||||
88
src/fdf.c
88
src/fdf.c
@ -54,7 +54,7 @@ void free_line_and_split(char **line, char ***split)
|
|||||||
*split = NULL;
|
*split = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_map(char *filename, t_fdf *fdf)
|
int read_map(char *filename, t_map *map)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *line;
|
char *line;
|
||||||
@ -65,8 +65,8 @@ int read_map(char *filename, t_fdf *fdf)
|
|||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
handle_error(NULL, FILE_ERROR);
|
return (ft_printf(FILE_ERROR, filename), 0);
|
||||||
y = fdf->map->height - 1;
|
y = map->height - 1;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
@ -76,10 +76,10 @@ int read_map(char *filename, t_fdf *fdf)
|
|||||||
split = ft_split(line, ' ');
|
split = ft_split(line, ' ');
|
||||||
while (split[x])
|
while (split[x])
|
||||||
{
|
{
|
||||||
fdf->map->original[y * fdf->map->width + x].x = x - fdf->map->width / 2;
|
map->original[y * map->width + x].x = x - map->width / 2;
|
||||||
fdf->map->original[y * fdf->map->width + x].y = fdf->map->height / 2 - y;
|
map->original[y * map->width + x].y = map->height / 2 - y;
|
||||||
fdf->map->original[y * fdf->map->width + x].z = ft_atoi(split[x]);
|
map->original[y * map->width + x].z = ft_atoi(split[x]);
|
||||||
fdf->map->original[y * fdf->map->width + x].color = get_color(split[x]);
|
map->original[y * map->width + x].color = 0xFFFFFFFF;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
free_line_and_split(&line, &split);
|
free_line_and_split(&line, &split);
|
||||||
@ -92,14 +92,14 @@ int read_map(char *filename, t_fdf *fdf)
|
|||||||
int parse_map(char *filename, t_fdf *fdf)
|
int parse_map(char *filename, t_fdf *fdf)
|
||||||
{
|
{
|
||||||
if (!get_map_sizes(filename, fdf->map))
|
if (!get_map_sizes(filename, fdf->map))
|
||||||
handle_error(fdf, "Error: failed to get map sizes");
|
return (FAILURE);
|
||||||
fdf->map->original = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
fdf->map->original = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
||||||
fdf->map->rotated = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
fdf->map->rotated = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_3d));
|
||||||
fdf->map->projected = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_2d));
|
fdf->map->projected = malloc(fdf->map->width * fdf->map->height * sizeof(t_point_2d));
|
||||||
if (!fdf->map->original || !fdf->map->rotated || !fdf->map->projected)
|
if (!fdf->map->original || !fdf->map->rotated || !fdf->map->projected)
|
||||||
handle_error(fdf, MALLOC_ERROR);
|
return (FAILURE);
|
||||||
if (!read_map(filename, fdf))
|
if (!read_map(filename, fdf->map))
|
||||||
handle_error(fdf, "Error: failed to read map");
|
return (FAILURE);
|
||||||
|
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
@ -121,22 +121,24 @@ void fdf_set_background(mlx_image_t *img, int color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fdf_project_isometric(t_fdf *fdf)
|
void fdf_project_isometric(t_map *map)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
|
const int scale = fmax(map->height, map->width) * SQRT2;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if(fdf->zoom == 0)
|
map->projected = malloc(map->width * map->height * sizeof(t_point_2d));
|
||||||
fdf->zoom = fmin(fdf->mlx->width / fdf->map->width, fdf->mlx->height / fdf->map->height) / SQRT2;
|
if (!map->projected)
|
||||||
while (i < fdf->map->width * fdf->map->height)
|
return ;
|
||||||
|
while (i < map->width * map->height)
|
||||||
{
|
{
|
||||||
x = (fdf->map->rotated[i].x - fdf->map->rotated[i].y) / SQRT2;
|
x = (map->rotated[i].x - map->rotated[i].y) / SQRT2;
|
||||||
y = (fdf->map->rotated[i].x + fdf->map->rotated[i].y - 2 * fdf->map->rotated[i].z) / SQRT6;
|
y = (map->rotated[i].x + map->rotated[i].y - 2 * map->rotated[i].z) / SQRT6;
|
||||||
fdf->map->projected[i].x = x * fdf->zoom + fdf->offset_x;
|
map->projected[i].x = x * WIDTH / scale + WIDTH / 2;
|
||||||
fdf->map->projected[i].y = y * fdf->zoom + fdf->offset_y;
|
map->projected[i].y = y * HEIGHT / scale + HEIGHT / 2;
|
||||||
fdf->map->projected[i].color = fdf->map->rotated[i].color;
|
map->projected[i].color = map->rotated[i].color;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,13 +157,15 @@ int init_mlx(t_fdf *fdf)
|
|||||||
mlx_t *mlx;
|
mlx_t *mlx;
|
||||||
|
|
||||||
printf("init_mlx\n");
|
printf("init_mlx\n");
|
||||||
mlx = mlx_init(WIDTH, HEIGHT, "FdF", true);
|
mlx = mlx_init(WIDTH, HEIGHT, "FdF", false);
|
||||||
if (!mlx)
|
if (!mlx)
|
||||||
handle_error(fdf, "Error: failed to initialise MLX");
|
return (printf("mlx_init failed\n"), FAILURE);
|
||||||
|
printf("mlx: %p\n", mlx);
|
||||||
fdf->mlx = mlx;
|
fdf->mlx = mlx;
|
||||||
fdf->img = mlx_new_image(fdf->mlx, fdf->mlx->width, fdf->mlx->height);
|
fdf->img = mlx_new_image(fdf->mlx, fdf->mlx->width, fdf->mlx->height);
|
||||||
if (!fdf->img || (mlx_image_to_window(fdf->mlx, fdf->img, 0, 0) < 0))
|
if (!fdf->img || (mlx_image_to_window(fdf->mlx, fdf->img, 0, 0) < 0))
|
||||||
handle_error(fdf, "Error: failed to create image");
|
return (FAILURE);
|
||||||
|
printf("img: %p\n", fdf->img);
|
||||||
fdf_hooks(fdf);
|
fdf_hooks(fdf);
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
@ -173,22 +177,20 @@ t_fdf *initialise_fdf()
|
|||||||
|
|
||||||
fdf = malloc(sizeof(t_fdf));
|
fdf = malloc(sizeof(t_fdf));
|
||||||
if (!fdf)
|
if (!fdf)
|
||||||
handle_error(fdf, MALLOC_ERROR);
|
return (ft_printf(MALLOC_ERROR), NULL);
|
||||||
map = malloc(sizeof(t_map));
|
map = malloc(sizeof(t_map));
|
||||||
if (!map)
|
if (!map)
|
||||||
handle_error(fdf, MALLOC_ERROR);
|
return (ft_printf(MALLOC_ERROR), NULL);
|
||||||
fdf->map = map;
|
fdf->map = map;
|
||||||
fdf->mlx = NULL;
|
fdf->mlx = NULL;
|
||||||
fdf->img = NULL;
|
fdf->img = NULL;
|
||||||
fdf->angle_x = 0;
|
fdf->angle_x = 0;
|
||||||
fdf->angle_y = 0;
|
fdf->angle_y = 0;
|
||||||
fdf->angle_z = 0;
|
fdf->angle_z = 0;
|
||||||
fdf->zoom = 0;
|
fdf->zoom = 1;
|
||||||
fdf->offset_x = WIDTH / 2;
|
fdf->offset_x = 0;
|
||||||
fdf->offset_y = HEIGHT / 2;
|
fdf->offset_y = 0;
|
||||||
fdf->z_scale = 0.1;
|
fdf->z_scale = 1;
|
||||||
fdf->last_width = WIDTH;
|
|
||||||
fdf->last_height = HEIGHT;
|
|
||||||
fdf->map->original = NULL;
|
fdf->map->original = NULL;
|
||||||
fdf->map->rotated = NULL;
|
fdf->map->rotated = NULL;
|
||||||
fdf->map->projected = NULL;
|
fdf->map->projected = NULL;
|
||||||
@ -209,33 +211,27 @@ bool clean_fdf(t_fdf *fdf)
|
|||||||
free(fdf->map->projected);
|
free(fdf->map->projected);
|
||||||
free(fdf->map);
|
free(fdf->map);
|
||||||
}
|
}
|
||||||
free(fdf);
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_error(t_fdf *fdf, char *error)
|
|
||||||
{
|
|
||||||
if (errno)
|
|
||||||
perror(error);
|
|
||||||
if (mlx_errno)
|
|
||||||
ft_putendl_fd(mlx_strerror(mlx_errno), 2);
|
|
||||||
ft_putendl_fd(error , 2);
|
|
||||||
clean_fdf(fdf);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
t_fdf *fdf;
|
t_fdf *fdf;
|
||||||
|
|
||||||
fdf = initialise_fdf();
|
fdf = initialise_fdf();
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
handle_error(fdf, "Usage: ./fdf <filename>");
|
{
|
||||||
|
ft_printf(USAGE_ERROR, argv[0]);
|
||||||
|
return (EXIT_FAILURE);
|
||||||
|
}
|
||||||
if (!parse_map(argv[1], fdf))
|
if (!parse_map(argv[1], fdf))
|
||||||
handle_error(fdf, "Error: failed to parse map");
|
return (EXIT_FAILURE);
|
||||||
|
|
||||||
init_mlx(fdf);
|
init_mlx(fdf);
|
||||||
|
printf("fdf: %p\n", fdf);
|
||||||
mlx_loop(fdf->mlx);
|
mlx_loop(fdf->mlx);
|
||||||
|
|
||||||
|
|
||||||
mlx_terminate(fdf->mlx);
|
mlx_terminate(fdf->mlx);
|
||||||
clean_fdf(fdf);
|
clean_fdf(fdf);
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
|
|||||||
@ -1,51 +0,0 @@
|
|||||||
#include "fdf.h"
|
|
||||||
|
|
||||||
int get_color(char *str)
|
|
||||||
{
|
|
||||||
int color;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
color = 0;
|
|
||||||
i = 0;
|
|
||||||
while (str[i] && ft_isdigit(str[i]))
|
|
||||||
i++;
|
|
||||||
i++;
|
|
||||||
if (str[i] == '0' && str[i + 1] == 'x')
|
|
||||||
i += 2;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if (ft_isdigit(str[i]))
|
|
||||||
color = color * 16 + str[i] - '0';
|
|
||||||
else if (str[i] >= 'a' && str[i] <= 'f')
|
|
||||||
color = color * 16 + str[i] - 'a' + 10;
|
|
||||||
else if (str[i] >= 'A' && str[i] <= 'F')
|
|
||||||
color = color * 16 + str[i] - 'A' + 10;
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if(color == 0)
|
|
||||||
return (0xFFFFFFFF);
|
|
||||||
return ((color << 8) + 0xFF);
|
|
||||||
}
|
|
||||||
int interpolate_color(t_point_2d start, t_point_2d end, t_point_2d current)
|
|
||||||
{
|
|
||||||
int delta_current;
|
|
||||||
int delta_total;
|
|
||||||
int red;
|
|
||||||
int green;
|
|
||||||
int blue;
|
|
||||||
|
|
||||||
delta_current = fmax(abs(current.x - start.x), abs(current.y - start.y));
|
|
||||||
delta_total = fmax(abs(end.x - start.x), abs(end.y - start.y));
|
|
||||||
if (delta_total == 0)
|
|
||||||
return (start.color);
|
|
||||||
red = (int) ((1 - (double) delta_current / delta_total) * (start.color >> 24 & 0xFF)
|
|
||||||
+ (double) delta_current / delta_total * (end.color >> 24 & 0xFF));
|
|
||||||
green = (int) ((1 - (double) delta_current / delta_total) * (start.color >> 16 & 0xFF)
|
|
||||||
+ (double) delta_current / delta_total * (end.color >> 16 & 0xFF));
|
|
||||||
blue = (int) ((1 - (double) delta_current / delta_total) * (start.color >> 8 & 0xFF)
|
|
||||||
+ (double) delta_current / delta_total * (end.color >> 8 & 0xFF));
|
|
||||||
return (red << 24 | green << 16 | blue << 8 | 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -39,7 +39,6 @@ void fdf_draw_line_low(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
current = start;
|
current = start;
|
||||||
while (current.x <= end.x)
|
while (current.x <= end.x)
|
||||||
{
|
{
|
||||||
current.color = interpolate_color(start, end, current);
|
|
||||||
fdf_put_pixel(img, current);
|
fdf_put_pixel(img, current);
|
||||||
if (delta > 0)
|
if (delta > 0)
|
||||||
{
|
{
|
||||||
@ -70,7 +69,6 @@ void fdf_draw_line_high(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
current = start;
|
current = start;
|
||||||
while (current.y <= end.y)
|
while (current.y <= end.y)
|
||||||
{
|
{
|
||||||
current.color = interpolate_color(start, end, current);
|
|
||||||
fdf_put_pixel(img, current);
|
fdf_put_pixel(img, current);
|
||||||
if (delta > 0)
|
if (delta > 0)
|
||||||
{
|
{
|
||||||
@ -84,11 +82,6 @@ void fdf_draw_line_high(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
|
|
||||||
void fdf_draw_line(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
void fdf_draw_line(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
||||||
{
|
{
|
||||||
if ((start.x < 0 || start.x >= (int) img->width
|
|
||||||
|| start.y < 0 || start.y >= (int) img->height)
|
|
||||||
&& (end.x < 0 || end.x >= (int) img->width
|
|
||||||
|| end.y < 0 || end.y >= (int) img->height))
|
|
||||||
return ;
|
|
||||||
if (abs(end.y - start.y) < abs(end.x - start.x))
|
if (abs(end.y - start.y) < abs(end.x - start.x))
|
||||||
{
|
{
|
||||||
if (start.x > end.x)
|
if (start.x > end.x)
|
||||||
@ -104,5 +97,3 @@ void fdf_draw_line(mlx_image_t *img, t_point_2d start, t_point_2d end)
|
|||||||
fdf_draw_line_high(img, start, end);
|
fdf_draw_line_high(img, start, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,43 +5,22 @@ int fdf_hooks(t_fdf *fdf)
|
|||||||
{
|
{
|
||||||
mlx_loop_hook(fdf->mlx, draw_hook, fdf);
|
mlx_loop_hook(fdf->mlx, draw_hook, fdf);
|
||||||
mlx_key_hook(fdf->mlx, key_hook, fdf);
|
mlx_key_hook(fdf->mlx, key_hook, fdf);
|
||||||
mlx_resize_hook(fdf->mlx, resize_hook, fdf);
|
printf("hooks set\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
void resize_hook(int width, int height, void *param)
|
|
||||||
{
|
|
||||||
t_fdf *fdf;
|
|
||||||
|
|
||||||
(void)width;
|
|
||||||
(void)height;
|
|
||||||
fdf = (t_fdf *)param;
|
|
||||||
mlx_delete_image(fdf->mlx, fdf->img);
|
|
||||||
fdf->img = mlx_new_image(fdf->mlx, fdf->mlx->width, fdf->mlx->height);
|
|
||||||
if (!fdf->img || (mlx_image_to_window(fdf->mlx, fdf->img, 0, 0) < 0))
|
|
||||||
exit(1);
|
|
||||||
fdf->offset_x += (fdf->mlx->width - fdf->last_width ) / 2 ;
|
|
||||||
fdf->offset_y += (fdf->mlx->height - fdf->last_height) / 2;
|
|
||||||
fdf->zoom = 0;
|
|
||||||
fdf->last_height = fdf->mlx->height;
|
|
||||||
fdf->last_width = fdf->mlx->width;
|
|
||||||
}
|
|
||||||
void draw_hook(void *param)
|
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 || fdf->last_height != fdf->mlx->height)
|
|
||||||
{
|
|
||||||
resize_hook(fdf->mlx->width, fdf->mlx->height, fdf);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
fdf_set_background(fdf->img, 0x000000FF);
|
fdf_set_background(fdf->img, 0x000000FF);
|
||||||
if (fdf->animate_z)
|
printf("background set\n");
|
||||||
fdf->angle_z += deg2rad(fdf->animate_z);
|
|
||||||
fdf_apply_rotation(fdf);
|
fdf_apply_rotation(fdf);
|
||||||
fdf_project_isometric(fdf);
|
printf("rotation applied\n");
|
||||||
|
fdf_project_isometric(fdf->map);
|
||||||
|
printf("projection applied\n");
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < fdf->map->width * fdf->map->height)
|
while (i < fdf->map->width * fdf->map->height)
|
||||||
{
|
{
|
||||||
@ -63,36 +42,12 @@ void key_hook(mlx_key_data_t keydata, void *param)
|
|||||||
mlx_close_window(((t_fdf *)param)->mlx);
|
mlx_close_window(((t_fdf *)param)->mlx);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (keydata.key == MLX_KEY_A && keydata.action != MLX_RELEASE)
|
if (keydata.key == MLX_KEY_LEFT && keydata.action == MLX_PRESS)
|
||||||
fdf->angle_z -= deg2rad(5);
|
fdf->angle_z -= deg2rad(5);
|
||||||
if (keydata.key == MLX_KEY_D && keydata.action != MLX_RELEASE)
|
if (keydata.key == MLX_KEY_RIGHT && keydata.action == MLX_PRESS)
|
||||||
fdf->angle_z += deg2rad(5);
|
fdf->angle_z += deg2rad(5);
|
||||||
if (keydata.key == MLX_KEY_W && keydata.action != MLX_RELEASE)
|
if (keydata.key == MLX_KEY_UP && keydata.action == MLX_PRESS)
|
||||||
fdf->angle_x -= deg2rad(5);
|
fdf->angle_x -= deg2rad(5);
|
||||||
if (keydata.key == MLX_KEY_S && keydata.action != MLX_RELEASE)
|
if (keydata.key == MLX_KEY_DOWN && keydata.action == MLX_PRESS)
|
||||||
fdf->angle_x += deg2rad(5);
|
fdf->angle_x += deg2rad(5);
|
||||||
if (keydata.key == MLX_KEY_Q && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->angle_y -= deg2rad(5);
|
|
||||||
if (keydata.key == MLX_KEY_E && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->angle_y += deg2rad(5);
|
|
||||||
if (keydata.key == MLX_KEY_X && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->z_scale *= 1.05;
|
|
||||||
if (keydata.key == MLX_KEY_Z && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->z_scale /= 1.05;
|
|
||||||
if (keydata.key == MLX_KEY_UP && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->offset_y -= 10;
|
|
||||||
if (keydata.key == MLX_KEY_DOWN && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->offset_y += 10;
|
|
||||||
if (keydata.key == MLX_KEY_LEFT && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->offset_x -= 10;
|
|
||||||
if (keydata.key == MLX_KEY_RIGHT && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->offset_x += 10;
|
|
||||||
if (keydata.key == MLX_KEY_EQUAL && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->zoom += 1;
|
|
||||||
if (keydata.key == MLX_KEY_MINUS && keydata.action != MLX_RELEASE)
|
|
||||||
fdf->zoom *= 1.1;
|
|
||||||
if (keydata.key == MLX_KEY_LEFT_BRACKET && keydata.action == MLX_PRESS)
|
|
||||||
fdf->animate_z /= 1.1;
|
|
||||||
if (keydata.key == MLX_KEY_RIGHT_BRACKET && keydata.action == MLX_PRESS)
|
|
||||||
fdf->animate_z += 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ void copy_map(t_fdf *fdf)
|
|||||||
fdf->map->rotated[i].x = fdf->map->original[i].x;
|
fdf->map->rotated[i].x = fdf->map->original[i].x;
|
||||||
fdf->map->rotated[i].y = fdf->map->original[i].y;
|
fdf->map->rotated[i].y = fdf->map->original[i].y;
|
||||||
fdf->map->rotated[i].z = fdf->map->original[i].z * fdf->z_scale;
|
fdf->map->rotated[i].z = fdf->map->original[i].z * fdf->z_scale;
|
||||||
fdf->map->rotated[i].color = fdf->map->original[i].color;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user