You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.5 KiB
81 lines
2.5 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* fdf.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/11/04 07:43:17 by narnaud #+# #+# */
|
|
/* Updated: 2022/02/24 13:44:31 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "fdf.h"
|
|
|
|
/* Function init_datas
|
|
* -------------------
|
|
* datas :
|
|
* fd :
|
|
*/
|
|
|
|
void init_map(t_datas *datas, int fd)
|
|
{
|
|
t_camera *cam;
|
|
t_map *map;
|
|
int y;
|
|
|
|
map = ft_calloc(1, sizeof(t_map));
|
|
map->altitude = ft_calloc(512000, sizeof(int *));
|
|
cam = ft_calloc(1, sizeof(t_camera));
|
|
datas->map = parse_file(fd, map);
|
|
map->z_mult = SCALE / (2 * map->hightest);
|
|
cam->ang.yaw = trigo_calc((DEF_YAW % 360) * 3.1415 / 180);
|
|
cam->ang.pitch = trigo_calc((DEF_PITCH % 360) * 3.1415 / 180);
|
|
cam->zoom = SCALE * WIN_Y_SZ / map->depth;
|
|
cam->center.x = WIN_X_SZ / 2;
|
|
cam->center.y = WIN_Y_SZ / 2;
|
|
y = 0;
|
|
cam->render = ft_calloc(datas->map->depth, sizeof(t_2di *));
|
|
while (y < map->depth)
|
|
{
|
|
cam->render[y] = (t_2di *)ft_calloc(datas->map->width, sizeof(t_2di));
|
|
y++;
|
|
}
|
|
datas->cam = cam;
|
|
}
|
|
|
|
void init_window(t_datas *datas)
|
|
{
|
|
void *mlx;
|
|
void *window;
|
|
|
|
mlx = mlx_init();
|
|
if (!mlx)
|
|
exit(error_msg("Mlx fail to init", 1));
|
|
datas->mlx = mlx;
|
|
window = mlx_new_window(mlx, WIN_X_SZ, WIN_Y_SZ, "FdF");
|
|
if (!window)
|
|
exit(error_msg("Mlx fail to create window", 1));
|
|
datas->win = window;
|
|
}
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
t_datas *datas;
|
|
int fd;
|
|
|
|
if (argc != 2)
|
|
return (error_msg("Wrong arguments.\n", 0));
|
|
fd = open(argv[1], O_RDONLY);
|
|
if (fd < 0)
|
|
return (error_msg("File error:", 1));
|
|
else if (ft_strncmp(get_file_ext(argv[1]), "fdf", 4))
|
|
return (error_msg("Wrong file extension.\n", 0));
|
|
datas = (t_datas *)malloc(sizeof(t_datas));
|
|
init_window(datas);
|
|
init_map(datas, fd);
|
|
draw_map(datas);
|
|
mlx_key_hook(datas->win, key_hook_primary, datas);
|
|
mlx_loop(datas->mlx);
|
|
return (0);
|
|
}
|
|
|