Course description

This course will teach you how to create a complete raycasting engine from scratch. We'll use an algorithm similar to the one used in Wolfenstein 3D. The final project will be coded using both JavaScript and C. It will implement player movement, 2D map view, 3D wall projection, textured walls, sprites, and other optimization techniques.

raycasting tutorial

This course will be divided in two important parts:

raycasting tutorial javascript

1. The first part of the course uses JavaScript to cover the theory and the math behind the raycasting algorithm. JavaScript is a simple high-level scripting language that helps us not get too distracted with implementation details.

raycasting tutorial cpp

2. The second part of the course uses the C programming language to implement a compiled version of our raycaster, including textured walls and sprites. We'll also use C to discuss important optimization and performance aspects of our code.

The tools you'll need

You'll need a web browser that can run JavaScript and a small C compiler. All these tools are cross-platform, so you can follow along with either Windows, macOS, or Linux!

c++ game engine platform

The Wolfenstein 3D raycasting algorithm we'll learn is heavily based on trigonometry, so make sure you have pen and paper ready for the lectures. I will make sure we review and understand every formula we find along the way!

game math

Is this course for you?

This course has no prerequisites. We'll cover all the math and the code as we go along, so even beginners with no prior experience are welcome to join!

There are faster raycasting algorithms out there, but we'll try to stay faithful to the Wolfenstein 3D technique.

How is this course different?

Other raycasting tutorials out there are either too long or overwhelmingly complex. This course tries to be as beginner-friendly as possible.

raycasting wolfenstein 3d

We never skip any of the math or any other implementation detail. Everything is always taught from scratch, and you get to see the code evolving line by line in front of your eyes!

About the instructor

gustavo pezzi

Gustavo Pezzi is a university lecturer in London, UK. He has won multiple education awards as a teacher and is also the founder of

Gustavo teaches fundamentals of computer science and mathematics; his academic path includes institutions such as Pittsburg State University, City University of London, and University of Oxford.

teaching certification
higher education academy
pgclt teaching certification
bpp university award

Course content

18 hours total length 18 Chapters Last updated July 2022
  • Motivations & Learning Outcomes
  • How to Take This Course
  • An High-Level Overview of the Raycasting Algorithm
  • Ray Casting or Ray Tracing?
  • Limitations of the Wolfenstein Raycasting Algorithm
  • Degrees and Radians
  • Sine, Cosine, and Tangeng
  • Quiz: Trig Functions
  • A Note on Different Raycasting Techniques
  • Defining the 2D Map Grid
  • The Map Class
  • Player Movement
  • Exercise: Map Collision
  • Defining the Field of View
  • FOV Increments
  • Wall Hits
  • Finding Horizontal Intersections
  • Finding Vertical Intersections
  • DDA Algorithm
  • Finding Grid-Cell Intersections
  • Fixing the Intersection Offset Error
  • Orientation using Angles vs. Vectors
  • Exercise: Ray Intersections
  • Wall Projection
  • Computing the Wall "Strip" Height
  • Drawing the Minimap
  • Fixing the Fishbowl Distortion
  • Spherical vs. Linear Confusion
  • Exercise: Wall Shading Based on Depth
  • Bright/Dark Walls
  • Exercise: Walls with Different Colors
  • Compiling our C Project
  • Configuring the C Compiler on Linux
  • Configuring the C Compiler on macOS
  • Makefiles
  • Configuring Visual Studio on Windows
  • Creating an SDL Window
  • SDL Rendering and SDL Event Polling
  • Rendering SDL Rectangles
  • Quiz: C Compilation
  • Game Loop Overview
  • Fixed Deltatime Game Loop
  • SDL Delay
  • Quiz: Game Loop
  • Drawing the Map with SDL
  • Player Movement and SDL Events
  • Exercise: Wall Collision in C
  • Ray Struct and Defining a Field of View
  • Finding Horizontal Intersections with C
  • Finding Vertical Intersections with C
  • Rendering Rays using SDL
  • The Colorbuffer
  • Coding a Colorbuffer
  • Allocating and Freeing Memory
  • A Function to Project and Render Walls
  • Exercise: Solid-Color Floor & Ceiling
  • Representing Textures in Memory
  • Creating Textures Manually
  • Mapping Textures to Walls
  • Working with Multiple Textures
  • Fixed-Size Data Types in C
  • Decoding PNG Files
  • Loading External PNG Files
  • Exercise: Reading Textures from PNG Files
  • Exercise: FOV Distortion
  • Understanding the Angle-Increment Distortion
  • Fixing the Angle-Increment Distortion
  • Fullscreen Window
  • Refactoring the Graphics File
  • Exercise: Drawing Rectangles
  • Refactoring the Map File
  • Refactoring the Ray and the Player File
  • The Line Equation
  • Rasterizing Lines
  • Implementing the DDA Algorithm
  • Exercise: Line Rendering
  • Refactoring the Wall Projection Function
  • Sending Pointers via Parameter
  • Refactoring the Ray-Facing Code
  • Wall Texture Color Intensity
  • Raycasting Sprites
  • Sprite Typedef
  • Rendering Sprites in the Minimap
  • Identifying Visible Sprites
  • Visible Sprites in the Wolfenstein 3D Code
  • Computing Sprite Distance
  • Normalization of the Player Rotation Angle
  • Computing Sprite Projection Height
  • Computing Sprite X Position
  • Computing Sprite Rectangle Position in the Screen
  • Displaying Textured Sprite
  • Exercise: Sorting Sprites by Distance
  • Exercise: Sorting Behind Walls
  • Enemies and Sprite Animation
  • Concluding our Raycasting Implementation
  • A Discussion About Look-Up Tables
  • Conclusion and Next Steps
  • Moving Forward and Extra Resources

What students are saying

5 star
4 star
3 star
2 star
1 star
Albert Nadal Garriga
Software Engineer
"This course taught me the magic behind the Raycasting technique, very clearly and concisely. I enjoyed the course from start to finish. This course make me better understand how to implement the Raycasting technique from its foundations using one of my favourite programming languages. This course also encouraged me to implement new challenging features like transparent walls or portal mirrors, just for fun. I strongly recommend this course. Thank you Gustavo."
17 Oct 2022
James Rozee
James Rozee
"This was a wonderful course. I grew up with very limited Math skills. So this course really helped me to understand much of the mathematics behind this Raycasting approach. Thank you for making this course!"
10 Oct 2022
"Fun but not perfect. The important part of the course is seeing the implementation of a fun algorithm, and this is conveyed well both in terms of how to write the algorithm and understanding how it works. The drawback of the course is that the code that is presented often goes against industry best practices, e.g. with var instead of let statements in the JavaScript code and tons of global variables in the C code (instead of explicit argument passing). I would recommend this course for an experienced programmer that's looking for some fun. For the junior programmer, there's a heavy does of asterixis that follow pretty much every single statement in this course."
18 Jul 2022
Albert Tsanaclis
Albert Tsanaclis
Senior Software Developer
"Amazing course! This course was amazing, thank you! I really enjoyed the lessons pace and the raycasting technique."
15 Jul 2022
Moeen Kamali
"Its the best way to start understanding rendering. i think Gustavo is a great person to teach complicated stuff very easily."
01 Jul 2022

Other similar courses

3D Computer Graphics Programming

35 hours
  • Create a 3D software renderer from scratch using the C programming language.

C++ 2D Game Engine Development

30 hours
  • Learn to make a simple 2D game engine using modern C++, SDL, ECS, and Lua.

Game Physics Engine Programming

35 hours
  • Learn how to create a 2D rigid-body game physics engine from scratch with C++.