#include "stdafx.h" #include "SGameForceSphereFX.h" #include "KViewport.h" #include "KSeqModel.h" #include "SGameObject.h" #include "GameDefine.h" #include "SDebug_Util.h" extern const char * pEffectAniKey[]; float SGameForceSphereFX::floatLinear( float v0, float v1, float t ) { return v0 + ( t * ( v1 - v0 ) ); } SGameForceSphereFX::SGameForceSphereFX() { m_dwVisibleTime = 1000; m_fRotation = 0.0f; m_bIsEnd = true; m_fSphereDistance = 10.0f; m_fSphereHeight = 10.0f; m_fRotationSpeed = 0.1256f; m_dwArrayTime = 1000; m_dwOldTime = 0; m_nAddOnType = SGAME_FORCE_SPHERE_FX; } SGameForceSphereFX::~SGameForceSphereFX() { std::vector< S_FORCE_SPHERE >::iterator iter = m_sForceSphere.begin(); for( ; iter < m_sForceSphere.end(); ) { SAFE_DELETE( (*iter).m_pForceSphere ); iter = m_sForceSphere.erase( iter ); } } void SGameForceSphereFX::SetSphereDistance( float fDistance ) { m_fSphereDistance = fDistance; } void SGameForceSphereFX::SetSphereHeight( float fHeight ) { m_fSphereHeight = fHeight; } //기공 하나 추가~ void SGameForceSphereFX::AddForceSphere() { if( m_sForceSphere.size() >= 10 ) return; NX3LoadPack loadpack; loadpack.Init(); KSeqModel* pSeqModel = new KSeqModel; pSeqModel->AddAnimation( pEffectAniKey[0], "rcfx_forcesphere_start.nx3" , KNX3Manager::SEQTYPE_ALL, &loadpack); pSeqModel->AddAnimation( pEffectAniKey[1], "rcfx_forcesphere_loop.nx3" , KNX3Manager::SEQTYPE_ALL, &loadpack); pSeqModel->AddAnimation( pEffectAniKey[2], "rcfx_forcesphere_use.nx3" , KNX3Manager::SEQTYPE_ALL, &loadpack); pSeqModel->PlayAnimation( m_dwTime, pEffectAniKey[0] ); S_FORCE_SPHERE data; data.m_pForceSphere = pSeqModel; m_sForceSphere.push_back( data ); ArrayForceSphere(); m_bIsEnd = false; } //기공 위치 정렬 void SGameForceSphereFX::ArrayForceSphere() { int nSize = (int)m_sForceSphere.size(); int nEnd = nSize - 1; for( int x = 0; x < nSize; x++ ) { S_FORCE_SPHERE* pData = &m_sForceSphere[x]; if( x == nEnd ) { pData->m_vPosition = K3DVector( m_fSphereDistance, 0.f, m_fSphereHeight ); } else { pData->m_vPosition = K3DVector( m_fSphereDistance, 0.f, m_fSphereHeight ); pData->m_bUseRot = true; pData->m_fBeZ = pData->m_fCurZ; pData->m_fAfZ = (nEnd-x) * ( (D3DX_PI * 2.f) / nSize); pData->m_dwOldArrayTime = m_dwTime; } } } //기공 하나 사용 void SGameForceSphereFX::UseForceSphere() { std::vector< S_FORCE_SPHERE >::iterator iter = m_sForceSphere.begin(); for( ; iter < m_sForceSphere.end(); ) //첫번째꺼 { if( (*iter).m_nStep == STEP_03 ) { ++iter; } else { (*iter).m_nStep = STEP_03; (*iter).m_pForceSphere->PlayAnimation( m_dwTime, pEffectAniKey[2] ); break; } } } int SGameForceSphereFX::GetForceSphereSize() { int nForceSphere = 0; std::vector< S_FORCE_SPHERE >::iterator iter = m_sForceSphere.begin(); for( ; iter != m_sForceSphere.end(); ++iter ) { if( (*iter).m_nStep != STEP_03 ) ++nForceSphere; } return nForceSphere; } void SGameForceSphereFX::UseRotation( S_FORCE_SPHERE* pForceSphere ) { K3DMatrix matZ; if( (m_dwTime - pForceSphere->m_dwOldArrayTime) < m_dwArrayTime ) { float fSpeed = (float)( m_dwTime - pForceSphere->m_dwOldArrayTime ) / (float)m_dwArrayTime; pForceSphere->m_fCurZ = floatLinear( pForceSphere->m_fBeZ, pForceSphere->m_fAfZ, fSpeed ); K3DMatrixRotationZ( matZ, pForceSphere->m_fCurZ ); } else { pForceSphere->m_bUseRot = false; K3DMatrixRotationZ( matZ, pForceSphere->m_fAfZ ); } K3DVectorTransform( pForceSphere->m_vPosition, K3DVector( m_fSphereDistance, 0.f, m_fSphereHeight ), matZ ); } void SGameForceSphereFX::Process( DWORD dwTime ) { m_dwTime = dwTime; if( m_bIsEnd ) return; K3DVector vPos = *m_pGameObj->GetPosition(); K3DMatrix mat, matParent, matTrans, matRot; K3DMatrixIdentity( matParent ); matParent._41 = vPos.x; matParent._42 = vPos.y; matParent._43 = vPos.z; if( m_hCreaturehandle != 0 ) { bool bCreature = false; SGameObject* pCreature = m_pGameObj->GetGameObject( m_hCreaturehandle ); if( pCreature ) { bCreature = true; } else { pCreature = m_pGameObj->GetGameTransportCreatureObject( m_hCreaturehandle ); if( pCreature ) bCreature = true; } if( bCreature ) { vPos = *pCreature->GetPosition(); matParent._41 = vPos.x; matParent._42 = vPos.y; WORD wTile=0; m_pGameObj->GetHeight( vPos.x, vPos.y, matParent._43,wTile ); } m_hCreaturehandle = 0; } if( (dwTime - m_dwOldTime) < 2000 ) { float fGap = (float)(dwTime - m_dwOldTime) / 2000; m_fRotation = 6.28f * fGap; } else { m_dwOldTime = dwTime; m_fRotation = 0.f; } K3DMatrixRotationZ( matRot, m_fRotation ); std::vector< S_FORCE_SPHERE >::iterator iter = m_sForceSphere.begin(); for( ; iter != m_sForceSphere.end(); ) { DWORD dwTimeLeft = (*iter).m_dwTimeLeft; if( (*iter).m_nStep == STEP_00 ) { //기공 생성되는 애니메이션 if( !(*iter).m_pForceSphere->IsPlaying() ) { (*iter).m_nStep = STEP_01; (*iter).m_dwTimeLeft = dwTime; (*iter).m_pForceSphere->PlayAnimation( dwTime, pEffectAniKey[1], KSeqForm::SEQTYPE_LOOP ); } } else if( (*iter).m_nStep == STEP_01 ) { //NONE } else if( (*iter).m_nStep == STEP_02 ) { //일정 시간안에 사라지게 한다 if( ( dwTime - dwTimeLeft ) < m_dwVisibleTime ) { float fAlpha = 1.0f - (float)( dwTime - dwTimeLeft ) / (float)m_dwVisibleTime; (*iter).m_pForceSphere->SetVisibility( fAlpha ); } else { SAFE_DELETE( (*iter).m_pForceSphere ); iter = m_sForceSphere.erase( iter ); if( m_sForceSphere.empty() ) { m_bIsEnd = true; m_fRotation = 0.f; break; } else { ArrayForceSphere(); continue; } } } else if( (*iter).m_nStep == STEP_03 ) { //기공 사용 애니메이션 if( !(*iter).m_pForceSphere->IsPlaying() ) { SAFE_DELETE( (*iter).m_pForceSphere ); iter = m_sForceSphere.erase( iter ); if( m_sForceSphere.empty() ) { m_bIsEnd = true; m_fRotation = 0.f; break; } else { ArrayForceSphere(); continue; } } } if( (*iter).m_bUseRot ) UseRotation( &(*iter) ); K3DMatrixIdentity( mat ); K3DMatrixTranslation( matTrans, (*iter).m_vPosition.x, (*iter).m_vPosition.y, (*iter).m_vPosition.z ); K3DMatrixMultiply( mat, matTrans, matRot ); K3DMatrixMultiply( mat, mat, matParent ); //K3DMatrixMultiply( mat, matTrans, &matParent ); (*iter).m_pForceSphere->SetTransform( mat ); (*iter).m_pForceSphere->Process( dwTime ); ++iter; } } void SGameForceSphereFX::Render( class KViewportObject** ppViewportList, int nViewportCount ) { if( m_bIsEnd ) return; for(int vit = 0; vit < nViewportCount; ++vit) { std::vector< S_FORCE_SPHERE >::iterator iter = m_sForceSphere.begin(); if( ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_GAME || ppViewportList[vit]->GetAttributes() & KViewportObject::VIEWPORT_WATER ) { while( iter != m_sForceSphere.end() ) { (*iter).m_pForceSphere->Render( ppViewportList[vit] ); ++iter; } } } }