Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Getting the cursor position

This topic is 4141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am using CsGL/C# for developing a simple checkers game. I follow the tutorials and lessons of Jerome JOUVIE (jerome.jouvie.free.fr), NeHe (nehe.gamedev.net) and some books. It was OK until I start to implement the selection part. A hit never happens. I think that this may happen because I couldn't get the cursor position appropriate. Here is my code for mouse click
public void onMouseClick(object sender, MouseEventArgs e) { int xPozisyon = e.X; int yPozisyon = e.Y; ProcessSelection(xPozisyon, yPozisyon); }
I the lessons I have read they use x = event->data[AUX_MOUSEX]; y = event->data[AUX_MOUSEY]; or int xPos = LOWORD(lParam); int yPos = HIWORD(lParam); Is that the problem for me why I cannot getting a hit. I mean is there a problem with gettting the cursor position inside the OpenGL Control? Thanks for your helps and best regards.

Share this post

Link to post
Share on other sites
Actually I realized that I do not to make any object selection. I need to get where the use clicked (on the scene).

Is it possible to define a reference position for making mathematical operations including the scene's rotation, transformation etc. ?

As I said before, I try to make a checkers game where the board width is 2 and height 2. I create a jagged array like :
public byte[,] boardMatrice = {{0, 2, 0, 2, 0, 2, 0, 2},
{2, 0, 2, 0, 2, 0, 2, 0},
{0, 2, 0, 2, 0, 2, 0, 2},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 0}};

After I draw the board I place the pieces according to this matrice in which 2 is the black player and 1 is the white player.

So -assuming the board is flat- if the user clicks on the board -let's say at (0.688,0.123)- the program should know that the boardMatrice[5,0] is selected. Because the board size is (2,2) so every square size is (0.25,0.25).

So here raises 5 problems :
1- The OpenGL control's Dock property is fill. So when the user changes the size, it may not stick to the left which means -for example- 0.0 to 0.25 does not mean the bottom left square anymore. How can I overcome this?
2- How can I define a reference point which rotates, transgorms etc. with the board? It will be used to make some calculations when the board is rotated, transformed etc.
3- How can I send a ray (-line?) from this reference point to the scene, and see if it intersects with the board. If it intersects how can I get the length, angle etc. of this ray ?
4- The window coordinates' (0,0) is the upper left but for OpenGL it is lower left. How can I change the window coordinate to OpenGL coordinate?
5- If the OpenGL control's size is -let's say- (480,480) does that I mean that the cursor's actual position in -again let's say- (240,120) is (1,0.5) ?

I will appreciate any help and suggestions.


[Edited by - apocalypse_k40 on March 17, 2007 10:15:32 AM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Check this site out, it should answer your questions.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!