Been trying to make a little textured raycaster for fun the past few days. Walls went fine, but I hit a wall when it came to floor texturing. No idea how to do it. So I found http://lodev.org/cgtutor/raycasting2.html , and I was able to adapt their floorcasting code quite easily. It worked, except that it couldn't handle it when I changed the camera height. Looking at their section on computing the 'currentDist' (from current pixel to floor, I'm assuming vertically), none of what they say makes any sense.
The distance the projection of the current pixel is to the floor can be calculated as follows:
- If the pixel is in the center of the screen (in vertical direction), the distance is infinite.
- If the pixel is at the bottom of the screen, you can choose a certain distance, for example 1
- So all the pixels between those are between 1 and infinite, the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height. You can use the formula "currentDist = h / (2.0 * y - h)" for the distance of the current pixel.
- You can also precalculate a lookup table for this instead, since there are only h / 2 possible values (one half of the screen in vertical direction).
"the distance from a pixel in the center of the screen to the floor is infinite" What?
"for the bottom of the screen, you can choose a distance" I'm assuming this would be where my camera elevation goes in
"for example, 1" oh, thank god they chose 1 as their magic number. It's not like that ever comes up anywhere else
"the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height." that wasn't even proper english. Plus, when they say 'inversely' and then use 1/x I assume the 1 is from standard math, but it's the only place on the page where they make any reference to the camera height which they so helpfully chose as 1 earlier.
"you can use this formula" no explanation on how they got that, or anything.
Is it even possible to have different camera elevations with this technique?