Getting OpenGL mouse pos in nehe C# basecode

Started by
2 comments, last by eSCHEn 18 years, 6 months ago
I am really, really stuck with this. I'm making a sort of level editor based on the nehe OpenGL C# basecode, but the one thing I cant get right is the mouse input. I used a global hook to get the mouse input, but this only gives me global screen coordinates, and I have no way of calculating the opengl mouse position. The basecode doesnt use glut and I could never convert it to glut with my skills. I can get the position of the whole window but thats not enough; global_mouse_pos - window_pos still wouldnt cater for the thickness of the title bar and borders etc. As far as I know theres no way of getting the global position of the opengl control, because all the app knows is that its at 0,0 in relative coordinates. Does anyone have any advice on how I can do this? or is the only way to try to implement glut? If its even possible, can the glutMouseFunc stuff be used without setting up the whole app with glut?
------------------physics-editor.com
Advertisement
Are you wanting a 2D position with an orthographic projection or 3D position? For a 2D position, the equivalent of ScreenToClient is PointToClient in C#. You would grab the screen position, convert into window co-ordinates and then providing you have a matching orthographic projection you have your OpenGL position. For a 3D situation, like deciding "is the mouse over the sphere?" then you would want to use something like gluUnProject.

These links may be of help:

Also, have a Google for gluUnProject and gluProject.

Hope that was of some help and good luck!
--
Cheers,
Darren Clark
Yes it was the 2d position I wanted, pointToClient was exactly what I needed. Thanks for your help!
------------------physics-editor.com
Not a problem, glad I could be of help.
--
Cheers,
Darren Clark

This topic is closed to new replies.

Advertisement