From 7d253d1c389be7cc583cebe9996e13b23eefdaa2 Mon Sep 17 00:00:00 2001 From: Seth Berrier Date: Wed, 23 Mar 2022 17:02:19 -0500 Subject: [PATCH] Added framework for animation --- Sonataria/Animatable.cpp | 46 ++++++++++++++++++++++++++ Sonataria/Animatable.h | 50 +++++++++++++++++++++++++++++ Sonataria/QuadSprite.h | 4 +-- Sonataria/Sonataria.vcxproj | 2 ++ Sonataria/Sonataria.vcxproj.filters | 6 ++++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 Sonataria/Animatable.cpp create mode 100644 Sonataria/Animatable.h diff --git a/Sonataria/Animatable.cpp b/Sonataria/Animatable.cpp new file mode 100644 index 0000000..fadb2f0 --- /dev/null +++ b/Sonataria/Animatable.cpp @@ -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) +{ + +} diff --git a/Sonataria/Animatable.h b/Sonataria/Animatable.h new file mode 100644 index 0000000..8bbba9f --- /dev/null +++ b/Sonataria/Animatable.h @@ -0,0 +1,50 @@ +#pragma once + +#include + +#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 anims; + + void applyMotion(AnimationData anim); + void applyLinear(AnimationData anim); +}; diff --git a/Sonataria/QuadSprite.h b/Sonataria/QuadSprite.h index 70e5ba7..cfbaf18 100644 --- a/Sonataria/QuadSprite.h +++ b/Sonataria/QuadSprite.h @@ -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); diff --git a/Sonataria/Sonataria.vcxproj b/Sonataria/Sonataria.vcxproj index 3cf9a52..2237c47 100644 --- a/Sonataria/Sonataria.vcxproj +++ b/Sonataria/Sonataria.vcxproj @@ -203,6 +203,7 @@ copy $(SolutionDir)dependencies\ffmpeg-4.5\bin\swresample-4.dll $(OutputPath) + @@ -241,6 +242,7 @@ copy $(SolutionDir)dependencies\ffmpeg-4.5\bin\swresample-4.dll $(OutputPath) + diff --git a/Sonataria/Sonataria.vcxproj.filters b/Sonataria/Sonataria.vcxproj.filters index ed8e4e0..00ce729 100644 --- a/Sonataria/Sonataria.vcxproj.filters +++ b/Sonataria/Sonataria.vcxproj.filters @@ -123,6 +123,9 @@ Source Files + + Source Files + @@ -236,6 +239,9 @@ Header Files + + Header Files +