Added framework for animation

This commit is contained in:
Seth Berrier
2022-03-23 17:02:19 -05:00
parent 2ea1cd5970
commit 7d253d1c38
5 changed files with 106 additions and 2 deletions

46
Sonataria/Animatable.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "Animatable.h"
Animatable::Animatable() {}
Animatable::~Animatable() {}
void Animatable::addMotion(PropertyType prop, Vector3 delta, double rate)
{
AnimationData newMotion = {
MOTION, prop, delta, Vector3(), rate
};
anims.push_back(newMotion);
}
void Animatable::addInterpolation(InterpolationType interpType, PropertyType prop,
Vector3 start, Vector3 end, double durationMsecs)
{
AnimationData newMotion = {
interpType, prop, start, end, durationMsecs
};
anims.push_back(newMotion);
}
void Animatable::update(int64_t currentSongOffset)
{
for (const auto curAnim: anims)
{
switch (curAnim.type)
{
case MOTION: applyMotion(curAnim); break;
case LINEAR: applyLinear(curAnim); break;
default: break;
}
}
}
void Animatable::applyMotion(AnimationData anim)
{
}
void Animatable::applyLinear(AnimationData anim)
{
}

50
Sonataria/Animatable.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
#include <vector>
#include "Transformable.h"
enum InterpolationType
{
MOTION,
LINEAR,
CUBIC,
COSINE,
BOUNCE,
EASE_IN,
EASE_OUT
};
enum PropertyType
{
POSITION,
ROTATION,
SCALE
};
struct AnimationData
{
InterpolationType type;
PropertyType prop;
Vector3 start, end;
double durationRate;
};
class Animatable : public Transformable
{
public:
Animatable();
~Animatable();
void addMotion(PropertyType prop, Vector3 delta, double rate);
void addInterpolation(InterpolationType interpType, PropertyType prop,
Vector3 start, Vector3 end, double durationMsecs);
void update(int64_t currentSongOffset);
private:
std::vector<AnimationData> anims;
void applyMotion(AnimationData anim);
void applyLinear(AnimationData anim);
};

View File

@@ -1,6 +1,6 @@
#pragma once
#include "OpenGLSprite.h"
#include "Transformable.h"
#include "Animatable.h"
// Full vertex data (for easier initialization)
struct QuadVertData {
@@ -8,7 +8,7 @@ struct QuadVertData {
Vector2 tex;
};
class QuadSprite : public OpenGLSprite, public Transformable
class QuadSprite : public OpenGLSprite, public Animatable
{
public:
QuadSprite(const std::wstring& newName);

View File

@@ -203,6 +203,7 @@ copy $(SolutionDir)dependencies\ffmpeg-4.5\bin\swresample-4.dll $(OutputPath)</
<ClCompile Include="ControllerInput.cpp" />
<ClCompile Include="GameRenderer.cpp" />
<ClCompile Include="GameState.cpp" />
<ClCompile Include="Animatable.cpp" />
<ClCompile Include="Key.cpp" />
<ClCompile Include="KeyboardState.cpp" />
<ClCompile Include="Logger.cpp" />
@@ -241,6 +242,7 @@ copy $(SolutionDir)dependencies\ffmpeg-4.5\bin\swresample-4.dll $(OutputPath)</
<ClInclude Include="ControllerInput.h" />
<ClInclude Include="GameRenderer.h" />
<ClInclude Include="GameState.h" />
<ClInclude Include="Animatable.h" />
<ClInclude Include="Key.h" />
<ClInclude Include="KeyboardState.h" />
<ClInclude Include="Logger.h" />

View File

@@ -123,6 +123,9 @@
<ClCompile Include="VideoShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Animatable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameState.h">
@@ -236,6 +239,9 @@
<ClInclude Include="VideoShader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Animatable.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc">