Mode 7 is a very simple effect. It projects a 2D x/y texture (or tiles) to some floor/ceiling. Old SNES use hardware to do this, but modern computers are so powerful that you can do this realtime (and no need of ASM as you mention).
Basic 3D math formula to project a 3D point (x, y, z) to a 2D point (x, y) is:
x' = x / z;
y' = y / z;
When you think about it, it makes sense. Objects that are far in the distance are smaller than objects near you. Think about railroad tracks going to nowhere:
If we look back at the formula's input values: x
and y
will be the current pixel we are processing, and z
will be distance information about how far the point is. To understand what z
should be, look at the picture, it shows z
values for image above:
purple = near distance, red = far away
So in this example, z
value is y - horizon
(assuming (x:0, y:0)
is at the center of screen)
If we put everything together, it becomes: (pseudocode)
for (y = -yres/2 ; y < yres/2 ; y++)
for (x = -xres/2 ; x < xres/2 ; x++)
{
horizon = 20; //adjust if needed
fov = 200;
px = x;
py = fov;
pz = y + horizon;
//projection
sx = px / pz;
sy = py / pz;
scaling = 100; //adjust if needed, depends of texture size
color = get2DTexture(sx * scaling, sy * scaling);
//put (color) at (x, y) on screen
...
}
One last thing: if you want to make a Mario Kart game, I suppose you also want to rotate the map. Well it's also very easy: rotate sx
and sy
before getting the texture value. Here is the formula:
x' = x * cos(angle) - y * sin(angle);
y' = x * sin(angle) + y * cos(angle);
and if you want to move through the map, just add some offset before getting the texture value:
get2DTexture(sx * scaling + xOffset, sy * scaling + yOffset);
NOTE: I tested the algorithm (almost copy-paste) and it works.
Here is the example: http://glslsandbox.com/e#26532.3 (requires recent browser and WebGL enabled)
NOTE2: I used simple math because you said you want something simple (and don't seems familiar with vector math). You can achieve the same things using the Wikipedia formula or tutorials you give. The way they did it is much more complex but you have much more possibilities for configuring the effect (in the end it works the same...).
For more information, I suggest reading this Wikipedia article about perspective projection.