feat: draw view cone (without DDA)

This commit is contained in:
Khaïs COLIN 2025-07-28 13:04:32 +02:00 committed by freddy_vqr
parent 805ddbab0b
commit c19b4087b9

View file

@ -6,13 +6,14 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/07/28 12:57:08 by kcolin ### ########.fr */
/* Updated: 2025/07/28 13:16:19 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft/includes/libft.h"
#include "../mlx/mlx.h"
#include "consts.h"
#include "cub3d_data.h"
#include "draw/drawutils.h"
#include "map/map_checker.h"
#include "draw/draw_map.h"
@ -53,27 +54,33 @@ bool touch(float px, float py, t_mapdata *map)
return (false);
}
void draw_line(t_cub3d_data *data, float start_x)
{
float cos_angle = cos(start_x);
float sin_angle = sin(start_x);
float ray_x = data->player.x;
float ray_y = data->player.y;
while(!touch(ray_x, ray_y, data->map))
{
my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xcc241b);
ray_x += sin_angle;
ray_y += cos_angle;
}
}
int game_loop(t_cub3d_data *data)
{
mlx_destroy_image(data->mlx, data->img_data->img);
data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
int column = 0;
while (column < 1)
int column = 0;
float fraction = M_PI / 3 / WIDTH;
float start_angle = data->player.yaw - M_PI / 6;
while (column < WIDTH)
{
// calculate angle
double cos_angle = cos(data->player.yaw);
double sin_angle = sin(data->player.yaw);
double ray_x = data->player.x;
double ray_y = data->player.y;
while (!touch(ray_x, ray_y, data->map))
{
my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xFF0000);
ray_x += sin_angle;
ray_y += cos_angle;
}
// calculate distance
// draw
draw_line(data, start_angle);
start_angle += fraction;
column++;
}