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 "picking" 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"><<a href="mailto:camior@gmail.com">camior@gmail.com</a>></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'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'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's position/direction and an object that it touches. If it doesn'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's reverse projection. What would a nice interface look like?<br><br>David<br><br><br>2008/11/29 Peter Verswyvelen <<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>>:<div>
<div></div><div class="Wj3C7c"><br>
> The windowPoint function in Reactive/GLUT/SimpleGL.hs has the following<br>> comment:<br>> -- | Convert a window position to a logical X,Y. Logical zero is at the<br>> -- origin, and [size??].<br>> -- <br>
> -- TODO: this def is completely broken. What do I even want? Probably to<br>> -- go backward through the viewing transform to the XY plane.<br>> The function I made in the past for doing this is:<br>><br>
> windowPoint :: GL.Position -> IO (Double,Double)<br>
> windowPoint pos@(GL.Position x y) = <br>> do<br>> viewport@(_,GL.Size _ height) <- get GL.viewport<br>> modelviewMatrix <- getMatrix $ GL.Modelview 0<br>> projectionMatrix <- getMatrix $ GL.Projection<br>
> let pos3 = GL.Vertex3 (fromIntegral x) (fromIntegral (height-y)) 0<br>> GL.Vertex3 vx vy _ <- GLU.unProject pos3 modelviewMatrix<br>> projectionMatrix viewport<br>> return (vx,vy)<br>> where<br>
> getMatrix :: GL.MatrixMode -> IO(GL.GLmatrix Scalar)<br>> getMatrix mode = get $ GL.matrix $ Just mode<br>><br>><br></div></div>> _______________________________________________<br>> Reactive mailing list<br>
> <a href="mailto:Reactive@haskell.org" target="_blank">Reactive@haskell.org</a><br>> <a href="http://www.haskell.org/mailman/listinfo/reactive" target="_blank">http://www.haskell.org/mailman/listinfo/reactive</a><br>
><br>><br><br><br><br>-- <br><font color="#888888">
David Sankel<br>
</font></blockquote></div><br></div>