Add support for playing specific animations at a different rate, scaled from the update rate.
This commit is contained in:
@@ -29,6 +29,8 @@ Model::Model ()
|
|||||||
m_bUseZBuffer = true;
|
m_bUseZBuffer = true;
|
||||||
m_pCurAnimation = NULL;
|
m_pCurAnimation = NULL;
|
||||||
m_bRevertToDefaultAnimation = false;
|
m_bRevertToDefaultAnimation = false;
|
||||||
|
m_fDefaultAnimationRate = 1;
|
||||||
|
m_fCurAnimationRate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Model::~Model ()
|
Model::~Model ()
|
||||||
@@ -683,15 +685,16 @@ void Model::DrawPrimitives()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::SetDefaultAnimation( CString sAnimation )
|
void Model::SetDefaultAnimation( CString sAnimation, float fPlayRate )
|
||||||
{
|
{
|
||||||
m_sDefaultAnimation = sAnimation;
|
m_sDefaultAnimation = sAnimation;
|
||||||
|
m_fDefaultAnimationRate = fPlayRate;
|
||||||
m_sMostRecentAnimation = ""; // Clear this out so if we set a different default
|
m_sMostRecentAnimation = ""; // Clear this out so if we set a different default
|
||||||
// while the current default is playing, it will
|
// while the current default is playing, it will
|
||||||
// change to the new one when the current ends.
|
// change to the new one when the current ends.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::PlayAnimation( CString sAniName )
|
void Model::PlayAnimation( CString sAniName, float fPlayRate )
|
||||||
{
|
{
|
||||||
msAnimation *pNewAnimation = NULL;
|
msAnimation *pNewAnimation = NULL;
|
||||||
if( m_mapNameToAnimation.find(sAniName) == m_mapNameToAnimation.end() )
|
if( m_mapNameToAnimation.find(sAniName) == m_mapNameToAnimation.end() )
|
||||||
@@ -700,6 +703,7 @@ void Model::PlayAnimation( CString sAniName )
|
|||||||
pNewAnimation = &m_mapNameToAnimation[sAniName];
|
pNewAnimation = &m_mapNameToAnimation[sAniName];
|
||||||
|
|
||||||
m_fCurrFrame = 0;
|
m_fCurrFrame = 0;
|
||||||
|
m_fCurAnimationRate = fPlayRate;
|
||||||
m_sMostRecentAnimation = sAniName;
|
m_sMostRecentAnimation = sAniName;
|
||||||
|
|
||||||
if ( m_pCurAnimation == pNewAnimation )
|
if ( m_pCurAnimation == pNewAnimation )
|
||||||
@@ -772,12 +776,12 @@ Model::AdvanceFrame (float dt)
|
|||||||
if( m_Meshes.empty() || !m_pCurAnimation )
|
if( m_Meshes.empty() || !m_pCurAnimation )
|
||||||
return; // bail early
|
return; // bail early
|
||||||
|
|
||||||
m_fCurrFrame += FRAMES_PER_SECOND * dt;
|
m_fCurrFrame += FRAMES_PER_SECOND * dt * m_fCurAnimationRate;
|
||||||
if (m_fCurrFrame >= (float)m_pCurAnimation->nTotalFrames)
|
if (m_fCurrFrame >= (float)m_pCurAnimation->nTotalFrames)
|
||||||
{
|
{
|
||||||
if( (m_bRevertToDefaultAnimation) && (m_sDefaultAnimation != "") && (m_sDefaultAnimation != m_sMostRecentAnimation) )
|
if( (m_bRevertToDefaultAnimation) && (m_sDefaultAnimation != "") && (m_sDefaultAnimation != m_sMostRecentAnimation) )
|
||||||
{
|
{
|
||||||
this->PlayAnimation( m_sDefaultAnimation );
|
this->PlayAnimation( m_sDefaultAnimation, m_fDefaultAnimationRate );
|
||||||
m_fCurrFrame = 0.0f;
|
m_fCurrFrame = 0.0f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
bool LoadFromModelFile( CString sFile );
|
bool LoadFromModelFile( CString sFile );
|
||||||
bool LoadMilkshapeAscii( CString sFile );
|
bool LoadMilkshapeAscii( CString sFile );
|
||||||
bool LoadMilkshapeAsciiBones( CString sAniName, CString sFile );
|
bool LoadMilkshapeAsciiBones( CString sAniName, CString sFile );
|
||||||
void PlayAnimation( CString sAniName );
|
void PlayAnimation( CString sAniName, float fPlayRate = 1 );
|
||||||
|
|
||||||
virtual void Update( float fDelta );
|
virtual void Update( float fDelta );
|
||||||
virtual void DrawPrimitives();
|
virtual void DrawPrimitives();
|
||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
void SetFrame( float fNewFrame );
|
void SetFrame( float fNewFrame );
|
||||||
virtual int GetNumStates();
|
virtual int GetNumStates();
|
||||||
CString GetDefaultAnimation() { return m_sDefaultAnimation; };
|
CString GetDefaultAnimation() { return m_sDefaultAnimation; };
|
||||||
void SetDefaultAnimation( CString sAnimation );
|
void SetDefaultAnimation( CString sAnimation, float fPlayRate = 1 );
|
||||||
bool m_bRevertToDefaultAnimation;
|
bool m_bRevertToDefaultAnimation;
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +77,8 @@ private:
|
|||||||
vector<RageModelVertexVector> m_vTempVerticesByBone;
|
vector<RageModelVertexVector> m_vTempVerticesByBone;
|
||||||
float m_fCurrFrame;
|
float m_fCurrFrame;
|
||||||
CString m_sDefaultAnimation;
|
CString m_sDefaultAnimation;
|
||||||
|
float m_fDefaultAnimationRate;
|
||||||
|
float m_fCurAnimationRate;
|
||||||
CString m_sMostRecentAnimation;
|
CString m_sMostRecentAnimation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user