add: EaseElasticInOut & EaseBounceInOut
This commit is contained in:
parent
00ee7002f3
commit
098167c606
|
|
@ -75,6 +75,24 @@ namespace easy2d
|
||||||
case EaseFunc::EaseExponentialInOut:
|
case EaseFunc::EaseExponentialInOut:
|
||||||
ease_func_ = math::EaseExponentialInOut;
|
ease_func_ = math::EaseExponentialInOut;
|
||||||
break;
|
break;
|
||||||
|
case EaseFunc::EaseBounceIn:
|
||||||
|
ease_func_ = math::EaseBounceIn;
|
||||||
|
break;
|
||||||
|
case EaseFunc::EaseBounceOut:
|
||||||
|
ease_func_ = math::EaseBounceOut;
|
||||||
|
break;
|
||||||
|
case EaseFunc::EaseBounceInOut:
|
||||||
|
ease_func_ = math::EaseBounceInOut;
|
||||||
|
break;
|
||||||
|
case EaseFunc::EaseElasticIn:
|
||||||
|
ease_func_ = std::bind(math::EaseElasticIn, std::placeholders::_1, 0.3f);
|
||||||
|
break;
|
||||||
|
case EaseFunc::EaseElasticOut:
|
||||||
|
ease_func_ = std::bind(math::EaseElasticOut, std::placeholders::_1, 0.3f);
|
||||||
|
break;
|
||||||
|
case EaseFunc::EaseElasticInOut:
|
||||||
|
ease_func_ = std::bind(math::EaseElasticInOut, std::placeholders::_1, 0.3f);
|
||||||
|
break;
|
||||||
case EaseFunc::EaseSineIn:
|
case EaseFunc::EaseSineIn:
|
||||||
ease_func_ = math::EaseSineIn;
|
ease_func_ = math::EaseSineIn;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,15 @@ namespace easy2d
|
||||||
EaseExponentialIn, // 譚찹긴섐우
|
EaseExponentialIn, // 譚찹긴섐우
|
||||||
EaseExponentialOut, // 譚섐우긴찹
|
EaseExponentialOut, // 譚섐우긴찹
|
||||||
EaseExponentialInOut, // 譚찹逞섐우, 疼譚섐우긋찹
|
EaseExponentialInOut, // 譚찹逞섐우, 疼譚섐우긋찹
|
||||||
|
EaseBounceIn, // 自起点赋予反弹力
|
||||||
|
EaseBounceOut, // 自终点赋予反弹力
|
||||||
|
EaseBounceInOut, // 在起点和终点赋予反弹力
|
||||||
|
EaseElasticIn, // 自起点赋予弹性
|
||||||
|
EaseElasticOut, // 自终点赋予弹性
|
||||||
|
EaseElasticInOut, // 再起点和终点赋予弹性
|
||||||
EaseSineIn, // 譚우긴찹, 꽃痰攣菊긴뻣醵똑
|
EaseSineIn, // 譚우긴찹, 꽃痰攣菊긴뻣醵똑
|
||||||
EaseSineOut, // 譚찹긴우, 꽃痰攣菊긴뻣醵똑
|
EaseSineOut, // 譚찹긴우, 꽃痰攣菊긴뻣醵똑
|
||||||
EaseSineInOut // 譚찹逞우, 疼譚우逞찹, 꽃痰攣菊긴뻣醵똑
|
EaseSineInOut, // 由慢至快, 再由快至慢, 采用正弦变换速度
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tween
|
class Tween
|
||||||
|
|
|
||||||
|
|
@ -98,10 +98,6 @@ namespace easy2d
|
||||||
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
|
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
|
||||||
freopen_s(&stdinStream, "conin$", "r+t", stdin);
|
freopen_s(&stdinStream, "conin$", "r+t", stdin);
|
||||||
freopen_s(&stderrStream, "conout$", "w+t", stderr);
|
freopen_s(&stderrStream, "conout$", "w+t", stderr);
|
||||||
|
|
||||||
// disable the close button of console
|
|
||||||
HMENU hmenu = ::GetSystemMenu(console, FALSE);
|
|
||||||
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -113,6 +109,13 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (console)
|
||||||
|
{
|
||||||
|
// disable the close button of console
|
||||||
|
HMENU hmenu = ::GetSystemMenu(console, FALSE);
|
||||||
|
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
|
||||||
|
}
|
||||||
|
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace easy2d
|
||||||
// 報炎<E5A0B1>連窃侏
|
// 報炎<E5A0B1>連窃侏
|
||||||
enum class Type : int
|
enum class Type : int
|
||||||
{
|
{
|
||||||
MoveBy = 0x0200, // 鼠标移动
|
Move = 0x0200, // 鼠标移动
|
||||||
LeftDown, // 報炎恣囚梓和
|
LeftDown, // 報炎恣囚梓和
|
||||||
LeftUp, // 報炎恣囚箕軟
|
LeftUp, // 報炎恣囚箕軟
|
||||||
LeftDoubleClick, // 報炎恣囚褒似
|
LeftDoubleClick, // 報炎恣囚褒似
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,14 @@ namespace easy2d
|
||||||
dirty_transform_ = true;
|
dirty_transform_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::MoveBy(float x, float y)
|
void Unit::Move(float x, float y)
|
||||||
{
|
{
|
||||||
this->SetPosition(transform_.position.x + x, transform_.position.y + y);
|
this->SetPosition(transform_.position.x + x, transform_.position.y + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::MoveBy(const Point & v)
|
void Unit::Move(const Point & v)
|
||||||
{
|
{
|
||||||
this->MoveBy(v.x, v.y);
|
this->Move(v.x, v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::SetScaleX(float scale_x)
|
void Unit::SetScaleX(float scale_x)
|
||||||
|
|
|
||||||
|
|
@ -74,13 +74,13 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 移动
|
// 移动
|
||||||
void MoveBy(
|
void Move(
|
||||||
float x,
|
float x,
|
||||||
float y
|
float y
|
||||||
);
|
);
|
||||||
|
|
||||||
// 移动
|
// 移动
|
||||||
void MoveBy(
|
void Move(
|
||||||
const Point & vector
|
const Point & vector
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
#include "base/Unit.h"
|
#include "base/Unit.h"
|
||||||
#include "base/Geometry.h"
|
#include "base/Geometry.h"
|
||||||
#include "base/Image.h"
|
#include "base/Image.h"
|
||||||
|
#include "base/Frames.h"
|
||||||
#include "base/Node.h"
|
#include "base/Node.h"
|
||||||
#include "base/Scene.h"
|
#include "base/Scene.h"
|
||||||
#include "base/Sprite.h"
|
#include "base/Sprite.h"
|
||||||
|
|
@ -70,7 +71,7 @@
|
||||||
#include "base/ActionCombined.h"
|
#include "base/ActionCombined.h"
|
||||||
#include "base/ActionTween.h"
|
#include "base/ActionTween.h"
|
||||||
#include "base/Animation.h"
|
#include "base/Animation.h"
|
||||||
#include "base/CallFunc.h"
|
#include "base/Delay.h"
|
||||||
#include "base/Transition.h"
|
#include "base/Transition.h"
|
||||||
#include "base/Debuger.h"
|
#include "base/Debuger.h"
|
||||||
|
|
||||||
|
|
@ -84,7 +85,9 @@
|
||||||
// math
|
// math
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "math/constants.hpp"
|
||||||
#include "math/scalar.hpp"
|
#include "math/scalar.hpp"
|
||||||
|
#include "math/ease.hpp"
|
||||||
#include "math/vector.hpp"
|
#include "math/vector.hpp"
|
||||||
#include "math/rand.h"
|
#include "math/rand.h"
|
||||||
#include "math/Matrix.hpp"
|
#include "math/Matrix.hpp"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright (c) 2016-2018 Easy2D - Nomango
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1900
|
||||||
|
# define E2D_CONSTEXPR constexpr
|
||||||
|
#else
|
||||||
|
# define E2D_CONSTEXPR const
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace easy2d
|
||||||
|
{
|
||||||
|
namespace math
|
||||||
|
{
|
||||||
|
namespace constants
|
||||||
|
{
|
||||||
|
E2D_CONSTEXPR auto PI_F = 3.141592653589793f;
|
||||||
|
E2D_CONSTEXPR auto PI_F_2 = 1.570796326794896f;
|
||||||
|
E2D_CONSTEXPR auto PI_F_X_2 = 6.283185307179586f;
|
||||||
|
|
||||||
|
E2D_CONSTEXPR auto PI_D = 3.14159265358979323846;
|
||||||
|
E2D_CONSTEXPR auto PI_D_2 = 1.57079632679489661923;
|
||||||
|
E2D_CONSTEXPR auto PI_D_X_2 = 6.28318530717958647692;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -64,6 +64,74 @@ namespace easy2d
|
||||||
return 0.5f * (2 - math::Pow(2, -10 * (step * 2 - 1)));
|
return 0.5f * (2 - math::Pow(2, -10 * (step * 2 - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float EaseBounceOut(float step)
|
||||||
|
{
|
||||||
|
if (step < 1 / 2.75f)
|
||||||
|
{
|
||||||
|
return 7.5625f * step * step;
|
||||||
|
}
|
||||||
|
else if (step < 2 / 2.75f)
|
||||||
|
{
|
||||||
|
step -= 1.5f / 2.75f;
|
||||||
|
return 7.5625f * step * step + 0.75f;
|
||||||
|
}
|
||||||
|
else if (step < 2.5f / 2.75f)
|
||||||
|
{
|
||||||
|
step -= 2.25f / 2.75f;
|
||||||
|
return 7.5625f * step * step + 0.9375f;
|
||||||
|
}
|
||||||
|
|
||||||
|
step -= 2.625f / 2.75f;
|
||||||
|
return 7.5625f * step * step + 0.984375f;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float EaseBounceIn(float step)
|
||||||
|
{
|
||||||
|
return 1 - EaseBounceOut(1 - step);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float EaseBounceInOut(float step)
|
||||||
|
{
|
||||||
|
if (step < 0.5f)
|
||||||
|
{
|
||||||
|
return EaseBounceIn(step * 2) * 0.5f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return EaseBounceOut(step * 2 - 1) * 0.5f + 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float EaseElasticIn(float step, float period)
|
||||||
|
{
|
||||||
|
if (step == 0 || step == 1)
|
||||||
|
return step;
|
||||||
|
|
||||||
|
step = step - 1;
|
||||||
|
return -math::Pow(2, 10 * step) * math::Sin((step - period / 4) * 360.f / period);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float EaseElasticOut(float step, float period)
|
||||||
|
{
|
||||||
|
if (step == 0 || step == 1)
|
||||||
|
return step;
|
||||||
|
|
||||||
|
return math::Pow(2, -10 * step) * math::Sin((step - period / 4) * 360.f / period) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float EaseElasticInOut(float step, float period)
|
||||||
|
{
|
||||||
|
if (step == 0 || step == 1)
|
||||||
|
return step;
|
||||||
|
|
||||||
|
step = step * 2 - 1;
|
||||||
|
if (step < 0)
|
||||||
|
{
|
||||||
|
return -0.5f * math::Pow(2, 10 * step) * math::Sin((step - period / 4) * 360.f / period);
|
||||||
|
}
|
||||||
|
return math::Pow(2, -10 * step) * math::Sin((step - period / 4) * 360.f / period) * 0.5f + 1;
|
||||||
|
}
|
||||||
|
|
||||||
inline float EaseSineIn(float step)
|
inline float EaseSineIn(float step)
|
||||||
{
|
{
|
||||||
return 1.f - math::Cos(step * 90);
|
return 1.f - math::Cos(step * 90);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "constants.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#if _MSC_VER >= 1900
|
#if _MSC_VER >= 1900
|
||||||
|
|
@ -32,14 +33,6 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
namespace math
|
namespace math
|
||||||
{
|
{
|
||||||
namespace constants
|
|
||||||
{
|
|
||||||
E2D_CONSTEXPR auto PI_F = 3.141592653589793f;
|
|
||||||
E2D_CONSTEXPR auto PI_F_2 = 1.570796326794896f;
|
|
||||||
E2D_CONSTEXPR auto PI_D = 3.14159265358979323846;
|
|
||||||
E2D_CONSTEXPR auto PI_D_2 = 1.57079632679489661923;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Abs(int val) { return ::abs(val); }
|
inline int Abs(int val) { return ::abs(val); }
|
||||||
|
|
||||||
inline float Abs(float val) { return ::fabsf(val); }
|
inline float Abs(float val) { return ::fabsf(val); }
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
is_selected_ = false;
|
is_selected_ = false;
|
||||||
}
|
}
|
||||||
else if (e.GetType() == MouseEvent::Type::MoveBy && is_selected_ && contains)
|
else if (e.GetType() == MouseEvent::Type::Move && is_selected_ && contains)
|
||||||
{
|
{
|
||||||
SetStatus(Status::Selected);
|
SetStatus(Status::Selected);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@
|
||||||
<ClInclude Include="..\..\core\base\Unit.h" />
|
<ClInclude Include="..\..\core\base\Unit.h" />
|
||||||
<ClInclude Include="..\..\core\base\window.h" />
|
<ClInclude Include="..\..\core\base\window.h" />
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\ease.hpp" />
|
<ClInclude Include="..\..\core\math\ease.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\rand.h" />
|
<ClInclude Include="..\..\core\math\rand.h" />
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,9 @@
|
||||||
<ClInclude Include="..\..\core\base\Frames.h">
|
<ClInclude Include="..\..\core\base\Frames.h">
|
||||||
<Filter>base</Filter>
|
<Filter>base</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="base">
|
<Filter Include="base">
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@
|
||||||
<ClInclude Include="..\..\core\base\Unit.h" />
|
<ClInclude Include="..\..\core\base\Unit.h" />
|
||||||
<ClInclude Include="..\..\core\base\window.h" />
|
<ClInclude Include="..\..\core\base\window.h" />
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\ease.hpp" />
|
<ClInclude Include="..\..\core\math\ease.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\rand.h" />
|
<ClInclude Include="..\..\core\math\rand.h" />
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,9 @@
|
||||||
<ClInclude Include="..\..\core\base\Frames.h">
|
<ClInclude Include="..\..\core\base\Frames.h">
|
||||||
<Filter>base</Filter>
|
<Filter>base</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="base">
|
<Filter Include="base">
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@
|
||||||
<ClInclude Include="..\..\core\base\Unit.h" />
|
<ClInclude Include="..\..\core\base\Unit.h" />
|
||||||
<ClInclude Include="..\..\core\base\window.h" />
|
<ClInclude Include="..\..\core\base\window.h" />
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\ease.hpp" />
|
<ClInclude Include="..\..\core\math\ease.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
<ClInclude Include="..\..\core\math\Matrix.hpp" />
|
||||||
<ClInclude Include="..\..\core\math\rand.h" />
|
<ClInclude Include="..\..\core\math\rand.h" />
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,9 @@
|
||||||
<ClInclude Include="..\..\core\base\Frames.h">
|
<ClInclude Include="..\..\core\base\Frames.h">
|
||||||
<Filter>base</Filter>
|
<Filter>base</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\core\math\constants.hpp">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="base">
|
<Filter Include="base">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue