Glut: Screen to world corrodinate mapping

Started by
2 comments, last by TechnoGoth 20 years, 3 months ago
I''m trying to map from mouse clicks on the screen to the openGl world corrident system,(ie, 0,0 is the middle of the screen) this is the system I currently use. x,y are supplied by glut. float mappedX=((x/512.0f)-1.0f)*5.6; float mappedY=((y/384.0f)-1.0f)*-4.2; as anyone can see this only works when the screen resolution is 1024x768. So I have a two part question, 1) is there a way to retrive the screen size using glut? 2) is there a better way to map screen to world? ----------------------------------------------------- Writer, Programer, Cook, I''m a Jack of all Trades Current Design project Chaos Factor Design Document
Advertisement
1) Register a reshape function call back (glutReshapeFunc, as I recall), it takes two arguements, the screen width and the screen height. Store that someplace you can access it.

2)Well, if yer in 3d I would think that you would just use divide the mouse click height by total height and then use that as a modifier for your world coords, but that has more to do with 2d mouse to 3d world coords and I never was too good at that.

If you're in 2d you could change the coords displayed on the screen to something thats slighty easier to map to..

[edited by - _buu_ on January 5, 2004 1:00:04 PM]
Look into ray picking if you want to convert from mouse clicks into world space.
Once upon a time I made a small program what would let you drag shapes around the screen. It''s not glut, but it might still be useful.

It can be found here, and is entitled ''Dragging by Smart Idiot''.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement