Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Step 0: Get gluUnproject:</strong></p> <p>The reports of needing it are true. That function does all the heavy lifting for you. I know at one point the MESA project had an implementation the worked almost perfectly on iOS without modifications. I'm not sure if that's still available. Barring that, you'll just have to do some research on it and either roll your own or port someone else's. It's a bit heavy on the Linear Algebra, so good luck.</p> <p><strong>Step 1: Convert from UIKit coordinates to OpenGL coordinates:</strong></p> <p>This normally involves two things:</p> <ol> <li><p>Flip the Y-coordinate, because UIKit likes its origins in the top left, whereas OpenGL likes its origins in the bottom left.</p> <pre><code>touchLocation.y = [[self view] bounds].size.height - touchLocation.y; </code></pre></li> <li><p>Convert from "Screen Units" to pixels. This keeps things consistent across standard and retina display devices.</p> <pre><code>CGFloat scale = [[UIScreen mainScreen] scale]; touchLocation.y *= scale; touchLocation.y *= scale; </code></pre></li> </ol> <p><strong>Step 3: Use gluUnproject on your converted coordinate:</strong></p> <p><code>gluUnproject()</code> technically converts a 3D point in window space to a 3D point in world space. So, to get a ray, you'll need to call it twice: once for the near clipping plane and once for the far clipping plane. That will give you two points, from which you can get a ray. To call <code>gluUnproject()</code>, you'll need access to your 2D view coordinate, the current OpenGL viewport, the current OpenGL model view matrix, and the current OpenGL projection matrix. Pseudocode:</p> <pre><code>Vector3 near, far; gluUnProject(touchLocation.x, touchLocation.y, 0, _modelview, _projection, _viewport, &amp;near.x, &amp;near.y, &amp;near.z); gluUnProject(touchLocation.x, touchLocation.y, 1, _modelview, _projection, _viewport, &amp;far.x, &amp;far.y, &amp;far.z); return MakeRay(near, Vector3Subtract(far, near)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload