Hello Guest

Mouse locations seem inaccurate.

  • 3 Replies
  • 4498 Views
Mouse locations seem inaccurate.
« on: March 03, 2009, 01:50:24 »
I am creating a app that will track user inputs on a touch screen.  I have been developing on a centos 5 box, under eclipse 3.2.1.  I have everything integerated and have started tracking the mouse positions.  From what I can see from the recording of the mouse events, they seem to be off.  Either my location where I am painting is wrong, or the mouse recording event is wrong.

Here is the example:

I supposedly painted a disc at
x = 350, y = 629, width and height = 30;

I moved the mouse to be in the center of the painted object, and the mouse points are
x=349, y= 626.  The mouse is in the center of the object and  then I mouse click on the left.


Not sure how the mouse points work, and how the translate of x, y for the object work. 

The points shown above for the disk, are the points I am tracking with.

The translation I am using is Translate3f (x,y, 0); to paint the disc/ball on the screen

Thanks in advance.

Brian

Re: Mouse locations seem inaccurate.
« Reply #1 on: March 03, 2009, 10:10:25 »
How far off is your mouse position? 1-3 pixels don't sound like much.

Keep in mind that the mouse and OpenGL use different coordinate systems, depending on your model view, projection and viewport. You can use gluUnProject and gluProject to convert between the two.
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/unproject.html
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/project.html

Translate3f (x,y, 0) sets the origin of the object coordinate system to (x,y, 0). Depending on how your object (the disc) is drawn, that may be its center, its bottom left corner or an arbitrary point. It depends on where your object is located in its object coordinate system. In your case it's highly likely to be its center.

Re: Mouse locations seem inaccurate.
« Reply #2 on: March 03, 2009, 17:37:09 »
Actually the mouse position is off it seems between 15-30 pixels.  In the example I gave, it may look like 1-3 pixels, but the mouse position supposedly was the near the center of that rectangle area and not at the upper left corner.  So you could see what I am driving at if I am hitting what is the center of a 30x30 pixel square area, but the mouse point is reporting just outside of the rectangle area I have a problem.  This is linear but should show what I mean 
R = report, | = rect edge, x= click point, - internal rectangle area, _ outer rectangle area.

R___|---------------x--------------|

So with the above.  The x is what the click point would be on the screen, but when it reports, the co-or is the R position.

Brian


Re: Mouse locations seem inaccurate.
« Reply #3 on: March 04, 2009, 04:41:36 »
Problem solved.  I wasn't using the disk creation properly.  Two problems I had were:

1)  Was using a diameter and not a radius for the drawing!
2)  Since I am using a rectangle to check for hits.  The drawing of the circle must move to the center of the rectangle.  I was keeping the draw point as the upper left of the rectangle, so we would be offset by the distance to the center. 

Got to get back to basic math and geometry.

Sorry to have bothered.