title: Screen Coordinates to 2D World
body: <p>This more of a mathy nature but anyway. I need to be able to detect where I click in an image displayed in a quad in OpenGl. The quad is 5000x5000 in size and is rendered at 0,0. Now from what I have seen this is rendered from the middle of the window. This renders the quad in the bottom left corner of the axis's. To counter this, rather than change the vertex's of the quad, and since I need to pan as well I transform before I draw the quad. </p>
  
  <p>So to make the quad centered at startup, I pan by GL.Translate(-2500, -2500), 0).</p>
  
  <p>Now the mouse coordinates are relative to the top left corner of the window, so I break them into a fraction e.g. Mouse.X / Width Mouse.Y / Height</p>
  
  <p>This is where it gets iffy. I know I need to multiply by 5000 but I also need to incorporate the pan somehow.</p>
  
  <p>Im not sure if this is important but this is how my Ortho matrix is setup:</p>
  
  <pre><code>GL.Ortho(-G_.MapSize * 1.5 ^ ZoomFactor, G_.MapSize * 1.5 ^ ZoomFactor, G_.MapSize * 1.5 ^ ZoomFactor, -G_.MapSize * 1.5 ^ ZoomFactor, -1, 1)
  </code></pre>