views:

266

answers:

2

When i make my program to use only 0-2% cpu (removed some CPU intensive opengl function), my mouse coordinates starts to lag! and when i use 100% CPU (when enabling the opengl function) i get nice and smooth mouse coordinates, note that the opengl function does nothing to my mouse coordinates. look at below image i recorded my rotation function values by using mouse coordinates:

This is with 100% cpu usage (as it should look): no lag

-

This is with 2% cpu usage: lag

It is really annoying problem, because i am using mouse cursor position to change the rotation angle, and with the above image case, it looks really laggy rotation.

I might be able to make own interpolation or something, but i want to know what is causing this and how to fix it.

Im getting mouse coordinates with WM_MOUSEMOVE message and i also tried to use GetCursorPos() on every frame before my rotation code, but it has no difference.

Edit: I noticed that the CPU usage doesnt have to be 100% to get smooth, but the CPU just needs to be "waken up" and then it stays smooth even with low CPU usage.

+1  A: 

Your second graph seems like it is "bunching" updates. Jumps on the Y axis seem to be at a fixed frequency on the X axis.

Speculation:

  • Maybe power saving is kicking your CPU to/from a lower power state. Is this a laptop, or is CPU power saving enabled in Windows/BIOS (I'm not sure where the setting is)?
  • As GMan suggested in his comment, maybe it has to do with how many timeslices your app is getting
  • Some sort of sleep/timer functionality is regressing to a lower resolution. An example would be the difference between timeGetTime() and queryPerformanceCounter(): http://www.geisswerks.com/ryan/FAQS/timing.html
Merlyn Morgan-Graham
Yeah, and it seems to have same coordinate in two sequential frames, when it shouldnt. The graphs represent my mouse movement in x-axis, so in that graph image the x-axis is time passed while moving my mouse, and y-axis is the x-axis recorded values. I dont have sleep/timer, i disabled v-sync code too (so it uses only my GFX card vsync) and it makes no difference.
Newbie
I dont understand "opengl enabled" thing GMan said. The lag appears when opengl is enabled... since my app only has opengl stuff in it, but only variable is the CPU usage, i am starting to think that it might have something to do with the power saving, since my CPU does have power saving capabilities. Could i somehow lie to my CPU so it would use full power?
Newbie
OH and its not a laptop, desktop computer with intel core 2 quad Q6600, i dont know how to disable power saving, and i dont really want to, since it would overheat perhaps if it used all the cores simultaneously with full power for whole day... and its not really a good fix to the problem if i would have to tell each user to do such thing manually.
Newbie
'I dont understand "opengl enabled" thing GMan said' is in reference to your statement 'when enabling the opengl function'.Can you please post some code? That might help beyond our speculation. In particular, if you can get the mouse code in there, and some sort of code (doesn't have to be your original block) that will "boost the CPU to 100%" and will cause the mouse to smooth out.
Merlyn Morgan-Graham
i have this same problem on my other opengl applications as well, and i dont use the same code to boost cpu to 100%, just that when i start sending more data to GPU my CPU gets wild and starts using 100% of one core (sometimes two cores) and then my mouse is nicely smooth. i will try this GetMouseMovePointsEx() function Michael Burr mentioned below.
Newbie
A: 

You might be able to get better information about the mouse motion by using the GetMouseMovePointsEx() API.


Sidenote: for some reason I can only see your first graphic

Michael Burr
heres the second: http://img5.imageshack.us/img5/5514/mousecursorlaggedcoords.png
Newbie