A raycasting engine inspired by the legendary Wolfenstein 3D, the first true FPS in videogame history. This project implements raycasting techniques to render a dynamic 3D view inside a maze from a 2D map perspective.
- About
- Features
- Prerequisites
- Installation
- Usage
- Map Format
- Controls
- Technical Implementation
- Resources
CUB3D is a 42 Network project that explores the fundamentals of raycasting, a rendering technique used in early 3D games. Using the MiniLibX library, this project creates a first-person perspective of a maze where the player can navigate through corridors with textured walls.
Key Concepts:
- Raycasting algorithm
- DDA (Digital Differential Analysis) algorithm
- Texture mapping
- Field of view rendering
- Player movement and collision detection
- โ Wall rendering with raycasting
- โ Different textures for each cardinal direction (North, South, East, West)
- โ Configurable floor and ceiling colors
- โ Smooth player movement (W, A, S, D)
- โ Camera rotation (Arrow keys)
- โ Map parsing and validation
- โ Proper error handling
- ๐ฏ Wall collision detection
- ๐บ๏ธ Minimap display
- ๐ฑ๏ธ Mouse rotation
- ๐ช Doors (optional)
- ๐จ Animated sprites (optional)
- Clone the repository:
git clone https://github.com/msabr/CUB3D_1337.git
cd CUB3D_1337- Compile the project:
# Mandatory part
make
# Bonus part
make bonus- Clean build files:
make clean # Remove object files
make fclean # Remove object files and executable
make re # Recompile everythingRun the program with a map file:
./cub3D maps/mapSubject.cub or
./cub3D_bonus maps/mapSubject.cubThe program will:
- Parse the map file
- Validate the map structure
- Initialize the graphics window
- Render the 3D environment
- Wait for player input
Map files use the .cub extension and follow this structure:
NO textures/wall_Gry.xpm
SO textures/wall_Huf.xpm
WE textures/wall_Sly.xpm
EA textures/wall_Rev.xpm
F 220,100,0
C 225,30,0
1111111111111111111111111
1000000000110000000000001
1011000001110000000000001
1001000000000000000000001
111111111011000001110000000000001
100000000011000001110111111111111
11110111111111011100000010001
11110111111111011101010010001
11000000110101011100000010001
10000000000000001100000010001
10000000000000001101010010001
11000001110101011111011110N0111
11110111 1110101 101111010001
11111111 1111111 111111111111
Texture Paths:
NO- North wall textureSO- South wall textureWE- West wall textureEA- East wall texture
Colors:
F- Floor color (RGB format: R,G,B)C- Ceiling color (RGB format: R,G,B)
Map Characters:
1- Wall0- Empty space (walkable floor)N- Player starting position facing NorthS- Player starting position facing SouthE- Player starting position facing EastW- Player starting position facing West(space) - Void (outside map boundaries)
- Map must be surrounded by walls (
1) - Must contain exactly one player starting position
- Valid characters only:
0,1,N,S,E,W, and spaces - Map must be closed (flood fill algorithm validation)
| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
โ |
Rotate camera left |
โ |
Rotate camera right |
ESC |
Exit program |
Mouse |
Rotate view (bonus) |
The project implements raycasting using the DDA algorithm:
- Ray Generation: For each vertical strip of the screen, cast a ray from the player's position
- DDA Algorithm: Calculate ray intersection with the map grid
- Wall Distance: Compute perpendicular distance to avoid fisheye effect
- Wall Height: Calculate projected wall height based on distance
- Texture Mapping: Apply appropriate texture based on wall orientation
- Rendering: Draw vertical strips to create the 3D illusion
Fisheye Correction:
correct_distance = ray_distance * cos(ray_angle - player_angle)
Wall Height Projection:
wall_strip_height = (WALL_HEIGHT / correct_distance) * DISTANCE_TO_PROJECTION_PLANE
wall_top_pixel = (WINDOW_HEIGHT / 2) - (wall_strip_height / 2)
wall_bottom_pixel = (WINDOW_HEIGHT / 2) + (wall_strip_height / 2)
- Standard FOV: 60 degrees
- Window divided by width to determine ray angles
- Each ray corresponds to one vertical pixel column
cub3D
โโโ Libft
โ โโโ Makefile
โ โโโ ft_atoi.c
โ โโโ ft_bzero.c
โ โโโ ft_calloc.c
โ โโโ ft_is_number.c
โ โโโ ft_isalnum.c
โ โโโ ft_isalpha.c
โ โโโ ft_isascii.c
โ โโโ ft_isdigit.c
โ โโโ ft_isprint.c
โ โโโ ft_isspace.c
โ โโโ ft_itoa.c
โ โโโ ft_malloc.c
โ โโโ ft_memchr.c
โ โโโ ft_memcmp.c
โ โโโ ft_memcpy.c
โ โโโ ft_memmove.c
โ โโโ ft_memset.c
โ โโโ ft_putchar_fd.c
โ โโโ ft_putendl_fd.c
โ โโโ ft_putnbr_fd.c
โ โโโ ft_putstr_fd.c
โ โโโ ft_split.c
โ โโโ ft_strcat.c
โ โโโ ft_strchr.c
โ โโโ ft_strcmp.c
โ โโโ ft_strcpy.c
โ โโโ ft_strdup.c
โ โโโ ft_striteri.c
โ โโโ ft_strjoin.c
โ โโโ ft_strlcat.c
โ โโโ ft_strlcpy.c
โ โโโ ft_strlen.c
โ โโโ ft_strmapi.c
โ โโโ ft_strncmp.c
โ โโโ ft_strndup.c
โ โโโ ft_strnstr.c
โ โโโ ft_strrchr.c
โ โโโ ft_strrev.c
โ โโโ ft_strstr.c
โ โโโ ft_strtrim.c
โ โโโ ft_substr.c
โ โโโ ft_tolower.c
โ โโโ ft_toupper.c
โ โโโ get_next_line.c
โ โโโ libft.h
โโโ Makefile
โโโ README.md
โโโ bonus
โ โโโ cub3d_bonus.h
โ โโโ main_bonus.c
โ โโโ parsing_bonus
โ โ โโโ parse_color_bonus.c
โ โ โโโ parse_fill_map_bonus.c
โ โ โโโ parse_line_bonus.c
โ โ โโโ parse_map_bonus.c
โ โ โโโ parse_memory_bonus.c
โ โ โโโ parse_player_bonus.c
โ โ โโโ parse_small_map_bonus.c
โ โ โโโ parse_textures_bonus.c
โ โ โโโ parse_utils_bonus.c
โ โ โโโ parse_validate_map_bonus.c
โ โ โโโ parsing_bonus.h
โ โโโ rendring_bonus
โ โโโ exit_game_bonus.c
โ โโโ game_loop_bonus.c
โ โโโ ray_cast_bonus.c
โ โโโ ray_cast_dda_algo_bonus.c
โ โโโ ray_cast_utils_bonus.c
โ โโโ rendring_bonus.h
โ โโโ start_game_bonus.c
โ โโโ texturing_bonus
โ โ โโโ texture_draw_bonus.c
โ โ โโโ texture_loading_bonus.c
โ โ โโโ texture_rendering_bonus.c
โ โ โโโ texture_utils_bonus.c
โ โ โโโ texturing_bonus.h
โ โโโ utils_bonus.c
โ โโโ wand_animation_bonus.c
โโโ file.md
โโโ images
โ โโโ Gryffindor.png
โ โโโ Hufflepuff.png
โ โโโ Ravenclaw.png
โ โโโ Slytherin.png
โ โโโ cub3d.png
โโโ mandatory
โ โโโ cub3d.h
โ โโโ main.c
โ โโโ parsing
โ โ โโโ parse_color.c
โ โ โโโ parse_fill_map.c
โ โ โโโ parse_line.c
โ โ โโโ parse_map.c
โ โ โโโ parse_memory.c
โ โ โโโ parse_player.c
โ โ โโโ parse_small_map.c
โ โ โโโ parse_textures.c
โ โ โโโ parse_utils.c
โ โ โโโ parse_validate_map.c
โ โ โโโ parsing_cub3d.h
โ โโโ rendring
โ โโโ exit_game.c
โ โโโ game_loop.c
โ โโโ ray_cast.c
โ โโโ ray_cast_dda_algo.c
โ โโโ ray_cast_utils.c
โ โโโ rendring_cub3d.h
โ โโโ start_game.c
โ โโโ texturing
โ โ โโโ texture_draw.c
โ โ โโโ texture_loading.c
โ โ โโโ texture_rendering.c
โ โ โโโ texture_utils.c
โ โ โโโ texturing_cub3d.h
โ โโโ utils.c
โโโ maps
โ โโโ Gryffindor_map.cub
โ โโโ Hufflepuff_map.cub
โ โโโ Ravenclaw_map.cub
โ โโโ Slytherin_map.cub
โ โโโ empty_map.cub
โ โโโ mapSubject.cub
โ โโโ map_subject.cub
โโโ minilibx_opengl
โ โโโ Makefile
โ โโโ font.c
โ โโโ font.xcf
โ โโโ mlx.h
โ โโโ mlx_init_loop.m
โ โโโ mlx_int.h
โ โโโ mlx_int_str_to_wordtab.c
โ โโโ mlx_mouse.m
โ โโโ mlx_new_image.m
โ โโโ mlx_new_window.h
โ โโโ mlx_new_window.m
โ โโโ mlx_opengl.h
โ โโโ mlx_opengl.m
โ โโโ mlx_png.c
โ โโโ mlx_png.h
โ โโโ mlx_rgb.c
โ โโโ mlx_shaders.c
โ โโโ mlx_xpm.c
โโโ structures_headers.tldr
โโโ textures
โโโ DOOR.xpm
โโโ wall_Gry.xpm
โโโ wall_Huf.xpm
โโโ wall_Rev.xpm
โโโ wall_Sly.xpm
โโโ wall_simple.xpm
โโโ wall_void.xpm
โโโ wand_magic
โโโ wand_magic_1.xpm
โโโ wand_magic_2.xpm
โโโ wand_magic_3.xpm
โโโ wand_magic_4.xpm
โโโ wand_magic_5.xpm
โโโ wand_magic_6.xpm
15 directories, 146 files
- msabr
- aylamiri
โโโ โโโ โโโโโโโ โโโโโโโ โโโ โโโ โโโโโโ โโโโโโโ โโโโโโโโโ โโโโโโโโ
โโโ โโโ โโโโโโโโโ โโโโโโโโ โโโ โโโ โโโโโโโโ โโโโโโโโ โโโโโโโโโ โโโโโโโโ
โโโโโโโโ โโโ โโโ โโโ โโโโ โโโ โโ โโโ โโโโโโโโ โโโโโโโโ โโโ โโโโโโโโ
โโโโโโโโ โโโ โโโ โโโ โโโ โโโโโโโโโโ โโโโโโโโ โโโโโโโโ โโโ โโโโโโโโ
โโโ โโโ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโโ โโโ โโโ โโโ โโโ โโโ โโโโโโโโ
โโโ โโโ โโโโโโโ โโโโโโโ โโโโโโโโ โโโ โโโ โโโ โโโ โโโ โโโโโโโโ
โโโโโโ โโโโโโโ
โโโโโโโ โโโโโโโโ
โโโโโโโ โโโ โโโ
โโโโโโโ โโโ โโโ
โโโโโโโ โโโโโโโโ
โโโโโโ โโโโโโโ
๐ฐ Welcome to Hogwarts 3D Game! ๐ฐ$
โจAfter All This Time โจ




