Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Non-Cursor Dependant Mouse Input  (Read 1322 times)

0 Members and 1 Guest are viewing this topic.

Everyday Everything

  • Newbie
  • *
  • Posts: 3
    • View Profile
Non-Cursor Dependant Mouse Input
« on: December 10, 2010, 10:49:37 pm »
First off, this being my first post, I would like to say that SFML is pretty awesome. I've had trouble finding something that really allowed me to dable in game programming the way I wanted to. I always find myself quickly outgrowing the constraints of what ever I've tried or ending up way over my head, sometimes unable to even get a working program at all.

But on to my question. I've been looking into using a more "raw" type of input from the mouse to look around a 3D environment. To be honest, setting the cursor to the middle of the screen, then reading/reseting the coordinates has worked pretty good, thus far save for a few unexplained jumps in my view now and then.

However I would like to avoid troubles with desktop mouse adjustments, like mouse acceleration. I am also concerned that reading the pixel change limits the accuracy of the mouse.

Could someone give me any ideas or suggestions?

EDIT:
After doing even more googling and thinking, I now imagine that offering the option to change the mouse settings in game is probably my best solution, such as being able to turn on/off pointer acceleration/enhanced pointer precision.

Also, when looking around the scene I could potentially increase windows pointer speed and then scale back the rotation speed in the game thereby increasing accuracy, if I decide that it is not accurate enough. Of course, now this self taught novice programmer (me) needs to figure out how to program in that . . .  :shock: . . . maybe just in Windows for now.

If I figure it out, I'll post it for anyone else having similar thoughts . . .

EDIT 2:
Here is some example functions, in case anyone else is looking for this type of solution.  This WILL change the windows settings for the user and I suggest that if you plan to use this, you save the default settings and apply them any time the program does not have focus and especially once it is closed. If your program crashes, you will obviously leave your user with the new mouse settings.

Since I am using SFML I am not certain what all you have to include to use this command, however I am certain you require <winuser.h>. Also, I should note that the SystemParametersInfo() function returns a bool but I am not capturing it.

Code: [Select]

void SetMouseSpeed(int speed) {
    SystemParametersInfo(SPI_SETMOUSESPEED, NULL, reinterpret_cast<void*>(speed), SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
}

int GetMouseSpeed() {
    int speed;
    SystemParametersInfo(SPI_GETMOUSESPEED, NULL, &speed, 0);
    return speed;
}

///Mouse Acceleration
/*The system applies two tests to the specified relative mouse motion when applying acceleration.
If the specified distance along either the x or y axis is greater than the first mouse threshold
value, and the mouse acceleration level is not zero, the operating system doubles the distance.
If the specified distance along either the x- or y-axis is greater than the second mouse threshold
value, and the mouse acceleration level is equal to two, the operating system doubles the distance
that resulted from applying the first threshold test. It is thus possible for the operating system
to multiply relatively-specified mouse motion along the x- or y-axis by up to four times.*/

//Sets the two mouse threshold values and the mouse acceleration. The pvParam parameter must point to an array of three integers that specifies these values.
void SetMouseAccel(int threshold1,int threshold2,int speed) {
    int info[3];
    info[0]=threshold1;
    info[1]=threshold2;
    SystemParametersInfo(SPI_SETMOUSE, NULL, info, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
}

//Retrieves the two mouse threshold values and the mouse acceleration. The pvParam parameter must point to an array of three integers that receives these values.
int GetMouseAccel(int *threshold1,int *threshold2) {
    int info[3];
    SystemParametersInfo(SPI_GETMOUSE, NULL, &info, 0);
    *threshold1 = info[0];
    *threshold2 = info[1];
    return info[2];

}


ps. If anyone has a better idea or knows how to get non-cursor dependent mouse input, let me know  :D

I'm sure there are better ways than my hack.

 

anything