This project has been created as part of the 42 curriculum by pifourni and sbrochar.
Description
Cube3D is a compact Wolfenstein-style raycaster written in C using MiniLibX. The goal is to implement basic 3D rendering from a 2D map (wall casting, sprites, and simple player movement) as a learning project for the 42 curriculum.
Instructions
- Install dependencies (Debian/Ubuntu):
sudo apt update
sudo apt install xorg libxext-dev zlib1g-dev libbsd-dev- Build:
make - Run:
./cub3D path/to/map.cub - Maps live in the
Map/folder; a valid map must end with.cuband include texture paths and floor/ceiling colors.
Resources
- Raycasting primer: https://lodev.org/cgtutor/raycasting.html
- MiniLibX docs: https://harm-smits.github.io/42docs/libs/minilibx
AI usage
AI-assisted edits were used to refine and shorten this README and to tidy wording. Code changes (small key-mapping update) were done manually in the source.
If you want the README expanded with usage examples, map format details, or development notes, tell me which sections to add.
Technical details
- Rendering approach: the engine casts one 2D ray per screen column from the player position to find the first wall intersection. The distance to that hit determines the vertical slice height drawn for that column; textures and wall face are selected based on the hit.
- Main data:
t_p(player) holds position (x,y), viewangle,speed, the parsedmap,tile_size, pointers tot_map(map/meta) andt_data(MLX image/window). SeeInclude/struct.hfor full fields. - Core files:
main.c— program start, argument parsing and MLX init.Parser/— read.cubfiles and load textures/colors intot_map.Render/casting.c,Render/ray.c— ray traversal and wall-slice drawing.Render/Sprite/sprite.c— sprite ordering and drawing.Src/Game/key.candInclude/Game/key.h— input handling and movement (WASD/rotation).
- Frame loop: each frame the code updates player state from input flags, runs the renderer to fill an off-screen image, then pushes that image to the MLX window with
mlx_put_image_to_window. - Collision: movement attempts update
x,ythen check the map cell at the new tile; moves are reverted on wall collision.
This section is intentionally concise — tell me if you want a deeper walkthrough (ray math, DDA steps, or texture sampling).