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 March 2023
  • 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
Edmar Paulino
Developer at Grupo Boticário
"An awesome course. Gustavo teaches us in an easy way, with incredible examples that really explain everything about the content, you learn and don't get that feeling of not having understood the subject."
27 Mar 2023
Adrian Devlin
"Loved the course. Well delivered and very interesting."
01 Feb 2023
Amro Ibrahim
Software Engineer
"The best tutorial for raycast!

I bought this course since I enjoyed other courses Mr. Gustavo Pezzi created, although I have already built a ray caster previously, I just wanted to refresh my knowledge. After all this is just a ray caster engine, and lots of tutorials cover this topic! Oh boy, oh boy I was completely wrong!

With Mr. Gustavo there is always something new to learn even if you know the topic by heart. The course covers topics that no other tutorials online covers, and this is what makes this course excel from all other tutorials online and making it the best resource available online.

Course content 10/10 Course progression 10/10 Explanation 10/10 Course self-contained 10/10 learn something new 10/10."
22 Dec 2022
Ramnath R
"Course is Execellent and Worth learning! Gustavo explained and break complex concepts to simple ones. I enjoyed the course. You have chosen simple mathematical techniques in the course which allowed me to grasp the Raycasting concept easily. There is something I would like to point out. You have formatted the code at the end of the course instead of following best practices from the beginning. That can cause some confusion and it is better to write separate header files from the beginning, doing so will be easier to follow, debug and even read the entire code. IMO, this is not a beginner C programming course isn't it Gustavo. So why not format the code from the beginning instead of reformatting entire thing at last sections. Other than that this course is highly recommended for anyone looking for awesome C based project and want to dive deep in to core concepts of game development."
12 Dec 2022
William Bickel
"My review. Thanks for this course."
12 Dec 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++.