animation component should theoretically work

This commit is contained in:
Clément Le Bihan
2021-06-02 15:08:46 +02:00
parent b4d783d6c2
commit d986a24c47
4 changed files with 44 additions and 20 deletions
+1 -1
View File
@@ -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()
@@ -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<int>(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<int>(this->_modelAnimation.getAnimationsCount());
}
void AnimationsComponent::incCurrentAnimFrameCounter()
{
this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter();
}
}
@@ -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
@@ -22,6 +22,6 @@ namespace BBM
auto &anim = entity.getComponent<AnimationsComponent>();
model.member.setAnimation(anim.getCurrentModelAnim());
anim.setAnimFrameCounter(anim.getAnimFrameCounter() + 1);
anim.setCurrentAnimFrameCounter(anim.getCurrentAnimFrameCounter() + 1);
}
}