It looks like Peter&#39;s function assumes a parallel projection where the camera is facing -z. I wonder what would be useful in a 3 dimensional space. I can imagine the following scenarios with mapping mouse coordinates:<br>
<ul><li>Intersection of the ray of that pixel&#39;s position/direction in 3D coordinates with the XY, YZ, or XZ planes depending on the camera position and type (parallel or perspective).</li><li>Intersection of the ray of that pixel&#39;s position/direction and an object that it touches. If it doesn&#39;t intersect an object it could either return a point at infinity or an intersection with a plane.</li>
</ul>Implementation would probably involve inspection of the z buffer at that pixel along with Peter&#39;s reverse projection. What would a nice interface look like?<br><br>David<br><br><br>2008/11/29 Peter Verswyvelen &lt;<a href="mailto:bugfact@gmail.com">bugfact@gmail.com</a>&gt;:<br>
&gt; The windowPoint function in&nbsp;Reactive/GLUT/SimpleGL.hs&nbsp;has the following<br>&gt; comment:<br>&gt; -- | Convert a window position to a logical X,Y. &nbsp;Logical zero is at the<br>&gt; -- origin, and [size??].<br>&gt; --&nbsp;<br>
&gt; -- TODO: this def is completely broken. &nbsp;What do I even want? &nbsp;Probably to<br>&gt; -- go backward through the viewing transform to the XY plane.<br>&gt; The function I made in the past for doing this is:<br>&gt;<br>&gt; windowPoint :: GL.Position -&gt; IO (Double,Double)<br>
&gt; windowPoint pos@(GL.Position x y) = <br>&gt; &nbsp; do<br>&gt; &nbsp; &nbsp; viewport@(_,GL.Size _ height) &lt;- get GL.viewport<br>&gt; &nbsp; &nbsp; modelviewMatrix &lt;- getMatrix $ GL.Modelview 0<br>&gt; &nbsp; &nbsp; projectionMatrix &lt;- getMatrix &nbsp;$ GL.Projection<br>
&gt; &nbsp; &nbsp; let pos3 = GL.Vertex3 (fromIntegral x) (fromIntegral (height-y)) 0<br>&gt; &nbsp; &nbsp; GL.Vertex3 vx vy _ &lt;- GLU.unProject pos3 modelviewMatrix<br>&gt; projectionMatrix viewport<br>&gt; &nbsp; &nbsp; return (vx,vy)<br>&gt; &nbsp; where<br>
&gt; &nbsp; &nbsp; getMatrix :: GL.MatrixMode -&gt; IO(GL.GLmatrix Scalar)<br>&gt; &nbsp; &nbsp; getMatrix mode = get $ GL.matrix $ Just mode<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Reactive mailing list<br>
&gt; <a href="mailto:Reactive@haskell.org">Reactive@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/reactive">http://www.haskell.org/mailman/listinfo/reactive</a><br>&gt;<br>&gt;<br><br><br><br>-- <br>
David Sankel<br>