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 compute Z made it too far zoomed out in comparison to my example image. I was getting a weird fisheye effect. So I played around with a zoom factor, which is a small value which I ended up subtracting from every single Z-coordinate. It was 0.12. I don't know yet if this will need to be adjusted when using a different field of view. If so, it might just be a ratio of 1/8. To be ascertained tomorrow...
  • My GitHub repo (in progress) is located here


Comments

Popular posts from this blog

Unleashing my inner Disney Princess ✩₊˚.⋆☾⋆⁺₊✧ at the 2024 Disney Princesses Half Marathon

The 20-something types of Computer Science majors

The Evenstar