Skip to content

Instantly share code, notes, and snippets.

@PapeCoding
Created January 11, 2024 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PapeCoding/9deab7070821b9cfe8206e182a19a947 to your computer and use it in GitHub Desktop.
Save PapeCoding/9deab7070821b9cfe8206e182a19a947 to your computer and use it in GitHub Desktop.
Simple Exponential Moving Average Filter for Dasher Mouse Input
// replace the content of the function with the one below:
[...]
bool CDasherMouseInput::GetScreenCoords(screenint &iX, screenint &iY, CDasherView *pView)
{
POINT mousepos;
GetCursorPos(&mousepos);
ScreenToClient(m_hwnd, &mousepos);
const float smoothing = (SmoothedPositionX < 0) ? 1.0f : SmoothingFactor;
SmoothedPositionX = smoothing * mousepos.x + (1.0f - smoothing) * SmoothedPositionX;
SmoothedPositionY = smoothing * mousepos.y + (1.0f - smoothing) * SmoothedPositionY;
iX = static_cast<Dasher::screenint>(SmoothedPositionX);
iY = static_cast<Dasher::screenint>(SmoothedPositionY);
return true;
}
[...]
// Add the three float variables below
[...]
class Dasher::CDasherMouseInput : public CScreenCoordInput {
[...]
private:
float SmoothedPositionX = -1.0f;
float SmoothedPositionY = -1.0f;
const float SmoothingFactor = 0.05f;
};
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment