// Z3DAniHolder.h: interface for the Z3DAniHolder class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_Z3DANIHOLDER_H__9061D061_E701_11D4_AD2B_0000E8EB4C69__INCLUDED_) #define AFX_Z3DANIHOLDER_H__9061D061_E701_11D4_AD2B_0000E8EB4C69__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "misc.h" #include "Z3DAniKeyPack.h" #include "vector.h" #include "quaternion.h" struct Z3DAniHolder { public: Z3DAniHolder() { m_rpPack = NULL; m_fSpeedFactor = 1.0f; m_sTick = 0; m_fCurrentFrame = 0; m_fPrevFrame = -1; // ùÇÁ·¹ÀÓ µ¿ÀÛ¿¡¼­ Â÷ºÐÄ¡ °è»êÀ» À§ÇØ -1ÇÁ·¹ÀÓÀÌ ¼¼ÆÃµÈ°ÍÀÌ ÀÖÀ»¼ö ÀÖÀ¸¹Ç·Î. m_bIsOverflow = true; m_bDirection = true; } ~Z3DAniHolder() {}; bool SetAniPack( Z3DAniKeyPack* pPack ) { if( NULL == pPack ) { MessageBox( NULL, "Z3DAniHolder::SetAniPack() - NULL parameter ¼³Á¤½Ãµµ", 0,0 ); } m_rpPack = pPack; // frame°ü·Ã¼³Á¤ reset //fSpeedFactor = 1.0f; m_sTick = 0; m_fCurrentFrame = 0; if( m_bDirection ) { m_fPrevFrame = -1; // ùÇÁ·¹ÀÓ µ¿ÀÛ¿¡¼­ Â÷ºÐÄ¡ °è»êÀ» À§ÇØ -1ÇÁ·¹ÀÓÀÌ ¼¼ÆÃµÈÀû°ÍÀÌ ÀÖÀ»¼ö ÀÖÀ¸¹Ç·Î. } else { m_fPrevFrame = 1; } m_bIsOverflow = false; return true; } bool GetControllerData( int n, vector3& v, quaternion &q ) { //_ASSERT( m_rpPack ); if( NULL == m_rpPack ) { v.Identity(); q.Identity(); } else { // controller°¹¼öº¸´Ù À妽º°¡ Å©¸é ¿À·ù if( m_rpPack->GetControllerCount() <= n ) { return false; } m_rpPack->GetData(n)->GetInterpolatedKeyframe( m_fCurrentFrame, v, q ); } return true; } bool GetDiffControllerData( int n, vector3& vDiff, quaternion &q ) { if( NULL == m_rpPack ) { vDiff.Identity(); //v.Identity(); q.Identity(); } else { // controller°¹¼öº¸´Ù À妽º°¡ Å©¸é ¿À·ù if( m_rpPack->GetControllerCount() <= n ) { return false; } m_rpPack->GetData(n)->GetDifferentiatedKeyframe( m_fCurrentFrame, m_fPrevFrame, vDiff, q ); } return true; } bool Progress() { if( !m_bIsOverflow ) { m_sTick++; } if( m_rpPack ) { m_fPrevFrame = m_fCurrentFrame; m_fCurrentFrame = m_fSpeedFactor * m_sTick; if( m_fCurrentFrame >= m_rpPack->GetAniLength() ) { m_fCurrentFrame = float(m_rpPack->GetAniLength()-1); m_bIsOverflow = true; return true; } // m_bIsOverflow = false; return true; } return false; } bool BackwardProgress() { m_sTick--; if( m_rpPack ) { m_fPrevFrame = m_fCurrentFrame; m_fCurrentFrame = m_fSpeedFactor * m_sTick; if( m_fCurrentFrame < -1 ) // backward wrap around { m_bIsOverflow = true; m_fPrevFrame = m_fCurrentFrame = -1; m_sTick = (short)((float)m_fCurrentFrame / m_fSpeedFactor); } return true; } return false; } bool IsOverflow() { return m_bIsOverflow; } void Loop() { m_bIsOverflow = false; if( m_rpPack ) { if( m_bDirection ) // forward { m_fCurrentFrame = 0.0f; m_sTick = 0; m_fPrevFrame = -1; } else // backward { m_fPrevFrame = float(m_rpPack->GetAniLength() - 1); m_fCurrentFrame = m_fPrevFrame - 1; m_sTick = (short)((float)m_fCurrentFrame / m_fSpeedFactor); } } } void SetCurrentFrame(float f) { if( f < (float)m_rpPack->GetAniLength() ) { m_fCurrentFrame = f; m_fPrevFrame = f - 1.0f; m_sTick = (short)(f/m_fSpeedFactor); m_bIsOverflow = false; } else { m_fCurrentFrame = m_fPrevFrame = m_rpPack->GetAniLength(); m_sTick = (short)(m_fCurrentFrame/m_fSpeedFactor); m_bIsOverflow = true; } } float GetCurrentFrame() { return m_fCurrentFrame; } float GetPrevFrame() { return m_fPrevFrame; } bool SetSpeedFactor( float f ) { if( f <= 0.0f ) { return false; } m_sTick = short((m_fSpeedFactor/f)*m_sTick); m_fSpeedFactor = f; return true; } const Z3DAniKeyPack* GetAniKeyPackInterface() { return m_rpPack; } protected: Z3DAniKeyPack* m_rpPack; float m_fSpeedFactor; // animation Ãâ·Â¼Óµµ¼³Á¤¿ë short m_sTick; // tick counter float m_fCurrentFrame; // speed factor ¼³Á¤À¸·Î ÀÎÇØ tick°ú frameÀÌ ºÐ¸®µÊ float m_fPrevFrame; // À̵¿½Ã Â÷ºÐ۰ª °è»êÀ» À§ÇÑ previous frame °è»ê¼³Á¤¿ë bool m_bIsOverflow; // µ¿ÀÛÀÌ ³¡³µ´Â°¡?(Ãâ·ÂµÉ frame¹øÈ£°¡ µ¥ÀÌÅÍ ÃÖÈÄframe¹øÈ£ ÀÌÈÄÀΰ¡) bool m_bDirection; // true = forward, false = backward }; #endif // !defined(AFX_Z3DANIHOLDER_H__9061D061_E701_11D4_AD2B_0000E8EB4C69__INCLUDED_)