Rand Barnett - Make a 3d video gaming engine with basic math and programming - Math part 2


Now we are viewing from the side instead of from above (map view). We are the dot on the right side of the screen. The dot is our eyes, our point of view. They are 5 feet off the ground. The first dot is still 5 feet in front of us. It is on the ground, so it is 5 feet below us too. So we do the math there:

a is to b what c is to d

In this case, a is 5 feet. b is 5 feet. c is unknown (what we are trying to figure out), so I am calling it n, which is typical in computer programming. And then d is one foot, the height of our viewport.

Cross multiply and divide. 5 times 1 is 5. 5 times n is 5n. n = 1

We do the same for the back dot. It is 10 feet away and still 5 feet below us.

Cross multiply and divide. 10 times 1 is 10. 5 times n is 5n. n = 10/5 = 2

Now we multiply these by the viewport (1,000 pixels). The dot closest to us is 1,000 pixels down and the one farthest from is is 500 pixels down.
Now we put it on the computer monitor. The dot that is 500 pixels to the left is 1,000 pixels down. The dot farthest away from us is 250 pixels to the left and 500 pixels down.
We can confirm from the working model that dot on the left is about twice as far out as the dot that is the back corner. We can also see that the far left dot is about twice as far down as the dot that is the back left corner. Our numbers would display something similar if our screen was that size. The computer monitor is actually only about 1,000 pixels high currently, so we would have to change our viewport for these numbers to work better. We can change the viewport number to anything we want. If we change it to a smaller number, everything will just get smaller.