title: How do I find the world coordinates of a pixel on the image plane?
body: <h2>A bit of background</h2>
  
  <p>I am writing a simple ray tracer in C++. I have most of the core complete but don't understand how to retrieve the world coordinate of a pixel on the image plane. I need this location so that I can cast the ray into the world.</p>
  
  <p>Currently I have a Camera with a position(aka my perspective reference point), a direction (vector) which is not normalized. The directions length signifies the center of the image plane and which way the camera is facing.</p>
  
  <p>There are other values associated with the camera but they should not be relevant.</p>
  
  <p>My image coordinates will range from -1 to 1 and the perspective(focal length), will change based on the distance of the direction associated with the camera.</p>
  
  <h2>What I need help with</h2>
  
  <p>I need to go from pixel coordinates (say [0, 256] in an image 256 pixels on each side) to my world coordinates.</p>
  
  <p>I will also want to program this so that no matter where the camera is placed and where it is directed, that I can find the pixel in the world coordinates. (Currently the camera will almost always be centered at the origin and will look down the negative z axis. I would like to program this with the future changes in mind.) It is also important to know if this code should be pushed down into my threaded code as well. Otherwise it will be calculated by the main thread and then the ray will be used in the threaded code.</p>
  
  <p><a href="https://i.stack.imgur.com/IAP07.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IAP07.gif" alt="Example of general idea"></a><br>
  <sub>(source: <a href="http://campar.in.tum.de/twiki/pub/Students/SepStetter/PinholeCam.gif" rel="nofollow noreferrer">in.tum.de</a>)</sub>  </p>
  
  <p>I did not make this image and it is only there to give an idea of what I need.</p>
  
  <p>Please leave comments if you need any additional info. Otherwise I would like a simple theory/code example of what to do.</p>