Created
January 11, 2024 11:56
-
-
Save PapeCoding/9deab7070821b9cfe8206e182a19a947 to your computer and use it in GitHub Desktop.
Simple Exponential Moving Average Filter for Dasher Mouse Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
[...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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