-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dfc50e
commit 7bbdaf1
Showing
19 changed files
with
1,170 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution_ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by_sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_LIBRARY_H | ||
#define HT_TWEEN_EASING_LIBRARY_H | ||
|
||
#include "Easing/BackEase.h" | ||
#include "Easing/BounceEase.h" | ||
#include "Easing/CircularEase.h" | ||
#include "Easing/CubicEase.h" | ||
#include "Easing/ElasticEase.h" | ||
#include "Easing/ExponentialEase.h" | ||
#include "Easing/LinearEase.h" | ||
#include "Easing/QuadraticEase.h" | ||
#include "Easing/QuarticEase.h" | ||
#include "Easing/QuinticEase.h" | ||
#include "Easing/SineEase.h" | ||
|
||
namespace Ease = ht::ease; | ||
template <typename EasingType> | ||
using EasingFunc = Ease::Easing<EasingType>; | ||
|
||
#endif // HT_TWEEN_EASING_LIBRARY_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution_ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by_sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_BACKEASE_H | ||
#define HT_TWEEN_EASING_BACKEASE_H | ||
|
||
#include "EasingBase.h" | ||
#include "Types.h" | ||
|
||
namespace ht { | ||
namespace ease { | ||
|
||
class BackEase : public EasingBase | ||
{ | ||
double v_overshoot {1.70158}; | ||
|
||
public: | ||
|
||
virtual ~BackEase() {} | ||
|
||
virtual double easeIn(double t) const | ||
{ | ||
t /= t_scale; | ||
return v_scale * t * t * ((v_overshoot + 1.) * t - v_overshoot); | ||
} | ||
|
||
virtual double easeOut(double t) const | ||
{ | ||
t = t / t_scale - 1.; | ||
return v_scale * (t * t * ((v_overshoot + 1.) * t + v_overshoot) + 1.); | ||
} | ||
|
||
virtual double easeInOut(double t) const | ||
{ | ||
double overshoot = v_overshoot * 1.525; | ||
t /= t_scale / 2.; | ||
if(t < 1.) | ||
return v_scale / 2. * (t * t * ((overshoot + 1.) * t - overshoot)); | ||
t -= 2.; | ||
return v_scale / 2. * (t * t * ((overshoot + 1.) * t + overshoot) + 2.); | ||
} | ||
|
||
void overshoot(const double ovs) { v_overshoot = ovs; } | ||
double overshoot() const { return v_overshoot; } | ||
}; | ||
|
||
template <> | ||
struct Easing<BackIn> : public BackEase | ||
{ | ||
double get(const double t) const { return BackEase::easeIn(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<BackOut> : public BackEase | ||
{ | ||
double get(const double t) const { return BackEase::easeOut(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<BackInOut> : public BackEase | ||
{ | ||
double get(const double t) const { return BackEase::easeInOut(t); } | ||
}; | ||
|
||
} // ease | ||
} // ht | ||
|
||
#endif // HT_TWEEN_EASING_BACKEASE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution_ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by_sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_BOUNCEEASE_H | ||
#define HT_TWEEN_EASING_BOUNCEEASE_H | ||
|
||
#include "EasingBase.h" | ||
|
||
namespace ht { | ||
namespace ease { | ||
|
||
class BounceEase : public EasingBase | ||
{ | ||
public: | ||
|
||
virtual ~BounceEase() {} | ||
|
||
virtual double easeIn(double t) const | ||
{ | ||
return v_scale - easeOut(t_scale - t); | ||
} | ||
|
||
virtual double easeOut(double t) const | ||
{ | ||
t /= t_scale; | ||
if (t < (1. / 2.75)) | ||
return v_scale * (7.5625 * t * t); | ||
else if (t < (2. / 2.75)) | ||
{ | ||
t -= 1.5 / 2.75; | ||
return v_scale * (7.5625 * t * t + 0.75); | ||
} | ||
else if (t < (2.5 / 2.75)) | ||
{ | ||
t -= 2.25 / 2.75; | ||
return v_scale * (7.5625 * t * t + 0.9375); | ||
} | ||
t -= 2.625 / 2.75; | ||
return v_scale * (7.5625 * t * t + 0.984375); | ||
} | ||
|
||
virtual double easeInOut(double t) const | ||
{ | ||
if(t < t_scale / 2.) | ||
return easeIn(t * 2.) * 0.5; | ||
else | ||
return easeOut(t * 2. - t_scale) * 0.5 + v_scale * 0.5; | ||
} | ||
}; | ||
|
||
template <> | ||
struct Easing<BounceIn> : public BounceEase | ||
{ | ||
double get(const double t) const { return BounceEase::easeIn(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<BounceOut> : public BounceEase | ||
{ | ||
double get(const double t) const { return BounceEase::easeOut(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<BounceInOut> : public BounceEase | ||
{ | ||
double get(const double t) const { return BounceEase::easeInOut(t); } | ||
}; | ||
|
||
} // ease | ||
} // ht | ||
|
||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution_ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by_sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_CIRCULAREASE_H | ||
#define HT_TWEEN_EASING_CIRCULAREASE_H | ||
|
||
#include "EasingBase.h" | ||
|
||
namespace ht { | ||
namespace ease { | ||
|
||
class CircularEase : public EasingBase | ||
{ | ||
public: | ||
|
||
virtual ~CircularEase() {} | ||
|
||
virtual double easeIn(double t) const | ||
{ | ||
t /= t_scale; | ||
return -v_scale * (sqrt(1. - t * t) - 1.); | ||
} | ||
|
||
virtual double easeOut(double t) const | ||
{ | ||
t = t / t_scale - 1.; | ||
return v_scale * sqrt(1. - t * t); | ||
} | ||
|
||
virtual double easeInOut(double t) const | ||
{ | ||
t /= t_scale / 2.; | ||
if(t < 1.) return -v_scale / 2. * (sqrt(1. - t * t) - 1.); | ||
t -= 2.; | ||
return v_scale / 2. * (sqrt(1. - t * t) + 1.); | ||
} | ||
}; | ||
|
||
template <> | ||
struct Easing<CircIn> : public CircularEase | ||
{ | ||
double get(const double t) const { return CircularEase::easeIn(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<CircOut> : public CircularEase | ||
{ | ||
double get(const double t) const { return CircularEase::easeOut(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<CircInOut> : public CircularEase | ||
{ | ||
double get(const double t) const { return CircularEase::easeInOut(t); } | ||
}; | ||
|
||
} // ease | ||
} // ht | ||
|
||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution-ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by-sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_CUBICEASE_H | ||
#define HT_TWEEN_EASING_CUBICEASE_H | ||
|
||
#include "EasingBase.h" | ||
|
||
namespace ht { | ||
namespace ease { | ||
|
||
class CubicEase : public EasingBase | ||
{ | ||
public: | ||
|
||
virtual ~CubicEase() {} | ||
|
||
virtual double easeIn(double t) const | ||
{ | ||
t /= t_scale; | ||
return v_scale * t * t * t; | ||
} | ||
|
||
virtual double easeOut(double t) const | ||
{ | ||
t = t / t_scale - 1.; | ||
return v_scale * (t * t * t + 1.); | ||
} | ||
|
||
virtual double easeInOut(double t) const | ||
{ | ||
t /= t_scale / 2.; | ||
if (t < 1.) return v_scale / 2. * t * t * t; | ||
t -= 2.; | ||
return v_scale / 2. * (t * t * t + 2.); | ||
} | ||
}; | ||
|
||
template <> | ||
struct Easing<CubicIn> : public CubicEase | ||
{ | ||
double get(const double t) const { return CubicEase::easeIn(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<CubicOut> : public CubicEase | ||
{ | ||
double get(const double t) const { return CubicEase::easeOut(t); } | ||
}; | ||
|
||
template <> | ||
struct Easing<CubicInOut> : public CubicEase | ||
{ | ||
double get(const double t) const { return CubicEase::easeInOut(t); } | ||
}; | ||
|
||
} // ease | ||
} // ht | ||
|
||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Easing Functions: Copyright (c) 2010 Andy Brown | ||
* http://www.andybrown.me.uk | ||
* | ||
* This work is licensed under a Creative Commons | ||
* Attribution_ShareAlike 3.0 Unported License. | ||
* http://creativecommons.org/licenses/by_sa/3.0/ | ||
*/ | ||
|
||
#pragma once | ||
#ifndef HT_TWEEN_EASING_EASINGBASE_H | ||
#define HT_TWEEN_EASING_EASINGBASE_H | ||
|
||
namespace ht { | ||
namespace ease { | ||
|
||
class EasingBase | ||
{ | ||
protected: | ||
|
||
double v_scale {1.}; | ||
double t_scale {1.}; | ||
|
||
public: | ||
|
||
// easing API methods | ||
virtual double easeIn(double t) const = 0; | ||
virtual double easeOut(double t) const = 0; | ||
virtual double easeInOut(double t) const = 0; | ||
|
||
// common properties | ||
void duration(const double t) { t_scale = t; } | ||
void scale(const double s) { v_scale = s; } | ||
double duration() const { return t_scale; } | ||
double scale() const { return v_scale; } | ||
}; | ||
|
||
template <typename> | ||
struct Easing | ||
{ | ||
double get(const double t); | ||
}; | ||
|
||
} // ease | ||
} // ht | ||
|
||
#endif |
Oops, something went wrong.