Ray Tracing: XYZ coordinates
When ray tracing, it is important to compute the proper XYZ coordinates. This bit me hard over these past few weeks. This is what I figured out: A few things to note: This only works for square images. The math gets weird when you have rectangular ones. In order to use a standard Cartesian Coordinate system, I had to make the Y start at -1. I had to swap my X and Y because of how PPM files are structured, versus how I was looping through my arrays in Java (this is the easiest way to account for it IMO). I was so confused for the longest time as to why my image was rendering vertically instead of horizontally. As you can see, I did some trig to compute Z. It is the same number for every single pixel, and it relates to the field of view, which is 28 in this example (though the formula should be the same regardless). It has to be negative because that's simply the standard for the graphics industry (not sure why). I also found that my formula to co...