「🏗️」 wip: Started printing raycasting (not working)
This commit is contained in:
2
Makefile
2
Makefile
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/07 16:02:18 by adjoly #+# #+# #
|
||||
# Updated: 2024/10/08 22:06:26 by adjoly ### ########.fr #
|
||||
# Updated: 2024/10/13 21:23:17 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/04 14:04:10 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/13 17:44:12 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/13 21:28:23 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
# define DDA_H
|
||||
|
||||
# include "typedef.h"
|
||||
# include "settings.h"
|
||||
# include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Function used to get all the ray angle
|
||||
@ -57,4 +59,5 @@ float *dist_dda(t_dda dda[WINDOW_X / RAY_SIZE]);
|
||||
*/
|
||||
uint16_t *line_dda(float *wall_dist);
|
||||
|
||||
uint16_t *dda(t_player *player, char **map);
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/06 17:58:41 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/14 12:32:14 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
#include "game/game.h"
|
||||
#include "mlx.h"
|
||||
|
||||
void *print_frame(t_cub *cub);
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_cub cub;
|
||||
@ -32,8 +34,9 @@ int main(int ac, char **av)
|
||||
cub.win = mlx_new_window(cub.mlx, WINDOW_X, WINDOW_Y, "WTF");
|
||||
cub.player.coords.x = 100;
|
||||
cub.player.coords.y = 100;
|
||||
cub.img = mlx_new_image(cub.mlx, WINDOW_X, WINDOW_Y);
|
||||
get_player_image(&cub, 0);
|
||||
cub.player.direction = 0;
|
||||
cub.img = print_frame(&cub);
|
||||
//get_player_image(&cub, 0);
|
||||
mlx_put_image_to_window(cub.mlx, cub.win, cub.img, 0, 0);
|
||||
mlx_on_event(cub.mlx, cub.win, MLX_KEYDOWN, key_hook, &cub);
|
||||
mlx_loop(cub.mlx);
|
||||
|
@ -6,26 +6,27 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/07 16:55:09 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/13 17:27:17 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/13 21:27:59 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game/dda.h"
|
||||
#include "game/settings.h"
|
||||
|
||||
void dda(t_player *player, char **map)
|
||||
uint16_t *dda(t_player *player, char **map)
|
||||
{
|
||||
t_dda dda[WINDOW_X / RAY_SIZE];
|
||||
t_coord map_coord;
|
||||
float *wall_dist;
|
||||
float *line_size;
|
||||
uint16_t *line_size;
|
||||
|
||||
setup_dda(&dda, player);
|
||||
map_coord.x = player->coords.x - player->coords.x % MAP_CHUNK_SIZE;
|
||||
map_coord.y = player->coords.y - player->coords.y % MAP_CHUNK_SIZE;
|
||||
while_dda(&dda, map, map_coord);
|
||||
wall_dist = dist_dda(dda);
|
||||
|
||||
line_size = line_dda(wall_dist);
|
||||
return (line_size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/08 13:26:19 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/08 21:40:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/13 21:30:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,22 +14,25 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "game/settings.h"
|
||||
#include "libft.h"
|
||||
|
||||
float *dist_dda(t_dda dda[WINDOW_X / RAY_SIZE])
|
||||
{
|
||||
size_t i;
|
||||
float wall_dist;
|
||||
float *wall_dist;
|
||||
|
||||
i = 0;
|
||||
wall_dist = ft_calloc(WINDOW_X / RAY_SIZE, sizeof(float));
|
||||
if (!wall_dist)
|
||||
return (NULL);
|
||||
while (dda[i])
|
||||
while (dda)
|
||||
{
|
||||
if (dda[i].wall_side == HORIZONTAL)
|
||||
wall_dist[i] = dda[i].side_dist.x - dda[i].delta_dist.x;
|
||||
else
|
||||
wall_dist[i] = dda[i].side_dist.y - dda[i].delta_dist.y;
|
||||
i++;
|
||||
dda++;
|
||||
}
|
||||
return (wall_dist);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/29 15:26:29 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/07 19:06:47 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/14 12:35:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "game/settings.h"
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void get_ray_angle(t_player *player, t_dda (*dda)[800])
|
||||
{
|
||||
@ -21,6 +22,7 @@ void get_ray_angle(t_player *player, t_dda (*dda)[800])
|
||||
float ray_angle;
|
||||
|
||||
x = 0;
|
||||
printf("plyaer dir = %f", player->direction);
|
||||
while (x < WINDOW_X)
|
||||
{
|
||||
ray_angle = player->direction - (FOV / 2) + (x / WINDOW_X) * FOV;
|
||||
|
@ -6,18 +6,20 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 17:27:44 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/13 17:36:05 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/13 21:28:12 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game/settings.h"
|
||||
#include "game/dda.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
uint16_t *line_dda(t_dda (*dda)[WINDOW_X / RAY_SIZE], float *wall_dist)
|
||||
#include <stdint.h>
|
||||
uint16_t *line_dda(float *wall_dist)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t *line_size;
|
||||
|
||||
(void)dda;
|
||||
i = 0;
|
||||
line_size = malloc(WINDOW_X / RAY_SIZE * sizeof(uint16_t));
|
||||
while (wall_dist[i])
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/06 18:46:56 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/08 13:28:33 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/10/13 21:34:01 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,22 +14,22 @@
|
||||
|
||||
void while_dda(t_dda (*dda)[WINDOW_X / RAY_SIZE], char **map, t_coord map_coord)
|
||||
{
|
||||
dda->wall_hit = false;
|
||||
while (!dda->wall_hit)
|
||||
(*dda)->wall_hit = false;
|
||||
while (!(*dda)->wall_hit)
|
||||
{
|
||||
if (dda->side_dist.x < dda->side_dist.y)
|
||||
if (( *dda )->side_dist.x < (*dda)->side_dist.y)
|
||||
{
|
||||
dda->side_dist.x += dda->delta_dist.x;
|
||||
map_coord.x += dda->step.x;
|
||||
dda->wall_side = HORIZONTAL;
|
||||
(*dda)->side_dist.x += (*dda)->delta_dist.x;
|
||||
map_coord.x += (*dda)->step.x;
|
||||
(*dda)->wall_side = HORIZONTAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
dda->side_dist.y += dda->delta_dist.y;
|
||||
map_coord.y += dda->step.y;
|
||||
dda->wall_side = VERTICAL;
|
||||
(*dda)->side_dist.y += (*dda)->delta_dist.y;
|
||||
map_coord.y += (*dda)->step.y;
|
||||
(*dda)->wall_side = VERTICAL;
|
||||
}
|
||||
if (map[map_coord.x][map_coord.y] == '1')
|
||||
dda->wall_hit = true;
|
||||
(*dda)->wall_hit = true;
|
||||
}
|
||||
}
|
||||
|
59
src/raycasting/print_frame.c
Normal file
59
src/raycasting/print_frame.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* print_frame.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/13 21:01:53 by adjoly #+# #+# */
|
||||
/* Updated: 2024/10/13 21:37:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game/dda.h"
|
||||
#include "mlx.h"
|
||||
#include <stdlib.h>
|
||||
#include "game/settings.h"
|
||||
|
||||
void draw_rectangle(t_cub *cub, void *img, t_coord start, t_coord end)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
x = start.x;
|
||||
y = start.y;
|
||||
while (x < end.x)
|
||||
{
|
||||
while (y < end.y)
|
||||
{
|
||||
mlx_set_image_pixel(cub->mlx, img, x, y, WHITE);
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
void *print_frame(t_cub *cub)
|
||||
{
|
||||
uint16_t *lines;
|
||||
int start;
|
||||
int stop;
|
||||
size_t i;
|
||||
void *img;
|
||||
|
||||
lines = dda(&cub->player, cub->map);
|
||||
img = mlx_new_image(cub->mlx, WINDOW_X, WINDOW_Y);
|
||||
i = 0;
|
||||
while (i < WINDOW_X / RAY_SIZE)
|
||||
{
|
||||
start = -lines[i] / 2 + WINDOW_Y / 2;
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
stop = lines[i] / 2 + WINDOW_Y / 2;
|
||||
if (stop >= WINDOW_Y)
|
||||
stop = WINDOW_Y - 1;
|
||||
draw_rectangle(cub, img, (t_coord){i * RAY_SIZE, start}, (t_coord){i * RAY_SIZE + RAY_SIZE - 1, stop});
|
||||
i++;
|
||||
}
|
||||
return (img);
|
||||
}
|
Reference in New Issue
Block a user