PDA

View Full Version : Mouse x,y to world x,y



02-20-2003, 01:40 AM
How can I convert the current mouse x,y from pixels to world space in Ortho view ?

My calculations are messed, obv it works if it is a 1 to 1 ratio, that is

cursor.x = x
cursor.y = SCREEN_HEIGHT - y

however this is not realistic as my screen height and perpective height etc.. may never be the same.

I was trying to get a ratio of the different sizes

cursor.x = x / (SCR_PIXELSX/ORTHO_WIDTH)
cursor.y = SCR_PIXELSY - (SCR_PIXELSY/ORTHO_HEIGHT)

this does not work either, I want to just move a quad with the same cursor pos for my gui.

any ideas ?

jebus
02-20-2003, 05:49 AM
look up gluProject and gluUnproject. you will need to get the viewport and the projection/modelview matrices to use these funcitons.

jebus