100 lines
3.3 KiB
C
100 lines
3.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* algo.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */
|
|
/* Updated: 2024/10/15 13:13:13 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "algo.h"
|
|
|
|
void *g_mlx = NULL;
|
|
void *g_win = NULL;
|
|
t_ray g_ray;
|
|
|
|
int worldMap[mapWidth][mapHeight] =
|
|
{
|
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
|
|
{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,1,1,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
|
|
{1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1},
|
|
{1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,1,1,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1},
|
|
{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
|
|
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
|
|
};
|
|
|
|
static int initalgo()
|
|
{
|
|
// TODO from map
|
|
g_ray.posX = 14;
|
|
g_ray.posY = 6.5;
|
|
g_ray.rot = 0;
|
|
return (0);
|
|
}
|
|
|
|
void draw_screen(void) {
|
|
int bpp;
|
|
int size_line;
|
|
int endian;
|
|
|
|
void *img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
u_int32_t *img_data = (u_int32_t *)mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian);
|
|
if (bpp != 32 || endian != 0)
|
|
{
|
|
// TODO manage error better
|
|
printf("image format error (got bpp == %i, endian == %i)\n", bpp, endian);
|
|
exit(1);
|
|
}
|
|
render(img_data);
|
|
mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
// Initialisation
|
|
g_mlx = mlx_init();
|
|
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
|
|
|
initalgo();
|
|
|
|
// hook keypress
|
|
mlx_hook(g_win, 2, 1L<<0, keypress, NULL);
|
|
|
|
// render the initial frame
|
|
draw_screen();
|
|
|
|
// start the mlx loop
|
|
mlx_loop(g_mlx);
|
|
|
|
return (0);
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://github.com/iciamyplant/Cub3d-Linux
|
|
|
|
// https://lodev.org/cgtutor/raycasting.html
|
|
|
|
// https://www.youtube.com/watch?v=js7HW65MmNw&list=PL0H9-oZl_QOHM34HvD3DiGmwmj5X7GvTW
|