Menu
RENDERING PROCESS:
MISCELLANEOUS:
|
Step IV: Finding Walls
INTRODUCTION:
The ability to find a wall forms the core of the engine, and is also
surprisingly easy to implement. The only trick is making it speedy. However,
it doesn't matter if your routines aren't blindingly fast to start with, just
as long as they work correctly.
The rest of this page is dedicated to the topic of finding walls in a
raycasting environment; objects aren't covered, though, as they require a
slightly different technique (or rather, an extension to this).
Anyway, it's time to get stuck in...
GETTING THE IDEA:
There may be other ways to implement the checking of walls, but in this
document I'm going to outline the one I'm familiar with. If you remember, the
raycasting environment is made up of cells, which are arranged in a
grid-pattern. The cells are of uniformed dimensions (ie. they're square) for
speed and simplicity. Since all walls are
orthogonal and the cubes
(walls could be cuboids if variable-height walls were supported or if you used
different width/breadth/height values in the maths, but let's keep things
simple) each take up a single cell, then we can simply check each horizontal
and vertical grid-line for a wall. In effect, we're not defining solid blocks,
just wafer-thin walls that make up the faces of the block. In theory, the
walls should be infinitely thin (like the grid-lines), but in practice, it's
possible to see a wall on its end. To clarify what I'm going on about, take a
look at fig9:

fig9: A single cell bordered by walls
The figure shows a single cell bordered entirely by walls (they're emphasized,
and so thicker than what they would be in an engine). The walls make up a
seemingly solid block if viewed from the outside, but we know that's not true,
don't we ? :) Anyhow, we need to work out how to detect walls, and it
turns out that it's a simple application of triangles.
The process can be split into two phases, as I've already mentioned; one to
check horizontal grid-lines and one to check vertical grid-lines. For clarity,
we'll use two separate functions for this, although they could be combined into
a conglomerate chunk of code if you wish (but that's harder to debug, IMHO).
FUNCTION INTERFACE
Both of the functions will require to know the angle at which to cast a ray,
and the starting point for this ray, as you'd expect. These values will be
passed to the horizontal and vertical grid-line checkers by the main rendering
loop which coordinates the whole process (which will be discussed after we've
run through the theory behind these two core functions...)
This page just re-inforced the ideas presented previously, but the next one
will present the actual mathematics behind casting for horizontal grid-lines.
So, if you can take the excitement, click the link below to enter the realms
of trigonometry ! :) It's a biggy, BTW...about 18K of text alone...
NEXT PAGE
|
PREVIOUS PAGE
|
|