{"id":29473436,"url":"https://github.com/mitadic/raycasting_game","last_synced_at":"2025-07-14T15:38:52.344Z","repository":{"id":304363740,"uuid":"847123404","full_name":"mitadic/raycasting_game","owner":"mitadic","description":"the 'cub3d' project from the 42 network, inspired by 1992 Wolfenstein","archived":false,"fork":false,"pushed_at":"2025-07-12T15:05:56.000Z","size":18339,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-12T17:27:51.618Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitadic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-24T23:15:48.000Z","updated_at":"2025-07-12T15:05:59.000Z","dependencies_parsed_at":"2025-07-12T17:37:55.662Z","dependency_job_id":null,"html_url":"https://github.com/mitadic/raycasting_game","commit_stats":null,"previous_names":["mitadic/raycasting_game"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mitadic/raycasting_game","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitadic%2Fraycasting_game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitadic%2Fraycasting_game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitadic%2Fraycasting_game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitadic%2Fraycasting_game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitadic","download_url":"https://codeload.github.com/mitadic/raycasting_game/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitadic%2Fraycasting_game/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265313471,"owners_count":23745190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-14T15:38:49.447Z","updated_at":"2025-07-14T15:38:52.334Z","avatar_url":"https://github.com/mitadic.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raycasting-powered engine\nThis is a raycasting engine for 2D→3D projection, inspired by 1992 Wolfenstein\n\n## Demo\n| ![final](https://github.com/user-attachments/assets/5ba101ee-86f9-431d-8fb4-247075fb0208) |\n|:---:|\n| Engine in action with custom neon textures |\n\n## Installation\n\n\u003e [!NOTE]\n\u003e These installation steps assume availability of x11 and clang or gcc\n\n### Installation steps\n\n1. Clone the repository; enter the created directory.\n\n        $ git clone https://github.com/mitadic/raycasting_game; cd raycasting_game\n\n2. Optional: tweak the settings manually in `cub3d.h` before compiling\n\n       // Settings \n       # define SCREEN_W 800\n       # define SCREEN_H 600\n       # define PLAY_FPS 60\n       # define ROT_SPEED_FEED 0.015\n       # define MOV_SPEED_FEED 0.0125\n\n4. Compile\n\n        $ make\n\n### Usage\n\nRun the app with a map of your choosing.\n```bash\n./cub3d maps/full.cub\n```\n\n### Customization\nAdd your custom maps/*.cub files with specifications for\n1. maps (`1`: walls, `0`: walkable tiles, `N|W|S|E`: player position and orientation)\n2. textures (`.xpm` format images only)\n3. floor \u0026 ceiling colors (RGB)\n\n\n\n## 🔬📚 Gains\nThe goal of the project was to recreate the then revolutionary tech behind Wolfenstein 3D from scratch. Although the engine is natively 2D, it renders a first-person 3D perspective by simulating a 3D environment on a 2D map.\n\n### The basic idea\nWe start with a 2D grid-based map where each cell represents walls (1) or empty space (0).\nUsing raycasting, we simulate the player's perspective by casting rays in different directions and calculating wall distances.\nEach ray represents a \"line of sight\" from the player’s position in a specific direction. As each ray moves forward, it checks for wall intersections on the map grid. We display different wall heights based on distance to give a depth illusion. The closer a wall is, the taller it appears.\nAs the player moves around and rotates, the 3D render updates, showing only what the player \"sees\" based on the rays cast.\n\n### The math\nThe project requires understanding vectors, trigonometry, and distance calculations.\nBefore we dive into the math, let's go over a few important concepts\n#### FOV (field of view)\ndefines how wide the player's visible world is in terms of angles. A wider FOV means fewer rays but a zoomed-in view.\n#### Player angle\nThe direction the player is facing, crucial for determining where rays are cast.\n#### Ray angle\nThe angle for each individual ray cast relative to the player's position, calculated based on the player angle and FOV.\n#### Grid-based optimization\nSince walls are aligned with grid cells, we implemented the DDA Alorithm that only checks for walls at grid intersections, allowing us to optimize wall hit detection. \nThe algorithm determines the distance from the player to the wall by stepping through the grid either horizontally or vertically, depending on which direction the ray is moving.\n\n### DDA algorithm breakdown\n1) Calculate the initial side distances (side_dist_x, side_dist_y), which represent the distance from the player to the nearest grid boundary in both the X and Y directions.\n2) Calculate the step size that represent the distance the ray has to travel along each axis (X or Y) to move from one grid line to the next. Use the ray’s direction and step size (delta_dist_x, delta_dist_y) to increment the ray’s position step-by-step until it intersects a wall. \n3) Once a wall is hit (grid value equals '1'), we calculate the exact intersection point between ray and the grid by determining whether the ray crosses a vertical or horizontal grid line first, adjusting for the player's position and the ray's direction to find the precise coordinates. Finally, we calculate the distance from the player to the wall at the intersection point, first using the Pythagorean theorem, then refining the distance by adjusting for overshoot caused by stepping past grid lines.\n\n\n\n## Credits \u0026 Feedback\n\nIf you have any feedback, feel free to reach out to the authors.\n\n| Team          | \u003cimg src=\"https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png\" alt=\"gh_logo.png\" width=\"15\" height=\"15\"/\u003e | \u003cimg src=\"https://cdn3.iconfinder.com/data/icons/web-ui-3/128/Mail-2-512.png\" alt=\"email_icon.jpg\" width=\"15\" height=\"15\"/\u003e | Responsibilities |\n| ------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | :--- |\n| Jasmin Nguyen | [@JasminNguyen](https://github.com/JasminNguyen)                                                                              | jasnguye@student.42.fr                                                                                                  | maths, rendering, QoL features, performance optimization\n| Milos Tadic   | [@mitadic](https://github.com/MilosTadic01)                                                                                         | mitadic@student.42.fr                                                                                             | map parsing, minilibX integration, testing, visuals\n\nWe thank our peers of 42 Berlin for their limitless drive for discovery and for their rigor and precision in providing feedback. We are likewise grateful to 42 Berlin itself for fostering a culture of inclusive excellence.\n\n## License\n\n[CC0 1.0 Universal](/LICENSE.txt)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitadic%2Fraycasting_game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitadic%2Fraycasting_game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitadic%2Fraycasting_game/lists"}