Created
August 30, 2011 15:28
-
-
Save satoruhiga/1181164 to your computer and use it in GitHub Desktop.
ofxSmooth.h
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
#pragma once | |
#include "ofMain.h" | |
template <class T> | |
class ofxSmooth | |
{ | |
T value, value_t; | |
float smooth; | |
public: | |
ofxSmooth(T value_ = T(), float smooth_ = 0.1) : value(value_), value_t(value_) | |
{ | |
setSmooth(smooth_); | |
} | |
const T& operator=(const T& v) | |
{ | |
value_t = v; | |
return value_t; | |
} | |
operator T() const { return value; } // useful | |
const T& get() const { return value; } // maybe fast | |
const T& assign(const T& v) | |
{ | |
value = value_t = v; | |
return value_t; | |
} | |
void update() | |
{ | |
value += (value_t - value) * smooth; | |
} | |
void setSmooth(float v) | |
{ | |
v = ofClamp(v, 0, 1); | |
smooth = v; | |
} | |
float getSmooth() const { return smooth; } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment