Texture* TextureFilters::glow(Texture* texture, D3DXCOLOR color, int centerX, int centerY, int radiusX_, int radiusY_, int gamma_, int alpha_, bool inPlace) { Texture* newTexture = new Texture(); if (texture != 0) texture->copy(newTexture); else newTexture->fillRectangle(0, 0, 256, 256, 0xff000000); float radiusX = 1.0f / radiusX_; float radiusY = 1.0f / radiusY_; float gamma = 1.0f - gamma_ / 256.0f; float alpha = 1.0f - alpha_ / 256.0f; newTexture->lock(); for (int y = 0; y < 256; y++) { float dy = (float)(y - centerY) * radiusY; float dy_2 = dy*dy; for (int x = 0; x < 256; x++) { float dx = (float)(x-centerX) * radiusX; float d = sqrtf(dx*dx + dy_2); if (d > 1.0f) d = 1.0f; d = 1.0f - d; float a = -1.0f;; if (d != 0.0f) { d = powf(d, gamma); a = d - alpha; } if (a < 0.0f) continue; D3DXCOLOR resultColor; D3DXCOLOR inputColor = newTexture->getPixel(x, y); D3DXColorLerp(&resultColor, &inputColor, &color, a); newTexture->putPixel(x, y, resultColor); } } newTexture->unlock(); return newTexture; }
void CFLASH::RenderFlash( C2DRender* p2DRender ) { _PROFILE("CFLASH::RenderFlash()"); if( m_bAction ) { // 흰색으로 만든다. if( m_bFade == FALSE ) { m_nAlphaCount+=m_nAlphaAcc; m_nAlphaAcc+=20; } // 페이드 아웃함( 정지시간, 지속시간 ) else { // 처음에 한번만 정지 유지시간 입력 if( !m_bStopTime ) { m_dwStopTime = timeGetTime()+m_dwStopTime; m_bStopTime = TRUE; } if( timeGetTime() > m_dwStopTime ) { //처음에 한번만 지속유지시간 입력 DWORD dwSaveTime = timeGetTime(); BOOL bBackup = m_bRunTime; if( !m_bRunTime ) { m_dwEndTime = dwSaveTime+m_dwTime; m_bRunTime = TRUE; } FLOAT fLerp = (FLOAT)(m_dwEndTime - dwSaveTime) / (FLOAT)m_dwTime; D3DXCOLOR dwColor; D3DXCOLOR dwStartColor = D3DCOLOR_RGBA( 255, 255, 255, 0 ); D3DXCOLOR dwEndColor = D3DCOLOR_RGBA( 255, 255, 255, 255 ); // 지나온시간과 완료시간사이의 보간 D3DXColorLerp( &dwColor, &dwStartColor, &dwEndColor, fLerp ); m_nAlphaCount = (int)( dwColor.a * 255 ); if( m_nAlphaCount <= 0 || m_dwEndTime < dwSaveTime ) Init(); } else { } } // 가장 밝은 색이 되면 페이드 아웃을 실시함 if( m_nAlphaCount > MAX_ALPHA ) { m_bFade = TRUE; m_nAlphaCount = MAX_ALPHA; } p2DRender->RenderFillRect( CRect( 0, 0, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT-48 ), D3DCOLOR_ARGB( m_nAlphaCount, 255, 255, 255 ) ); } }
HRESULT CTailEffectBelt::Render( LPDIRECT3DDEVICE9 pd3dDevice ) { if( m_bActive == FALSE ) return E_FAIL; if( m_pTexture == NULL ) return E_FAIL; if( m_nMaxTail < 2 ) return E_FAIL; // 꼬리는 최소 2개노드(버텍스4개)가 있어야 삼각형스트립 2개를 만들어 낼수 있다. D3DXMATRIX mWorld; D3DXMatrixIdentity( &mWorld ); pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld ); // Set World Transform pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); // pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); // pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff ); pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE ); pd3dDevice->SetTexture(0, m_pTexture ); pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(TAILVERTEX) ); pd3dDevice->SetVertexShader( NULL ); pd3dDevice->SetVertexDeclaration( NULL ); pd3dDevice->SetFVF( TAILVERTEX::FVF ); HRESULT hr; TAIL* pTail = m_pTails; TAILVERTEX* pVertices; DWORD dwNumTailsToRender = 0; m_dwBase += m_dwFlush; if(m_dwBase >= m_dwDiscard) m_dwBase = 0; if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(TAILVERTEX), m_dwFlush * sizeof(TAILVERTEX), (void**) &pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) ) { return hr; } D3DXCOLOR clrDiffuse; D3DXVECTOR3 vPos1, vPos2; int nCount = 0; float fTy; float fFade; while( pTail ) { vPos1 = pTail->m_vPos1; // 꼬리좌표 1 vPos2 = pTail->m_vPos2; // 꼬리좌표 2 if( pTail->m_fFade > 1.0f ) fFade = 2.0f - pTail->m_fFade; else fFade = pTail->m_fFade; D3DXColorLerp( &clrDiffuse, &pTail->m_clrFade, &pTail->m_clrDiffuse, fFade ); DWORD dwDiffuse = (DWORD) clrDiffuse; if( nCount & 1 ) fTy = 1.0f; else fTy = 0.0f; // 버텍스 버퍼로 옮김. pVertices->v = vPos1; pVertices->color = dwDiffuse; pVertices->tx = 0.0f; pVertices->ty = fTy; pVertices++; pVertices->v = vPos2; pVertices->color = dwDiffuse; pVertices->tx = 1.0f; pVertices->ty = fTy; pVertices++; if( ++dwNumTailsToRender == m_dwFlush ) { m_pVB->Unlock(); if(FAILED(hr = pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, m_dwBase, (dwNumTailsToRender * 2) - 2 ))) return hr; m_dwBase += m_dwFlush; if(m_dwBase >= m_dwDiscard) m_dwBase = 0; if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(TAILVERTEX), m_dwFlush * sizeof(TAILVERTEX), (void**) &pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) ) { return hr; } dwNumTailsToRender = 0; } pTail = pTail->m_pNext; nCount ++; } m_pVB->Unlock(); #ifdef _DEBUG if( dwNumTailsToRender == 1 ) Error( "TailRender : 렌더할 꼬리개수가 넘 작은경우 발생. %d", dwNumTailsToRender ); #endif // Render any remaining particles if( dwNumTailsToRender ) // 위에서 512개씩 출력해주고 남은 버텍스들을 여기서 마저 다 그려줌. { if(FAILED(hr = pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, m_dwBase, (dwNumTailsToRender * 2) - 2 ))) // 트라이앵글 스트립은 프리미티브 개수가 버텍스개수 - 2이다. return hr; } pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); pd3dDevice->SetTexture(0, NULL ); return S_OK; }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Renders the particle system using either pointsprites (if supported) // or using 4 vertices per particle //----------------------------------------------------------------------------- HRESULT CParticles::Render( LPDIRECT3DDEVICE9 pd3dDevice ) { if( m_bActive == FALSE ) return S_OK; if( m_pParticleTexture == NULL ) return S_OK; if( m_dwParticles <= 0 ) return S_OK; D3DXMATRIX mWorld; D3DXMatrixIdentity( &mWorld ); pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld ); // Set World Transform // Draw particles pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff ); // pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT ); // pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE ); pd3dDevice->SetTexture(0, m_pParticleTexture ); HRESULT hr; // Set the render states for using point sprites pd3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(m_fSize) ); pd3dDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(1.00f) ); pd3dDevice->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.00f) ); pd3dDevice->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.00f) ); pd3dDevice->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(1.00f) ); // Set up the vertex buffer to be rendered pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(POINTVERTEX) ); pd3dDevice->SetVertexShader( NULL ); pd3dDevice->SetVertexDeclaration( NULL ); pd3dDevice->SetFVF( POINTVERTEX::FVF ); PARTICLE* pParticle = m_pParticles; POINTVERTEX* pVertices; DWORD dwNumParticlesToRender = 0; // Lock the vertex buffer. We fill the vertex buffer in small // chunks, using D3DLOCK_NOOVERWRITE. When we are done filling // each chunk, we call DrawPrim, and lock the next chunk. When // we run out of space in the vertex buffer, we start over at // the beginning, using D3DLOCK_DISCARD. m_dwBase += m_dwFlush; if(m_dwBase >= m_dwDiscard) m_dwBase = 0; if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(POINTVERTEX), m_dwFlush * sizeof(POINTVERTEX), (void**) &pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) ) { return hr; } D3DXCOLOR clrDiffuse; D3DXVECTOR3 vPos; D3DXVECTOR3 vVel; // 파티클 리스트를 따라 파티클을 렌더링한다. while( pParticle ) { vPos = pParticle->m_vPos; vVel = pParticle->m_vVel; /* // 파티클의 잔상을 보여주기 위한 부분. FLOAT fLengthSq = D3DXVec3LengthSq(&vVel); UINT dwSteps; if( fLengthSq < 1.0f ) dwSteps = 2; else if( fLengthSq < 4.00f ) dwSteps = 3; else if( fLengthSq < 9.00f ) dwSteps = 4; else if( fLengthSq < 12.25f ) dwSteps = 5; else if( fLengthSq < 16.00f ) dwSteps = 6; else if( fLengthSq < 20.25f ) dwSteps = 7; else dwSteps = 8; vVel *= -0.04f / (FLOAT)dwSteps; */ D3DXColorLerp( &clrDiffuse, &pParticle->m_clrFade, &pParticle->m_clrDiffuse, pParticle->m_fFade ); DWORD dwDiffuse = (DWORD) clrDiffuse; // Render each particle a bunch of times to get a blurring effect // dwSteps = 1; // for( DWORD i = 0; i < dwSteps; i++ ) { pVertices->v = vPos; pVertices->color = dwDiffuse; pVertices++; if( ++dwNumParticlesToRender == m_dwFlush ) { // Done filling this chunk of the vertex buffer. Lets unlock and // draw this portion so we can begin filling the next chunk. m_pVB->Unlock(); if(FAILED(hr = pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender))) return hr; // Lock the next chunk of the vertex buffer. If we are at the // end of the vertex buffer, DISCARD the vertex buffer and start // at the beginning. Otherwise, specify NOOVERWRITE, so we can // continue filling the VB while the previous chunk is drawing. m_dwBase += m_dwFlush; if(m_dwBase >= m_dwDiscard) m_dwBase = 0; if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(POINTVERTEX), m_dwFlush * sizeof(POINTVERTEX), (void**) &pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) ) { return hr; } dwNumParticlesToRender = 0; } // vPos += vVel; // 잔상처리를 위한 부분. } // for dwSteps pParticle = pParticle->m_pNext; } // particle list // Unlock the vertex buffer m_pVB->Unlock(); // Render any remaining particles if( dwNumParticlesToRender ) // 위에서 512개씩 출력해주고 남은 파티클을 여기서 마저 다 그려줌. { if(FAILED(hr = pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender ))) return hr; } // Reset render states pd3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE ); pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE, FALSE ); pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); // pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); return S_OK; }
//----------------------------------------------------------------------------- // Name: RenderStar() // Desc: ��������� //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::RenderStar() { // ����Ʈ���� ����ϴ� ��� ���� static const s_maxPasses = 3; static const int nSamples = 8; // ������ static const D3DXCOLOR s_colorWhite(0.63f, 0.63f, 0.63f, 0.0f) ; static const D3DXCOLOR s_ChromaticAberrationColor[8] = { D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.0f), // �� D3DXCOLOR(0.8f, 0.3f, 0.3f, 0.0f), // �� D3DXCOLOR(1.0f, 0.2f, 0.2f, 0.0f), // �� D3DXCOLOR(0.5f, 0.2f, 0.6f, 0.0f), // �� D3DXCOLOR(0.2f, 0.2f, 1.0f, 0.0f), // �� D3DXCOLOR(0.2f, 0.3f, 0.7f, 0.0f), // �� D3DXCOLOR(0.2f, 0.6f, 0.2f, 0.0f), // �� D3DXCOLOR(0.3f, 0.5f, 0.3f, 0.0f), // �� } ; static D3DXVECTOR4 s_aaColor[s_maxPasses][nSamples]; for (int p = 0 ; p < s_maxPasses ; p ++) { // �߽ɿ����� �Ÿ������� �������� ����� float ratio = (float)(p + 1) / (float)s_maxPasses ; // ���� ���ø��ؼ� ������ ���� ����� for (int s = 0 ; s < nSamples ; s ++) { D3DXCOLOR chromaticAberrColor ; D3DXColorLerp(&chromaticAberrColor, &( s_ChromaticAberrationColor[s] ), &s_colorWhite, ratio) ; // ��ü���� �� ��ȭ�� ���� D3DXColorLerp( (D3DXCOLOR*)&( s_aaColor[p][s] ), &s_colorWhite, &chromaticAberrColor, 0.7f ) ; } } float radOffset = m_fWorldRotY/5;// ������ ���� ȸ�� // ����ȭ���� ���� ���� ���� D3DSURFACE_DESC desc; m_pSurfStarSource->GetDesc( &desc ); float srcW = (FLOAT) desc.Width; float srcH = (FLOAT) desc.Height; int nStarLines = 6;// ������ �ٱ� ���� for (int d = 0 ; d < nStarLines ; d ++) { // ��� ���� ���� PDIRECT3DTEXTURE9 pTexSource = m_pTexStarSource; float rad = radOffset + 2*d*D3DX_PI/(FLOAT)nStarLines;// ���� float sn = sinf(rad); float cs = cosf(rad); D3DXVECTOR2 vtStepUV = D3DXVECTOR2(0.3f * sn / srcW, 0.3f * cs / srcH); float attnPowScale = (atanf(D3DX_PI/4) + 0.1f) * (160.0f + 120.0f) / (srcW + srcH); int iWorkTexture = 0; for (int p = 0 ; p < s_maxPasses; p++) { // �������� �� ���� PDIRECT3DSURFACE9 pSurfDest = NULL; if (p == s_maxPasses - 1) { // ���� �н��� ������ ���ۿ� Ȯ���Ѵ� pSurfDest = m_apSurfStar[d+2]; } else { pSurfDest = m_apSurfStar[iWorkTexture]; } m_pd3dDevice->SetRenderTarget( 0, pSurfDest ); //�ؽ�ó��ǥ�� �ռ��Ҷ��� ����ġ�� ��� D3DXVECTOR4 avSampleWeights[MAX_SAMPLES]; D3DXVECTOR2 avSampleOffsets[MAX_SAMPLES]; for (int i = 0 ; i < nSamples ; i++) { // ������ ����ġ float lum = powf( 0.95f, attnPowScale * i ); avSampleWeights[i] = s_aaColor[s_maxPasses-1-p][i] * lum * (p+1.0f) * 0.5f ; // �ؽ�ó��ǥ�� �ø� �� avSampleOffsets[i].x = vtStepUV.x * i ; avSampleOffsets[i].y = vtStepUV.y * i ; if ( 0.9f <= fabs(avSampleOffsets[i].x) || 0.9f <= fabs(avSampleOffsets[i].y) ) { avSampleOffsets[i].x = 0.0f ; avSampleOffsets[i].y = 0.0f ; avSampleWeights[i] *= 0.0f ; } } m_pEffect->SetValue("g_avSampleOffsets", avSampleOffsets, sizeof(avSampleOffsets)); m_pEffect->SetVectorArray("g_avSampleWeights", avSampleWeights, nSamples); // ��üȭ�� ���� m_pEffect->SetTechnique("Star"); m_pEffect->Begin(NULL, 0); m_pEffect->Pass(0); m_pd3dDevice->SetTexture( 0, pTexSource ); DrawFullScreenQuad(0.0f, 0.0f, 1.0f, 1.0f); m_pEffect->End(); // ���� �н��� ���� �Ķ���� ���� vtStepUV *= nSamples; attnPowScale *= nSamples; // �������� ����� ���� �ؽ�ó�� �Ѵ� pTexSource = m_apTexStar[iWorkTexture]; iWorkTexture ^= 1; } } // ��� ������ �ռ� m_pd3dDevice->SetRenderTarget( 0, m_apSurfStar[0] ); m_pEffect->SetTechnique("MergeTextures"); m_pEffect->Begin(NULL, 0); m_pEffect->Pass(0); m_pd3dDevice->SetTexture( 0, m_apTexStar[0+2] ); m_pd3dDevice->SetTexture( 1, m_apTexStar[1+2] ); m_pd3dDevice->SetTexture( 2, m_apTexStar[2+2] ); m_pd3dDevice->SetTexture( 3, m_apTexStar[3+2] ); m_pd3dDevice->SetTexture( 4, m_apTexStar[4+2] ); m_pd3dDevice->SetTexture( 5, m_apTexStar[5+2] ); DrawFullScreenQuad(0.0f, 0.0f, 1.0f, 1.0f); m_pEffect->End(); return S_OK; }
/* * Processes the emitter * @author Rigardt de Vries * @param _fDeltaTick the game timer. * @return void */ void CSpiralParticleEmitter::Process(float32 _fDeltaTick) { m_fRotationAngle += _fDeltaTick * 10; if (m_dwVertexBufferSize > m_vecParticles.size()) { m_fSpawnTimer += _fDeltaTick; if (m_fSpawnTimer > m_fEmitRate) { m_fSpawnTimer = 0.0f; //Adding particles to the emitter AddParticle(); } } for(std::vector<TParticle>::iterator iter = m_vecParticles.begin(); iter != m_vecParticles.end(); ++iter) { if(iter->bAlive) { //Adding the velocity to move the particles iter->vec3Position += iter->vec3Velocity * _fDeltaTick; if (m_pTank->GetTeam() == TEAM_GREEN) { if (iter->fLifeTime < 0.3f) { D3DXColorLerp(&iter->colour, &KCOLYELLOW, &KCOLTEAM_GREEN, iter->fLifeTime * 3.333333f); } else { D3DXColorLerp(&iter->colour, &KCOLTEAM_GREEN, &KCOLYELLOW, (iter->fLifeTime - 0.3f) * 3.333333f); } } else { if (iter->fLifeTime < 0.3f) { D3DXColorLerp(&iter->colour, &KCOLTEAM_PURPLE, &KCOLBLUE, iter->fLifeTime * 3.333333f); } else { D3DXColorLerp(&iter->colour, &KCOLBLUE, &KCOLTEAM_PURPLE, (iter->fLifeTime - 0.3f) * 3.333333f); } } //Adding to the life counter iter->fLifeTime += _fDeltaTick; if(iter->fAge <= iter->fLifeTime) { { iter->bAlive = false; } } } } CTotalCubeDomination::GetInstance().GetRenderer()->AddToAllViewports(this, RENDERTYPE_3DCOORDS | RENDERTYPE_ALPHABLEND); m_eFace = m_pTank->GetFacePosition(); m_matWorld._41 = m_pTank->GetWorldMatrix()._41; m_matWorld._42 = m_pTank->GetWorldMatrix()._42; m_matWorld._43 = m_pTank->GetWorldMatrix()._43; }
/* * Process * @author Rigardt de Vries * @param _fDeltaTick the game timer * @return void */ void CFlameParticleEmitter::Process(float32 _fDeltaTick) { if (m_dwVertexBufferSize > m_vecParticles.size()) { m_fSpawnTimer += _fDeltaTick; if (m_fSpawnTimer > m_fEmitRate) { m_fSpawnTimer = 0.0f; //Adding particles to the emitter AddParticle(); } } //Check if particles are still emmiting for(std::vector<TParticle>::iterator iter = m_vecParticles.begin(); iter != m_vecParticles.end(); ++iter) { if (m_pFlameplate->GetActive() == true) { if (iter->bAlive == false) { m_fSpawnTimer += _fDeltaTick; if (m_fSpawnTimer > m_fEmitRate) { m_fSpawnTimer = 0.0f; iter->bAlive = true; } } } if(iter->bAlive) { //Adding the velocity to move the particles iter->vec3Position += iter->vec3Velocity * _fDeltaTick * 8.0f; if (iter->fLifeTime < 0.3f) { D3DXColorLerp(&iter->colour, &KCOLYELLOW, &KCOLRED, iter->fLifeTime * 3.333333f); } else { D3DXColorLerp(&iter->colour, &KCOLRED, &KCOLGREY, (iter->fLifeTime - 0.3f) * 3.333333f); } //Adding to the life counter iter->fLifeTime += _fDeltaTick; if(iter->fAge <= iter->fLifeTime) { if (m_pFlameplate->GetActive() == true) { Resetparticle(&(*iter)); } else { iter->bAlive = false; } } } } CTotalCubeDomination::GetInstance().GetRenderer()->AddToAllViewports(this, RENDERTYPE_3DCOORDS | RENDERTYPE_ALPHABLEND); //Lastly Remove the dead particles CheckAlive(); }
/** * CABT::splitTriangle * @date Modified Apr 18, 2006 */ void CABT::splitTriangle(CMesh::SVertex* pVertex, SPlane& oPlane, std::vector<CMesh::SVertex>& vFront, std::vector<CMesh::SVertex>& vBack) { unsigned int nResA, nResB; CMesh::SVertex vA, vB; vA = pVertex[2]; nResA = getPointClassification(vA.vPosition, oPlane); std::vector<CMesh::SVertex> vFrontFaces, vBackFaces; // Check triangle edges for(unsigned int i = 0; i < 3; ++i) { // Get the next triangle point vB = pVertex[i]; nResB = getPointClassification(vB.vPosition, oPlane); if(nResB == PT_FRONT) { if(nResA == PT_BACK) { // Find intersection D3DXVECTOR3 vIntersect; D3DXPLANE oDXPlane; D3DXPlaneIntersectLine(&vIntersect, D3DXPlaneFromPointNormal(&oDXPlane, &oPlane.point, &oPlane.normal), &vA.vPosition, &vB.vPosition); // Calculate interpolation factor D3DXVECTOR3 vNew, vWhole; D3DXVec3Subtract(&vNew, &vA.vPosition, &vIntersect); D3DXVec3Subtract(&vWhole, &vA.vPosition, &vB.vPosition); float fFactor = D3DXVec3Length(&vNew) / D3DXVec3Length(&vWhole); // Interpolate vertex data. CMesh::SVertex vNewVertex; D3DXCOLOR oColor; vNewVertex.vPosition = vIntersect; D3DXVec3Lerp(&vNewVertex.vNormal, &vA.vNormal, &vB.vNormal, fFactor); D3DXVec2Lerp(&vNewVertex.vTexCoord0, &vA.vTexCoord0, &vB.vTexCoord0, fFactor); D3DXColorLerp(&oColor, &D3DXCOLOR(vA.Color), &D3DXCOLOR(vB.Color), fFactor); vNewVertex.Color = oColor; vFrontFaces.push_back(vNewVertex); vBackFaces.push_back(vNewVertex); } vFrontFaces.push_back(vB); } else if(nResB == PT_BACK) { if(nResA == PT_FRONT) { // Find intersection D3DXVECTOR3 vIntersect; D3DXPLANE oDXPlane; D3DXPlaneIntersectLine(&vIntersect, D3DXPlaneFromPointNormal(&oDXPlane, &oPlane.point, &oPlane.normal), &vA.vPosition, &vB.vPosition); // Calculate interpolation factor D3DXVECTOR3 vNew, vWhole; D3DXVec3Subtract(&vNew, &vA.vPosition, &vIntersect); D3DXVec3Subtract(&vWhole, &vA.vPosition, &vB.vPosition); float fFactor = D3DXVec3Length(&vNew) / D3DXVec3Length(&vWhole); // Interpolate vertex data. CMesh::SVertex vNewVertex; D3DXCOLOR oColor; vNewVertex.vPosition = vIntersect; D3DXVec3Lerp(&vNewVertex.vNormal, &vA.vNormal, &vB.vNormal, fFactor); D3DXVec2Lerp(&vNewVertex.vTexCoord0, &vA.vTexCoord0, &vB.vTexCoord0, fFactor); D3DXColorLerp(&oColor, &D3DXCOLOR(vA.Color), &D3DXCOLOR(vB.Color), fFactor); vNewVertex.Color = oColor; vFrontFaces.push_back(vNewVertex); vBackFaces.push_back(vNewVertex); } vBackFaces.push_back(vB); } else { vFrontFaces.push_back(vB); vBackFaces.push_back(vB); } // Next Edge vA = vB; nResA = nResB; } // Make a triangle list out of the the vertices created. for(unsigned int i = 1; i < vFrontFaces.size() - 1; ++i) { vFront.push_back(vFrontFaces[0]); vFront.push_back(vFrontFaces[i]); vFront.push_back(vFrontFaces[i+1]); } for(unsigned int i = 1; i < vBackFaces.size() - 1; ++i) { vBack.push_back(vBackFaces[0]); vBack.push_back(vBackFaces[i]); vBack.push_back(vBackFaces[i+1]); } }
//-------------------------------------------------------------------------------------- void CTUIBlendColor::Blend( UINT iState, float fElapsedTime, float fRate ) { D3DXCOLOR destColor = States[ iState ]; D3DXColorLerp( &Current, &Current, &destColor, 1.0f - powf( fRate, 30 * fElapsedTime ) ); }