minmap overlay

This commit is contained in:
whaffman 2025-05-11 14:06:16 +02:00
parent d4319f0789
commit 0287cad1b3
10 changed files with 51 additions and 17 deletions

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/05/08 23:15:13 by whaffman ######## odam.nl #
# Updated: 2025/05/11 13:26:58 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
@ -27,7 +27,7 @@ MLX42_PATH = $(LIB_PATH)/MLX42
MLX42_INC_PATH = $(MLX42_PATH)/include/MLX42
MLX42 = $(MLX42_PATH)/build/libmlx42.a
CC = clang
CC = cc
RM = rm -rf
INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH) -I./$(MLX42_INC_PATH)

BIN
assets/overlay.xcf Normal file

Binary file not shown.

BIN
assets/overlay2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

BIN
assets/overlay2.xcf Normal file

Binary file not shown.

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_math.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* :::::::: */
/* vec_math.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */
/* Updated: 2025/05/06 15:20:37 by qmennen ### ########.fr */
/* Updated: 2025/05/11 13:36:45 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -93,4 +93,13 @@ t_vec2 rot(t_vec2 a, double angle);
*/
t_vec2 perp(t_vec2 a);
/**
* @brief Rotates a 2D vector by a given direction vector.
*
* @param vec The 2D vector to rotate.
* @param dir The direction vector to rotate by.
* @return The rotated vector as a new 2D vector.
*/
t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis);
#endif // VEC_MATH_H

23
src/math/rot_by_dir.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* rot_by_dir.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/11 13:24:34 by whaffman #+# #+# */
/* Updated: 2025/05/11 13:38:30 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis)
{
const double sin_angle = dir.x;
const double cos_angle = -dir.y;
t_vec2 rotated_vec;
rotated_vec.x = axis.x + (vec.x - axis.x) * cos_angle - (vec.y - axis.y) * sin_angle;
rotated_vec.y = axis.y + (vec.x - axis.x) * sin_angle + (vec.y - axis.y) * cos_angle;
return (rotated_vec);
}

View File

@ -1,7 +1,7 @@
#include "cub3d.h"
#define MINIMAP_SIZE 200
#define MINIMAP_SIZE 300
void render_map(t_game *game)
{
t_vec2_int disp;
@ -26,6 +26,8 @@ void render_map(t_game *game)
}
map.x = ((double)disp.x/TILE_SIZE) + game->player->pos.x - (0.5 * MINIMAP_SIZE/TILE_SIZE);
map.y = ((double)disp.y/TILE_SIZE) + game->player->pos.y - (0.5 * MINIMAP_SIZE/TILE_SIZE);
map = rot_by_dir(map, game->player->dir, game->player->pos);
if (map.x < 0 || map.x >= game->map->width
|| map.y < 0 || map.y >= game->map->height)
{

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
/* Updated: 2025/05/09 15:13:05 by whaffman ######## odam.nl */
/* Updated: 2025/05/11 13:26:18 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -101,10 +101,10 @@ static void cam_fraction(t_game *game, t_sprite *sprite)
}
unsigned int calculate_alpha(mlx_texture_t *texture, int x, int y, double dist)
{
int index;
// int index;
int alpha;
index = (x + y * texture->width) * texture->bytes_per_pixel;
// index = (x + y * texture->width) * texture->bytes_per_pixel;
dist = (dist > 1) * dist + (dist <= 1) * 1;
alpha = (255.0 / dist);
return (alpha);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
/* Updated: 2025/05/09 15:27:37 by whaffman ######## odam.nl */
/* Updated: 2025/05/11 14:04:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -78,7 +78,7 @@ int screen_display(t_screen *screen)
printf(RED"Failed to display buffer image\n"RESET);
return (FAILURE);
}
if (mlx_image_to_window(screen->mlx, screen->minimap, 200, 200) < 0)
if (mlx_image_to_window(screen->mlx, screen->minimap, 175, 575) < 0)
{
printf(RED"Failed to display buffer image\n"RESET);
return (FAILURE);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
/* Updated: 2025/05/09 13:07:25 by whaffman ######## odam.nl */
/* Updated: 2025/05/11 14:03:16 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -68,7 +68,7 @@ static int init_temp(t_game **game)
(*game)->map->sprites[9].dist = 0;
(*game)->map->sprites[9].texture = mlx_load_png("./assets/lamp.png");
(*game)->map->n_sprites = 10;
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx, mlx_load_png("./assets/overlay.png"));
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx, mlx_load_png("./assets/overlay2.png"));
return (SUCCESS);
}