I've been watching a 3D tutorial on youtube about doing 3D graphics in Java without any exterior libraries -- just standard Java. I've been curious about how 3D graphics work down at the lower levels; I've used Unity and openGL to make applications, and now I'm aiming to go a step deeper into my understanding of 3D graphics (I also am very intrigued into the mathematics behind it all). And here is where my question arises.
Below is a function in the Render3D class for the tutorial. Using what's written below, it takes two for loops to go through each pixel in the pixels array, and end up drawing a green and blue checkered pattern shown here:
public void floor() {
for (int y = 0; y < height; y++) {
double ceiling = (y - height / 2.0) / height;
double z = 8 / ceiling;
for (int x = 0; x < width; x++) {
double depth = (x - width / 2.0) / height;
depth *= z;
int xx = (int) (depth) & 15;
int yy = (int) (z) & 15;
pixels[x + y * width] = (xx << 4)||(yy << 4)<< 8;
}
}
}
basically, I'm wondering if anyone has a good explanation for how this works or what the name of the algorithm is. I understand how this physically chooses what color to put in each pixel (by following through the code and printing out values), but how does this relate to rendering a 3D environment later on?
Thanks in advance! Let me know if more information is needed as well.
--Chris