get Scale of the window in HOpenGL?

I want to move one object to the border of window, then go back to the start point. Does anyone one have an idea to implement it ? Thank you! ___________________________________________________________ 好玩贺卡等你发,邮箱贺卡全新上线! http://card.mail.cn.yahoo.com/

Am Samstag, 30. Mai 2009 22:49:20 schrieb yu yang:
I want to move one object to the border of window, then go back to the start point. Does anyone one have an idea to implement it ? Thank you!
Let your viewport fill the whole window, tracking changes in the window size via GLUT's reshape callback: reshape :: ReshapeCallback reshape size@(Size w h) = do viewport $= (Position 0 0, size) <setup your projection matrix using w and h> Then you can use ... (position, size) <- get viewport ... in your rendering code to get the available window area. Then you'll have to apply the inverses of your projection matrix and your modelview matrix to this area to get the object coordinates you want. Depending on what you exactly want to achieve, it might be possible to setup your modelview matrix and your projection matrix in such a way that you get a 1:1 mapping between object coordinates and window coordinates, so you don't have to apply the inverses. Cheers, S.

Hi all,
Depending on what you exactly want to achieve, it might be possible to setup your modelview matrix and your projection matrix in such a way that you get a 1:1 mapping between object coordinates and window coordinates, so you don't have to apply the inverses.
I recently struggeled with this issue, the following reshape callback does exactly this. -- | This function is called when the window is resized reshape s@(OpenGL.Size w h) = do -- Make sure that our model coordinates correspond to pixels OpenGL.matrixMode $= OpenGL.Projection OpenGL.loadIdentity OpenGL.ortho 0 (fromIntegral w) 0 (fromIntegral h) 0 1 -- Do something funky with the viewport OpenGL.viewport $= (OpenGL.Position 0 0, s) I'm not 100% confident about the final 0 and 1 arguments (which specify the bounds on the depth axis, but it works like this (specifying 0 0 didn't work and made the last line be silently ignored!). Alternatively, you could probably set up the projection matrix such that the model coordinates always range from -1 to 1 in both directions. IIRC that is what happens when uinsg only identity matrices and is the default, but I'm not 100% sure. In any case, you always need to set the viewport, AFAIU. Gr. Matthijs
participants (3)
-
Matthijs Kooijman
-
Sven Panne
-
yu yang