Tuesday, November 20, 2007

Maze Raycasting

Modern maze uses a raycasting engine. I believe I have discussed raycasting in the past but review never hurts. Essentially raycasting is a simplified version of ray tracing. You follow light from the camera (the player's eye) to the nearest wall. The size to draw the wall is based on the distance the ray had to travel to hit the wall. A texture strip is then drawn based on where on the wall that the ray hit. Lighting could be applied to the texture also based on the distance, but this adds a lot of time per pixel plotted and we are using software rendering which is slow already.

The method that I used for doing the casting is a bit different from the other methods I have seen described. I calculate the stepping distance between entering different tiles. I then just take steps picking the x or y step based on the distance. Only one of the steps is adjusted each iteration since obviously the farther crossing distance hasn't been reached. The one that is crossed gets the distance needed to travel across the tile added to it.

No comments: