mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-29 19:55:37 +00:00
Add math/Misc.h
This commit is contained in:
parent
e37db2c2e0
commit
dbdf6ed054
|
@ -2,6 +2,7 @@
|
|||
#ifndef ES_CORE_GUI_COMPONENT_H
|
||||
#define ES_CORE_GUI_COMPONENT_H
|
||||
|
||||
#include "math/Misc.h"
|
||||
#include "math/Transform4x4f.h"
|
||||
#include "HelpPrompt.h"
|
||||
#include "HelpStyle.h"
|
||||
|
@ -62,7 +63,7 @@ public:
|
|||
|
||||
float getRotation() const;
|
||||
void setRotation(float rotation);
|
||||
inline void setRotationDegrees(float rotation) { setRotation((float) (rotation * M_PI / 180)); }
|
||||
inline void setRotationDegrees(float rotation) { setRotation((float)ES_DEG_TO_RAD(rotation)); }
|
||||
|
||||
float getScale() const;
|
||||
void setScale(float scale);
|
||||
|
|
61
es-core/src/math/Misc.h
Normal file
61
es-core/src/math/Misc.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
#ifndef ES_CORE_MATH_MISC_H
|
||||
#define ES_CORE_MATH_MISC_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define ES_PI (3.1415926535897932384626433832795028841971693993751058209749445923)
|
||||
#define ES_RAD_TO_DEG(x) ((x) * (180.0 / ES_PI))
|
||||
#define ES_DEG_TO_RAD(x) ((x) * (ES_PI / 180.0))
|
||||
|
||||
namespace Math
|
||||
{
|
||||
inline float scroll_bounce(const float delayTime, const float scrollTime, const float currentTime, const int scrollLength)
|
||||
{
|
||||
if(currentTime < delayTime)
|
||||
{
|
||||
// wait
|
||||
return 0;
|
||||
}
|
||||
else if(currentTime < (delayTime + scrollTime))
|
||||
{
|
||||
// lerp from 0 to scrollLength
|
||||
const float fraction = (currentTime - delayTime) / scrollTime;
|
||||
return (float)(((1.0 - cos(ES_PI * fraction)) * 0.5) * scrollLength);
|
||||
}
|
||||
else if(currentTime < (delayTime + scrollTime + delayTime))
|
||||
{
|
||||
// wait some more
|
||||
return scrollLength;
|
||||
}
|
||||
else if(currentTime < (delayTime + scrollTime + delayTime + scrollTime))
|
||||
{
|
||||
// lerp back from scrollLength to 0
|
||||
const float fraction = 1.0 - (currentTime - delayTime - scrollTime - delayTime) / scrollTime;
|
||||
return (float)(((1.0 - cos(ES_PI * fraction)) * 0.5) * scrollLength);
|
||||
}
|
||||
|
||||
// and back to waiting
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline float scroll_loop(const float delayTime, const float scrollTime, const float currentTime, const int scrollLength)
|
||||
{
|
||||
if(currentTime < delayTime)
|
||||
{
|
||||
// wait
|
||||
return 0;
|
||||
}
|
||||
else if(currentTime < (delayTime + scrollTime))
|
||||
{
|
||||
// lerp from 0 to scrollLength
|
||||
const float fraction = (currentTime - delayTime) / scrollTime;
|
||||
return fraction * scrollLength;
|
||||
}
|
||||
|
||||
// and back to waiting
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ES_CORE_MATH_MISC_H
|
Loading…
Reference in a new issue