Created
March 30, 2016 05:22
-
-
Save ofZach/73cd2cbb0e7757ee9df980c714712b4f to your computer and use it in GitHub Desktop.
framerate independent smoothing example
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
ofPoint pt; | |
ofPoint smoothPt; | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
if (ofGetElapsedTimeMillis() % 5000 < 2500){ | |
ofSetFrameRate(30); | |
} else { | |
ofSetFrameRate(60); | |
} | |
pt.x = 0.99f * pt.x + 0.01 * mouseX; | |
pt.y = 0.99f * pt.y + 0.01 * mouseY; | |
double dt = ofGetLastFrameTime(); | |
smoothPt.x = ofLerp(smoothPt.x, mouseX, 1 - powf(0.6,dt)); | |
smoothPt.y = ofLerp(smoothPt.y, mouseY, 1 - powf(0.6,dt)); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofSetColor(255,0,0); | |
ofCircle(pt, 10); | |
ofSetColor(255,255,0); | |
ofCircle(smoothPt, 5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment