mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat: draw view cone (without DDA)
This commit is contained in:
parent
e4523ff8b4
commit
b6aa74d8d8
1 changed files with 23 additions and 16 deletions
39
src/main.c
39
src/main.c
|
|
@ -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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue