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

5 star
4 star
3 star
2 star
1 star
Vince Sevedge
"Fun and practical! This course was a journey, a story about a program and all the details, beautiful and messy alike. Math, algorithms, code organization, best practices, refactoring - all landmarks along the way to a victorious ending and a promising epilogue."
17 Dec 2023
Gerard Druiven
"Great. Nice thing, eteps from easy to more complex. Not afraid for making mistakes, on purpose or not, and than ofcourse correcting these mistakes which is great learning point."
10 Nov 2023
Niki Prljic Junior
Niki Prljic Junior
"I really like this course. Really well explained. It's really worth the money."
28 Aug 2023
Patrick Apgar
"Great Course w/ a Fun Project"
03 Aug 2023
Esko Tarkka
"Thank you for this marvelous course. I am a beginner in programming and this has helped me a lot. Will be taking other courses to get further learning. My main focus is demoscene, making digital art in real-time for pc. But perhaps some day in a few years to do some game development. Would also love to see a course from Pikuma that teaches a bit of artistic real-time coding, like maybe a few simple 2d and 3d effects in C or C++. There are many interesting effects but I am not good at implementing math/linear algebra to a code yet. Thanks a lot. Pikuma is a wonderful place to learn."
31 Jul 2023

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