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.6%
4 star
2.4%
3 star
0.0%
2 star
0.0%
1 star
0.0%
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
Andres Mata
Profesor de talleres tecnológicos
"Exceptional Introduction to Raycasting Programming!

Gustavo Pezzi's course on raycasting programming is nothing short of exceptional. As someone delving into game development or simply interested in the intricacies of computer graphics, this course provides an enriching experience that exceeds expectations.

Gustavo's expertise shines through as he navigates learners through the complexities of raycasting. His clear explanations and structured approach make even the most daunting concepts accessible to beginners.

What sets this course apart is its hands-on nature. Gustavo guides students through the process of building a simple but complete raycaster from scratch, mirroring the techniques utilized in Wolfenstein 3D. The practical exercises ensure that learners not only grasp theoretical concepts but also gain invaluable programming skills applicable in various domains.

Furthermore, Gustavo's teaching style fosters a supportive learning environment. His responsiveness to questions and willingness to clarify doubts ensures that no learner is left behind. The course materials, including lectures, assignments, and supplementary resources, are meticulously curated to facilitate a seamless learning journey.

By the end of the course, students emerge with a profound understanding of raycasting principles and a tangible project to showcase their newfound skills. Whether you're an aspiring game developer or simply passionate about coding, Gustavo Pezzi's raycasting course is an invaluable resource that deserves five stars without hesitation."
06 May 2024
Alexandre Canova
Alexandre Canova
"Another great course from Gustavo! Hands-on experience that builds your knowledge foundation in a well structured pace. You'll create the raycasting engine first in Javascript and then move to a more complete version in C. It really covers a lot in such little time, thank you!"
28 Apr 2024
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

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