Fixed MD2 animation

Former-commit-id: 3ba7d63f9518c64677e575e13d8a42b459c5151f
This commit is contained in:
Lynix 2012-12-29 01:37:44 +01:00
parent 15888b0f42
commit 11fccc4c4b
4 changed files with 43 additions and 2 deletions

View File

@ -44,6 +44,8 @@ class NAZARA_API NzAnimation : public NzResource
bool CreateSkeletal(unsigned int frameCount, unsigned int jointCount);
void Destroy();
void EnableLoopPointInterpolation(bool loopPointInterpolation);
unsigned int GetFrameCount() const;
unsigned int GetJointCount() const;
NzSequence* GetSequence(const NzString& sequenceName);
@ -59,6 +61,7 @@ class NAZARA_API NzAnimation : public NzResource
bool HasSequence(const NzString& sequenceName) const;
bool HasSequence(unsigned int index = 0) const;
bool IsLoopPointInterpolationEnabled() const;
bool IsValid() const;
bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams());

View File

@ -424,8 +424,16 @@ void NzModel::Update(float elapsedTime)
unsigned lastFrame = m_currentSequence->firstFrame + m_currentSequence->frameCount - 1;
if (m_nextFrame+1 > lastFrame)
{
m_currentFrame = m_currentSequence->firstFrame;
m_nextFrame = m_currentFrame+1;
if (m_animation->IsLoopPointInterpolationEnabled())
{
m_currentFrame = m_nextFrame;
m_nextFrame = m_currentSequence->firstFrame;
}
else
{
m_currentFrame = m_currentSequence->firstFrame;
m_nextFrame = m_currentFrame+1;
}
}
else
{

View File

@ -16,6 +16,7 @@ struct NzAnimationImpl
std::vector<NzSequence> sequences;
std::vector<NzSequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
nzAnimationType type;
bool loopPointInterpolation = false;
unsigned int frameCount;
unsigned int jointCount; // Uniquement pour les animations squelettiques
};
@ -206,6 +207,19 @@ void NzAnimation::Destroy()
}
}
void NzAnimation::EnableLoopPointInterpolation(bool loopPointInterpolation)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
#endif
m_impl->loopPointInterpolation = loopPointInterpolation;
}
unsigned int NzAnimation::GetFrameCount() const
{
#if NAZARA_UTILITY_SAFE
@ -435,6 +449,19 @@ bool NzAnimation::HasSequence(unsigned int index) const
return index >= m_impl->sequences.size();
}
bool NzAnimation::IsLoopPointInterpolationEnabled() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->loopPointInterpolation;
}
bool NzAnimation::IsValid() const
{
return m_impl != nullptr;

View File

@ -266,6 +266,9 @@ namespace
return false;
}
// Le MD2 requiert une interpolation de la dernière à la première frame (en cas de loop)
animation->EnableLoopPointInterpolation(true);
// Décodage des séquences
///TODO: Optimiser le calcul
char last[16];