This project has been created as part of the 42 curriculum by ymassiou.
SpinRoam is a first-person perspective graphical engine built from scratch in C. Inspired by the 1992 classic Wolfenstein 3D, this project uses ray-casting principles to transform a 2D map into a dynamic 3D view. It focuses on the practical application of mathematics and trigonometry to create an efficient rendering system within a maze environment.
The engine is built using the miniLibX graphical library, handling window management, real-time events, and pixel-level manipulation.
- Ray-Casting Engine: Renders a "realistic" 3D view of a maze from a first-person perspective.
- Wall Textures: Displays different textures based on wall orientation (North, South, East, West).
- Environment Coloring: Configurable floor and ceiling colors parsed from the scene description.
- Scene Parsing: Robust parsing of
.cubfiles, including map validation (ensuring the map is closed/surrounded by walls) and texture/color configurations. - Smooth Controls: Real-time movement and rotation without input lag.
- Wall Collisions: Prevents the player from walking through walls by calculating potential coordinates before movement.
- Minimap System: A real-time 2D overlay showing the player's position, orientation, and the surrounding environment.
- Mouse Rotation: Allows the player to look around naturally using the mouse.
- Animated Sprites: Integration of dynamic, animated objects within the 3D world to enhance the atmosphere.
| Key | Action |
|---|---|
| W, A, S, D | Move and strafe through the maze |
| Left / Right Arrows | Look left and right |
| Mouse | Rotate the camera view |
| ESC | Close the window and exit cleanly |
- GCC compiler.
- Standard C libraries.
- miniLibX (X11 or Metal version depending on the OS).
The project includes a Makefile with the following rules:
make # Compiles the mandatory part
make bonus # Compiles with bonus features
make clean # Removes object files
make fclean # Removes object files and the executable
make re # Recompiles the projectRun the program by passing a valid scene description file as an argument:
./cub3D maps/maze.cub-
Digital Differential Analysis (DDA): Efficient wall distance calculation to avoid the high cost of standard trigonometric functions per ray.
-
Texture Mapping: Precise mapping of 2D textures to 3D vertical strips by calculating the exact horizontal offset on the wall during intersection.
-
Mathematical Foundation: Heavy reliance on trigonometry for handling player rotation, field-of-view (FOV) casting, and movement vectors.
-
Event Handling: Implementation of non-blocking key hooks and mouse tracking for a seamless user experience.
- 42 Docs - MiniLibX — Unofficial guide for window management and image manipulation.
- Lode's Raycasting Tutorial — The industry standard for learning DDA and texturing.