[SDL] Translating mouse coordinates in SDL into OpenGL space

Started by
13 comments, last by adam_o 16 years, 3 months ago
Quote:Original post by smart_idiot

*** Source Snippet Removed ***

The value for mouse_depth is a tricky value to get, how far into the screen is the mouse? You can either use gluProject on a known point, and use its depth, making the mouse as far into the screen as that point is, or you can read the data from the depth buffer, and use the point under the mouse, in which case it will follow the surface of the geometry being rendered.


Ok, here's some nice help. A few questions though:
• Is your "mouse_x" and "mouse_y" equivalent to my x_loc and y_loc?
• Correct me if I'm wrong, but isn't the point of this to take the 2D coordinates of the mouse and "UnProject" them so I can know where the mouse is clicking? The mouse doesn't have a 3rd dimension in SDL, so it only gives me 2 dimensions, so where does that put "mouse_depth"?

Also, I still get the "cannot convert..." errors with the matrix arrays. The computer's telling me that the second argument of glGetDoublev() is ONE double, not a double array.
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
Advertisement
Is your "mouse_x" and "mouse_y" equivalent to my x_loc and y_loc?
Most likely.

Correct me if I'm wrong, but isn't the point of this to take the 2D coordinates of the mouse and "UnProject" them so I can know where the mouse is clicking? The mouse doesn't have a 3rd dimension in SDL, so it only gives me 2 dimensions, so where does that put "mouse_depth"?

You'll need to specify the depth. Are you pointing to the surface of the camera lens, some point a million parsecs away, or somewhere in between?

Assuming the point of this is to interact with some object on the screen, use gluProject on that object's center, and then use gluUnProject using your mouse position and the depth value you got from the object, and then the mouse will effectively be floating on an invisible plane intersecting the object you want to interact with.

Quote:
The value for mouse_depth is a tricky value to get, how far into the screen is the mouse? You can either use gluProject on a known point, and use its depth, making the mouse as far into the screen as that point is, or you can read the data from the depth buffer, and use the point under the mouse, in which case it will follow the surface of the geometry being rendered.


Also, I still get the "cannot convert..." errors with the matrix arrays. The computer's telling me that the second argument of glGetDoublev() is ONE double, not a double array.

You're probably trying to pass the address of the array and not the array itself.
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.
Quote:Original post by smart_idiot
You'll need to specify the depth. Are you pointing to the surface of the camera lens, some point a million parsecs away, or somewhere in between?

Assuming the point of this is to interact with some object on the screen, use gluProject on that object's center, and then use gluUnProject using your mouse position and the depth value you got from the object, and then the mouse will effectively be floating on an invisible plane intersecting the object you want to interact with.

Ok, so what if I use gluOrtho2D? Then it doesn't have a z axis, correct?
Quote:Original post by smart_idiot
You're probably trying to pass the address of the array and not the array itself.

... and for some reason this made more sense than anything else, no offense to you, it just wasn't clicking.
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
While you have a z-axis in orthogonal projection mode, you won't have any distortion with regards to perspective, so it doesn't matter what Z depth an object is actually at. So in this case, you should be able to pick an arbitrary value for the mouse depth.
---Just trying to be helpful.Sebastian Beschkehttp://randomz.heim.at/
Great. It works perfectly, and gives me perfect precision. randomz++.
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!

This topic is closed to new replies.

Advertisement