Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it not possible to obtain mouse coordinates as floating point values?

It seems to me that it could be useful in some cases to read higher precision values from the mouse, rather than just a range of discrete pixel coordinates over the current screen resolution. Obviously there is no need for this in GUIs, but for some games it might not even make any sense to associate it with screen resolution at all.

Why are we forced to read it as pixel coordinates instead of just raw analog values?

like image 261
Steve Vermeulen Avatar asked Jun 24 '12 17:06

Steve Vermeulen


People also ask

How to find the coordinates of the mouse over the screen?

The top left corner of the screen is (0, 0) i,e, X and Y coordinate is (0, 0). This means that vertical zero is topmost point and horizontal zero is the leftmost point. So, the task is to find the coordinates of the mouse over the screen. It can be find using the clientX and clientY property:

What is the purpose of floating point numbers?

The floating-point numbers serve as rough approximations of mathematical real numbers. They do not represent the exact value. For this reason, we compare the arithmetic results of float variables with a minimum tolerance value.

How does a computer work with a float value?

To understand this, you first have to know how a computer works with float values. When a float variable is initialized, the computer treats it as an exponential value and allocates 4 bytes (32 bits) memory where the mantissa part occupies 24 bits, the exponent part occupies 7 bits, and the remaining 1 bit is used to denote sign.

What is the maximum number a small float can represent?

The small float can not represent 1.3, 2.4, 5.6, etc. In that case, small float approximates them. It can not represent numbers bigger than 7. Besides many combinations represent the same value.


1 Answers

Under Windows at least, you can retrieve higher resolution coordinates, from 0 to 0xffff, rather than the mouse position translated to screen coordinates, for devices that support high-resolution reporting

Retrieves high resolution points. Points can range from zero to 65,535 (0xFFFF) in both x- and y-coordinates. This is the resolution provided by absolute coordinate pointing devices such as drawing tablets.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646259(v=vs.85).aspx

One can use non-standard scaling to achieve sub-pixel resolution on the Mac according to one answer here:

High resolution and high framerate mouse coordinates on OSX? (Or other solution?)

Neither answer to that question was accepted, but it may be worth further investigation.

like image 150
Eric J. Avatar answered Oct 10 '22 23:10

Eric J.