Ah yes, true, I only used this function for orthographic (aka parallel) projection.<div><br></div><div>With perspective projection, it makes more sense to return a ray, not a point. With this ray, one can do all kinds of intersections.<br>
</div><div><br></div><div>One could use the Z-buffer to figure out the closest object, but reading from the z-buffer with the CPU is rather slow, and might be rather inaccurate, but for testing purposes, that might work fine.</div>
<div><br></div><div>I guess it all comes down to what kind of &quot;picking&quot; interface one wants. It certainly would be nice to have an Event in reactive-fieldtrip for picking objects :) Since most (if not all?) geometry in fieldtrip is procedural, picking could be made exact?</div>
<div><br></div><div><div class="gmail_quote">On Mon, Dec 1, 2008 at 3:28 PM, David Sankel <span dir="ltr">&lt;<a href="mailto:camior@gmail.com">camior@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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" target="_blank">bugfact@gmail.com</a>&gt;:<div>
<div></div><div class="Wj3C7c"><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></div></div>&gt; _______________________________________________<br>&gt; Reactive mailing list<br>

&gt; <a href="mailto:Reactive@haskell.org" target="_blank">Reactive@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/reactive" target="_blank">http://www.haskell.org/mailman/listinfo/reactive</a><br>
&gt;<br>&gt;<br><br><br><br>-- <br><font color="#888888">
David Sankel<br>
</font></blockquote></div><br></div>