From d986a24c47025bc4de9127aadd9ebe15c74fe920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 2 Jun 2021 15:08:46 +0200 Subject: [PATCH] animation component should theoretically work --- lib/Ray/sources/Model/ModelAnimations.cpp | 2 +- .../Animation/AnimationsComponent.cpp | 37 +++++++++++++------ .../Animation/AnimationsComponent.hpp | 23 ++++++++---- sources/System/Animation/AnimationsSystem.cpp | 2 +- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/Ray/sources/Model/ModelAnimations.cpp b/lib/Ray/sources/Model/ModelAnimations.cpp index 224b9979..2b7328f4 100644 --- a/lib/Ray/sources/Model/ModelAnimations.cpp +++ b/lib/Ray/sources/Model/ModelAnimations.cpp @@ -13,7 +13,7 @@ RAY::ModelAnimations::ModelAnimations(const std::string &filePath): ::ModelAnimation *ptr = this->_animationsPtr.get(); for (int i = 0; i < this->_animationCount; i++) - this->_animations.push_back(RAY::ModelAnimation(ptr[i])); + this->_animations.emplace_back(RAY::ModelAnimation(ptr[i])); } RAY::ModelAnimations::~ModelAnimations() diff --git a/sources/Component/Animation/AnimationsComponent.cpp b/sources/Component/Animation/AnimationsComponent.cpp index d32c6818..ce29964d 100644 --- a/sources/Component/Animation/AnimationsComponent.cpp +++ b/sources/Component/Animation/AnimationsComponent.cpp @@ -8,36 +8,51 @@ namespace BBM { - AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation) + AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation, int animIndex) : WAL::Component(entity), _modelAnimation(modelAnimation), - _animFrameCounter(0) + _currentAnimIndex(animIndex) { + this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0); } WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const { - return new AnimationsComponent(entity, this->_modelAnimation); + return new AnimationsComponent(entity, this->_modelAnimation, this->_currentAnimIndex); } - size_t AnimationsComponent::getAnimFrameCounter() const + size_t AnimationsComponent::getCurrentAnimFrameCounter() const { - return this->_animFrameCounter; + return this->_modelAnimation[this->_currentAnimIndex].getFrameCounter(); } RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim() const { - return this->_modelAnimation[static_cast(this->_animFrameCounter)]; + return this->_modelAnimation[this->_currentAnimIndex]; } - void AnimationsComponent::setAnimFrameCounter(size_t animFrameCounter) + void AnimationsComponent::setCurrentAnimFrameCounter(size_t animFrameCounter) { - this->_animFrameCounter = animFrameCounter; - this->_animFrameCounter %= this->_modelAnimation.getAnimationsCount(); + this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(animFrameCounter); } - void AnimationsComponent::resetAnimFrameCounter() + void AnimationsComponent::resetCurrentAnimFrameCounter() { - this->_animFrameCounter = 0; + this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0); + } + + size_t AnimationsComponent::getCurrentAnimIndex() const + { + return this->_currentAnimIndex; + } + + void AnimationsComponent::setAnimIndex(int animIndex) + { + this->_currentAnimIndex = animIndex % static_cast(this->_modelAnimation.getAnimationsCount()); + } + + void AnimationsComponent::incCurrentAnimFrameCounter() + { + this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter(); } } \ No newline at end of file diff --git a/sources/Component/Animation/AnimationsComponent.hpp b/sources/Component/Animation/AnimationsComponent.hpp index a3d741a9..239c9470 100644 --- a/sources/Component/Animation/AnimationsComponent.hpp +++ b/sources/Component/Animation/AnimationsComponent.hpp @@ -16,26 +16,35 @@ namespace BBM private: //! @brief To get the animation data RAY::ModelAnimations &_modelAnimation; - //! @brief the frame animation counter - size_t _animFrameCounter; + //! @brief The index of the + int _currentAnimIndex; public: //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; + //! @brief get the current animation index + size_t getCurrentAnimIndex() const; + + //! @brief Set the animation index to use + void setAnimIndex(int animIndex); + //! @brief get animation frame counter - size_t getAnimFrameCounter() const; + size_t getCurrentAnimFrameCounter() const; //! @brief get the current RAY::ModelAnimation getCurrentModelAnim() const; - //! @brief - void setAnimFrameCounter(size_t animFrameCounter); + //! @brief set the anim frame counter + void setCurrentAnimFrameCounter(size_t animFrameCounter); //! @brief Set the internal anim counter to 0 - void resetAnimFrameCounter(); + void resetCurrentAnimFrameCounter(); + + //! @brief Increment the internal anim counter + void incCurrentAnimFrameCounter(); //! @brief ctor entity and the path of the animation file - explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation); + explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations &modelAnimation, int animIndex); //! @brief copy ctor AnimationsComponent(const AnimationsComponent &) = default; //! @brief dtor diff --git a/sources/System/Animation/AnimationsSystem.cpp b/sources/System/Animation/AnimationsSystem.cpp index 42425acf..f9f7c9ef 100644 --- a/sources/System/Animation/AnimationsSystem.cpp +++ b/sources/System/Animation/AnimationsSystem.cpp @@ -22,6 +22,6 @@ namespace BBM auto &anim = entity.getComponent(); model.member.setAnimation(anim.getCurrentModelAnim()); - anim.setAnimFrameCounter(anim.getAnimFrameCounter() + 1); + anim.setCurrentAnimFrameCounter(anim.getCurrentAnimFrameCounter() + 1); } } \ No newline at end of file