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

Peter Verswyvelen bugfact at gmail.com
Sat Nov 29 12:11:49 EST 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20081129/5b512c14/attachment.htm


More information about the Reactive mailing list