[Fieldtrip] windowPoint function in Reactive/GLUT/SimpleGL.hs

Conal Elliott conal at conal.net
Mon Dec 1 13:00:23 EST 2008


forwarding from reactive at haskell.org :

---------- Forwarded message ----------
From: David Sankel <camior at gmail.com>
Date: 2008/12/1
Subject: Re: [reactive] windowPoint function in Reactive/GLUT/SimpleGL.hs
To: Peter Verswyvelen <bugfact at gmail.com>
Cc: reactive at haskell.org


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:

   - 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).
   - 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.

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?

David


2008/11/29 Peter Verswyvelen <bugfact at gmail.com>:

> The windowPoint function in Reactive/GLUT/SimpleGL.hs has the following
> comment:
> -- | Convert a window position to a logical X,Y.  Logical zero is at the
> -- origin, and [size??].
> --
> -- TODO: this def is completely broken.  What do I even want?  Probably to
> -- go backward through the viewing transform to the XY plane.
> The function I made in the past for doing this is:
>
> windowPoint :: GL.Position -> IO (Double,Double)
> windowPoint pos@(GL.Position x y) =
>   do
>     viewport@(_,GL.Size _ height) <- get GL.viewport
>     modelviewMatrix <- getMatrix $ GL.Modelview 0
>     projectionMatrix <- getMatrix  $ GL.Projection
>     let pos3 = GL.Vertex3 (fromIntegral x) (fromIntegral (height-y)) 0
>     GL.Vertex3 vx vy _ <- GLU.unProject pos3 modelviewMatrix
> projectionMatrix viewport
>     return (vx,vy)
>   where
>     getMatrix :: GL.MatrixMode -> IO(GL.GLmatrix Scalar)
>     getMatrix mode = get $ GL.matrix $ Just mode
>
>
> _______________________________________________
> Reactive mailing list
> Reactive at haskell.org
> http://www.haskell.org/mailman/listinfo/reactive
>
>



-- 
David Sankel

_______________________________________________
Reactive mailing list
Reactive at haskell.org
http://www.haskell.org/mailman/listinfo/reactive
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/fieldtrip/attachments/20081201/f7f32ea1/attachment-0001.htm


More information about the FieldTrip mailing list