# What mathematics would I need to know in order to build a 2.5D raycasting engine

I realize this is a fairly common-type question, but I've been studying Maths in my spare time, fairly slowly at that, and I really want to develop a raycasting engine like the original DOOM.

I know more-or-less the subjects / categories of Maths needed for modern 3D games, such as Linear Algebra, but I don't they all would be applicable for a raycasting engine.

Assume I am starting from the ground-up in Maths, what would I need to know? I assume Algebra, Trigonometry and Geometry would be the most important. I'm wondering if I could pull it off just with that?

-
It seems like you should be asking about how to create a raycasting engine, and then doing research on the math you don't know to solve a problem that you're currently facing rather than just studying math without context. – Tetrad Jul 12 '12 at 15:49
Obligatory: Write Games, Not Engines. (scientificninja.com/blog/write-games-not-engines) An engine is a fine way of trying to learn the technology you want to learn, but a directed purpose for an engine - that is, a game (or even 'just' a visualization) attached to it - will both help motivate during the sloggier bits of development and also actively help with making design decisions for the engine, because you'll be solving a specific problem rather than an abstract one. – Steven Stadnicki Jul 12 '12 at 18:26
@Tetrad I have done some degree of research in raycasting engines, so I know it seems like I'm shooting this question out of the dark, but I have looked at it some. The reason I am asking this question is because I started losing myself a bit when the stuff I was reading got a bit... too Mathy? However, the parts that talked about shooting rays and scaling slices just as Tapio mentioned, seemed to make perfect and simple sense. – Daniel Carvalho Jul 12 '12 at 19:00

A Wolfenstein-style raycaster is really simple. You basically shoot beams horizontally in an arc from one side of the player view to the other edge. When a beam encounters a wall, you get the wall slices height on screen from the distance (e.g. scale_factor / distance). E.g. for this height calculation you don't need to understand anything about matrices etc, just think that you want a smaller height on screen when the distance from viewer is greater.

The "trickiest" part is "shooting" the beam (i.e. determining direction and traversing it in small steps), but that's trivial for any 2d game programmer - just use sin and cos as you would have done for the player movement.

It gets slightly more complicated when adding stuff like textured walls (still easy) and sprite enemies, and you can always explain the thing with difficult mathematics using projection planes and whatnot, but the basic idea is just traversing 2d beams on a 2d grid - if you're language/programming environment has an easy way to output graphics, you can get a basic raycaster running in less than 50 lines of code without any matrices or even vector classes.

-
For the research I did do into raycasting engines, I took away what you're saying here, which is very comforting, because it's stuff I understand. But, as you perfectly noted, it gets more complicated when doing projections, which is about the point in my research I donned a "huh?" face. – Daniel Carvalho Jul 12 '12 at 19:07

Well, if you stick to something very simple then you can do it using only basic linear algebra. I would list the absolute necessities as understanding a) orthogonal coordinate systems; b) matrix multiplication and c) how and why the two are related.

And if you want to actually construct some arbitrary rotation matrices then you'll at least need to understand the basic trigonometric functions and their relation to the circle.