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 pikuma.com.

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 August 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

73% of our students come back for another course

We don't offer discounts on our courses. Ever.

What students are saying

4.98
5 star
97.7%
4 star
2.3%
3 star
0.0%
2 star
0.0%
1 star
0.0%
Paul Canegaly
"Well done. Great course. I'm learning much."
23 Sep 2024
Robert Pashov
"A+ Great course - teaches you the WHY and makes you think about what you are actually building. Very good explanations on the trigonometry used to build the engine."
03 Aug 2024
Todd Martin
Software Engineer
"Excellent course. Really enjoyed the content and the presentation. As with all of Gustavo's content, he does a really good job explaining it and breaking it down turning complex ideas into simple ones."
01 Aug 2024
Code Wiki
Code Wiki
"Great course! This course is really excellent. It covers the concept of Raycasting (based on Wolfenstein 3D techniques) from scratch. Gustavo is an excellent teacher who explains everything in detail, paying particular attention to the difficult points. I recommend this course to anyone who wants to learn how raycasting works, it's really worth it."
06 Jun 2024
"Thank you sir. So far, the lecturer seems very friendly, and clear, and he clearly knows what he's talking about. The topics he covers are wonderful, and it's obvious how much work has been put into these courses. So far, it's easily a 5-star experience, and I don't expect it to go any lower. In fact, it seems to get nicer and nicer the more I go through it. I don't think a simple 'thank you' is enough to show my appreciation and gratitude for this lecturer and his platform."
27 May 2024

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++.