|
floating mouse coordinates |
Loki66
Member #17,089
May 2019
|
Hello, sorry for my bad englishI am an Italian boy and I apologize for my bad English |
LennyLen
Member #5,313
December 2004
|
Assuming you're using Allegro 5, you could do this: ALLEGRO_MOUSE_STATE state; float mx, my; al_get_mouse_state(&state); mx = (float)state.x; my = (float)state.y; Why do you want the co-ordinates as floats?
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
LennyLen, I think we're missing the real purpose here. To get floating point precision mouse coordinates, you'll need to either A) use OS specific system calls to do it or B) Interface with a mouse driver that provides support for high dpi aware pointing devices. Allegro does not provide anything other than on screen integral mouse coordinates. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Loki66
Member #17,089
May 2019
|
Hi, and thanks for the quick reply. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Loki66, that is as expected. dx and dy will probably never be more than two or three. First, you need to know about the different types of variables there are. You can declare a float and assign it the value of an int. You can also cast an int to float or double with (float) or (double). Second, to track the direction, you need to track the starting point. If the distance between your starting point and your end point are small, then you will get large intervals between angles because of low precision. Are you tracking mouse movement? You can always do it like this ; 1int mx = 0,mxstart = 0;
2int my = 0,mystart = 0;
3
4if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
5 mxstart = ev.mouse.x;
6 mystart = ev.mouse.y;
7 drag = true;
8}
9
10if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
11 drag = false;
12}
13
14if (ev.type == ALLEGRO_EVENT_MOUSE_AXES && drag) {
15 mx += ev.mouse.dx;
16 my += ev.mouse.dy;
17 double angle = atan2(my - mystart , mx - mxstart);
18 double degrees = angle*180.0/M_PI;
19}
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SiegeLord
Member #7,827
October 2006
|
If there are platforms which return sub-pixel mouse positions, we can easily add support for them like we did with the "sub-pixel" mouse-wheel positions (via al_set_mouse_wheel_precision) "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Loki66
Member #17,089
May 2019
|
Hello everyone, I solved with atan2 as suggested by Edgar Reynaldo // calculate destination points x, y for the vector // values used are: d_c1dy = event.mouse.dy // d_c1dx = event.mouse.dx Thank you all |
|