#include "stdafx.h" #include "SGameAvatarFx.h" #include "KViewport.h" #include "SGameAvatarEx.h" #include "SModelEffectResourceDB.h" #include "SSoundResourceDB.h" #include "SDebug_Util.h" SGameAvatarFx::SGameAvatarFx() { m_nAddOnType = SGAME_AVATAR_FX; m_pParentMatrix = NULL; m_pEvpMatrix = NULL; m_pEvpAttachMatrix = NULL; } SGameAvatarFx::~SGameAvatarFx() { } void SGameAvatarFx::Initialize() { NX3LoadPack loadpack; loadpack.Init(); m_pSeqModel = new KSeqModel; m_pSeqModel->AddAnimation( "effect_middle", GetResourceDB().GetEffectResourceName( m_pModelEffectRes->effect_file_ID ), KNX3Manager::SEQTYPE_ALL, &loadpack); m_pSeqModel->PlayAnimation( 0, "effect_middle", SEQTYPE_LOOP ); m_pParentMatrix = m_pGameObj->GetTransform(); m_pEvpMatrix = m_pGameObj->GetEventPointMatrix( m_pModelEffectRes->effect_position ); m_pEvpAttachMatrix = m_pGameObj->GetEventPointAttachMatrix( m_pModelEffectRes->effect_position ); } void SGameAvatarFx::SetModelEffectRes( ModelEffectResourceGame* pModelEffectRes ) { m_pModelEffectRes = pModelEffectRes; } void SGameAvatarFx::Process( DWORD dwTime ) { m_pSeqModel->Process( dwTime ); m_pSeqModel->SetVisibility( m_pGameObj->GetVisibility() ); } void SGameAvatarFx::Render( class KViewportObject** ppViewportList, int nViewportCount ) { K3DMatrix matResult, matTemp; float fScale = m_pGameObj->GetScale(); K3DMatrixScaling( matResult, fScale, fScale, fScale ); if( m_pEvpMatrix == NULL ) { if( m_pEvpAttachMatrix && m_pParentMatrix ) { K3DMatrixMultiply( matTemp, *m_pEvpAttachMatrix, *m_pParentMatrix ); K3DMatrixMultiply( matResult, matResult, matTemp ); } else if( m_pParentMatrix ) { K3DMatrixMultiply( matResult, matResult, *m_pParentMatrix ); } else assert( false && "SGameAvatarFx::Render" ); } else { if( m_pEvpAttachMatrix && m_pParentMatrix ) { K3DMatrixMultiply( matTemp, *m_pEvpAttachMatrix, *m_pParentMatrix ); K3DMatrixMultiply( matResult, matResult, matTemp ); } else if( m_pParentMatrix ) { matResult._41 = m_pParentMatrix->_41; matResult._42 = m_pParentMatrix->_42; matResult._43 = m_pParentMatrix->_43; } else assert( false && "SGameAvatarFx::Render" ); } m_pSeqModel->SetTransform( matResult ); for(int vit = 0; vit < nViewportCount; ++vit) { if( ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_GAME || ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_WATER ) { m_pSeqModel->Render( ppViewportList[vit] ); } } } /////////////////////////////////////////////////////////////////////////////// //////Motion FX SGameAvatarMotionFx::SGameAvatarMotionFx() { m_nAddOnType = SGAME_AVATAR_MOTION_FX; m_pParentMatrix = NULL; m_pEvpMatrix = NULL; m_pEvpAttachMatrix = NULL; m_nAnimationID = -1; m_nTmpAnimationID = -1; } SGameAvatarMotionFx::~SGameAvatarMotionFx() { } void SGameAvatarMotionFx::Initialize() { NX3LoadPack loadpack; loadpack.Init(); m_pSeqModel = new KSeqModel; m_pSeqModel->AddAnimation( "effect_middle", m_strFxFileName.c_str(), KNX3Manager::SEQTYPE_ALL, &loadpack); m_pSeqModel->PlayAnimation( 0, "effect_middle", SEQTYPE_LOOP ); m_pParentMatrix = m_pGameObj->GetTransform(); m_pEvpMatrix = m_pGameObj->GetEventPointMatrix( m_nFxPos ); m_pEvpAttachMatrix = m_pGameObj->GetEventPointAttachMatrix( m_nFxPos ); } void SGameAvatarMotionFx::SetMotioinFxInfo( DWORD dwTime, const char* szFileName, int nFxPos, int nAniID ) { m_strFxFileName = szFileName; m_dwTime = dwTime; m_nFxPos = nFxPos; m_nAnimationID = nAniID; } void SGameAvatarMotionFx::SetRenderFlag( bool bRenderFlag ) { m_bRenderFlag = bRenderFlag; } void SGameAvatarMotionFx::ChangeNewMotionFx() { if( m_nAnimationID == m_nTmpAnimationID ) return; m_nTmpAnimationID = m_nAnimationID; SAFE_DELETE( m_pSeqModel ); NX3LoadPack loadpack; loadpack.Init(); m_pSeqModel = new KSeqModel; m_pSeqModel->AddAnimation( "effect_middle", m_strFxFileName.c_str(), KNX3Manager::SEQTYPE_ALL, &loadpack); m_pSeqModel->PlayAnimation( m_dwTime, "effect_middle", SEQTYPE_LOOP ); } void SGameAvatarMotionFx::Process( DWORD dwTime ) { m_pSeqModel->Process( dwTime ); m_pSeqModel->SetVisibility( m_pGameObj->GetVisibility() ); } void SGameAvatarMotionFx::Render( class KViewportObject** ppViewportList, int nViewportCount ) { if( !m_bRenderFlag ) return; K3DMatrix matResult, matTemp; float fScale = m_pGameObj->GetScale(); K3DMatrixScaling( matResult, fScale, fScale, fScale ); if( m_pEvpMatrix == NULL ) { if( m_pEvpAttachMatrix && m_pParentMatrix ) { K3DMatrixMultiply( matTemp, *m_pEvpAttachMatrix, *m_pParentMatrix ); K3DMatrixMultiply( matResult, matResult, matTemp ); } else if( m_pParentMatrix ) { K3DMatrixMultiply( matResult, matResult, *m_pParentMatrix ); } else assert( false && "SGameAvatarFx::Render" ); } else { if( m_pEvpAttachMatrix && m_pParentMatrix ) { K3DMatrixMultiply( matTemp, *m_pEvpAttachMatrix, *m_pParentMatrix ); K3DMatrixMultiply( matResult, matResult, matTemp ); } else if( m_pParentMatrix ) { matResult._41 = m_pParentMatrix->_41; matResult._42 = m_pParentMatrix->_42; matResult._43 = m_pParentMatrix->_43; } else assert( false && "SGameAvatarFx::Render" ); } m_pSeqModel->SetTransform( matResult ); for(int vit = 0; vit < nViewportCount; ++vit) { if( ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_GAME || ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_WATER ) { m_pSeqModel->Render( ppViewportList[vit] ); } } }