feat: draw view cone (without DDA)

This commit is contained in:
Khaïs COLIN 2025-07-28 13:04:32 +02:00
parent e4523ff8b4
commit b6aa74d8d8
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,13 +6,14 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ /* 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 "../libft/includes/libft.h"
#include "../mlx/mlx.h" #include "../mlx/mlx.h"
#include "consts.h" #include "consts.h"
#include "cub3d_data.h"
#include "draw/drawutils.h" #include "draw/drawutils.h"
#include "map/map_checker.h" #include "map/map_checker.h"
#include "draw/draw_map.h" #include "draw/draw_map.h"
@ -53,27 +54,33 @@ bool touch(float px, float py, t_mapdata *map)
return (false); 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) int game_loop(t_cub3d_data *data)
{ {
mlx_destroy_image(data->mlx, data->img_data->img); mlx_destroy_image(data->mlx, data->img_data->img);
data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT); data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
int column = 0; int column = 0;
while (column < 1) float fraction = M_PI / 3 / WIDTH;
float start_angle = data->player.yaw - M_PI / 6;
while (column < WIDTH)
{ {
// calculate angle draw_line(data, start_angle);
double cos_angle = cos(data->player.yaw); start_angle += fraction;
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
column++; column++;
} }