Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created August 30, 2011 15:28
Show Gist options
  • Save satoruhiga/1181164 to your computer and use it in GitHub Desktop.
Save satoruhiga/1181164 to your computer and use it in GitHub Desktop.
ofxSmooth.h
#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