/*
* draws the Emitter
* @author Rigardt de Vries
* @return void
*/
void
CPICParticleEmitter::Draw()
{
	if (!m_pVertexBuffer)
    {
        return;
    }
    if (!IsEmpty() )
	{
		TVertexParticleSize* pv;
		DWORD dwNumParticlesInBatch = 0;
		PreDraw();
        CRenderer* pRenderer = CTotalCubeDomination::GetInstance().GetRenderer();

		if (m_ePICType == PIC_BULLET_DAMAGE)
		{
			CTextureManager::GetInstance().SetTexture(0, s_uiBulletDamageID);
		}
		else if (m_ePICType == PIC_BULLET_SPEED)
		{
			CTextureManager::GetInstance().SetTexture(0, s_uiBulletMoveID);
		}
		else if (m_ePICType == PIC_MOVE_SPEED)
		{
			CTextureManager::GetInstance().SetTexture(0, s_uiMoveID);
		}
		else if (m_ePICType == PIC_EXPLODE_RADIUS)
		{
			CTextureManager::GetInstance().SetTexture(0, s_uiRadiusID);
		}
		else 
		{
			CTextureManager::GetInstance().SetTexture(0, s_uiShieldID);
		}

        pRenderer->SetWorldMatrix(m_matWorld);
		pRenderer->GetDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE);
		pRenderer->GetDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(TVertexParticleSize) );

		SortParticles();

		m_pVertexBuffer->Lock(NULL, 0, (void**)&pv, D3DLOCK_DISCARD);

		for (int32 i = 0; i < static_cast<int32>(m_vecParticles.size() ); ++i)
		{
			pv->vec3Position = m_vecParticles[i].vec3Position;
			const D3DXCOLOR& kr = m_vecParticles[i].colour;
			pv->colour = D3DCOLOR_COLORVALUE(kr.r, kr.g, kr.b, kr.a);
			pv->fsize = m_vecParticles[i].fSize;
			pv++;
			++dwNumParticlesInBatch;			
		}
		m_pVertexBuffer->Unlock();
		//if (IsAlive() == true)
		//{
			pRenderer->GetDevice()->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesInBatch);
		//}
		PostDraw();
	}
}
/*
* Draws the particles
*
* @author Michael McQuarrie
*
* @return void
*/
void
CFlagParticleEmitter::Draw()
{
    if (!m_pVertexBuffer)
    {
        return;
    }
    if (!IsEmpty() )
    {
        //First PreDraw it
        TVertexParticleSize* pv;
        DWORD dwNumParticlesInBatch = 0;
        PreDraw();

        //Get the renderer
        CRenderer* pRenderer = CTotalCubeDomination::GetInstance().GetRenderer();

        //Get the texture
        CTextureManager::GetInstance().SetTexture(0, s_uiTextureID);

        //Set Matrix
        pRenderer->SetWorldMatrix(m_matWorld);

        //Set FVF and source things
        pRenderer->GetDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE);
        pRenderer->GetDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(TVertexParticleSize) );

        SortParticles();

        m_pVertexBuffer->Lock(NULL, 0, (void**)&pv, D3DLOCK_DISCARD);

        //Doing colour things
        for (int32 i = 0; i < static_cast<int32>(m_vecParticles.size() ); ++i)
        {
            if (m_vecParticles[i].bAlive)
            {
                pv->vec3Position = m_vecParticles[i].vec3Position;
                const D3DXCOLOR& kr = m_vecParticles[i].colour;
                pv->colour = D3DCOLOR_COLORVALUE(kr.r, kr.g, kr.b, 1.0f - kr.a);
                pv->fsize = m_vecParticles[i].fLifeTime + 0.5f;
                pv++;
                ++dwNumParticlesInBatch;
            }

        }
        m_pVertexBuffer->Unlock();
        //Draw it
        if (IsAlive() == true)
        {
            pRenderer->GetDevice()->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesInBatch);
        }
        //End the drawing
        PostDraw();
    }
}
/*
* Draw the particles in this emitter
* @author Rigardt de Vries
* @return void
*/
void
CSpiralParticleEmitter::Draw()
{
    if (!m_pVertexBuffer)
    {
        return;
    }

	if (!IsEmpty() )
	{
		TVertexParticle* pv;
		DWORD dwNumParticlesInBatch = 0;
		PreDraw();
        CRenderer* pRenderer = CTotalCubeDomination::GetInstance().GetRenderer();
        CTextureManager::GetInstance().SetTexture(0, s_uiTextureID);
        pRenderer->SetWorldMatrix(m_matWorld);
		pRenderer->GetDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
		pRenderer->GetDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(TVertexParticle) );

		SortParticles();

		m_pVertexBuffer->Lock(NULL, 0, (void**)&pv, D3DLOCK_DISCARD);

		for (int32 i = 0; i < static_cast<int32>(m_vecParticles.size() ); ++i)
		{
			if (m_vecParticles[i].bAlive)
			{
				pv->vec3Position = m_vecParticles[i].vec3Position;
				const D3DXCOLOR& kr = m_vecParticles[i].colour;
				pv->colour = D3DCOLOR_COLORVALUE(kr.r, kr.g, kr.b, kr.a);
				pv++;
				++dwNumParticlesInBatch;
			}
			
		}
		m_pVertexBuffer->Unlock();
		if (dwNumParticlesInBatch)
		{
			pRenderer->GetDevice()->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesInBatch);
		}
		PostDraw();
	}
}
Exemplo n.º 4
0
//--------------------------------------------------------------------------------------
void CopyParticlesToVertexBuffer( PARTICLE_VERTEX* pVB, D3DXVECTOR3 vEye, D3DXVECTOR3 vRight, D3DXVECTOR3 vUp )
{
    SortParticles( vEye );

    g_NumActiveParticles = 0;
    UINT iVBIndex = 0;
    for( int i = g_NumUsedParticles - 1; i >= 0; i-- )
    {
        UINT index = g_pParticleIndices[i];

        D3DXVECTOR3 vPos = g_pParticleArray[index].vPos;
        float fRadius = g_pParticleArray[index].fRadius;
        float fRot = g_pParticleArray[index].fRot;
        float fFade = g_pParticleArray[index].fFade;
        DWORD vColor = g_pParticleArray[index].Color;

        if( !g_pParticleArray[index].bVisible )
            continue;

        // rotate
        float fSinTheta = sinf( fRot );
        float fCosTheta = cosf( fRot );

        D3DXVECTOR2 New[4];
        for( int v = 0; v < 4; v++ )
        {
            New[v].x = fCosTheta * g_sQuad[v].x - fSinTheta * g_sQuad[v].y;
            New[v].y = fSinTheta * g_sQuad[v].x + fCosTheta * g_sQuad[v].y;

            New[v].x *= fRadius;
            New[v].y *= fRadius;
        }

        // Tri 0 (0,1,3)
        pVB[ iVBIndex + 2 ].vPos = vPos + vRight * New[0].x + vUp * New[0].y;
        pVB[ iVBIndex + 2 ].vUV = D3DXVECTOR2( 0, 1 );
        pVB[ iVBIndex + 2 ].fLife = fFade;
        pVB[ iVBIndex + 2 ].fRot = fRot;
        pVB[ iVBIndex + 2 ].Color = vColor;
        pVB[ iVBIndex + 1 ].vPos = vPos + vRight * New[1].x + vUp * New[1].y;
        pVB[ iVBIndex + 1 ].vUV = D3DXVECTOR2( 1, 1 );
        pVB[ iVBIndex + 1 ].fLife = fFade;
        pVB[ iVBIndex + 1 ].fRot = fRot;
        pVB[ iVBIndex + 1 ].Color = vColor;
        pVB[ iVBIndex + 0 ].vPos = vPos + vRight * New[3].x + vUp * New[3].y;
        pVB[ iVBIndex + 0 ].vUV = D3DXVECTOR2( 0, 0 );
        pVB[ iVBIndex + 0 ].fLife = fFade;
        pVB[ iVBIndex + 0 ].fRot = fRot;
        pVB[ iVBIndex + 0 ].Color = vColor;

        // Tri 1 (3,1,2)
        pVB[ iVBIndex + 5 ].vPos = vPos + vRight * New[3].x + vUp * New[3].y;
        pVB[ iVBIndex + 5 ].vUV = D3DXVECTOR2( 0, 0 );
        pVB[ iVBIndex + 5 ].fLife = fFade;
        pVB[ iVBIndex + 5 ].fRot = fRot;
        pVB[ iVBIndex + 5 ].Color = vColor;
        pVB[ iVBIndex + 4 ].vPos = vPos + vRight * New[1].x + vUp * New[1].y;
        pVB[ iVBIndex + 4 ].vUV = D3DXVECTOR2( 1, 1 );
        pVB[ iVBIndex + 4 ].fLife = fFade;
        pVB[ iVBIndex + 4 ].fRot = fRot;
        pVB[ iVBIndex + 4 ].Color = vColor;
        pVB[ iVBIndex + 3 ].vPos = vPos + vRight * New[2].x + vUp * New[2].y;
        pVB[ iVBIndex + 3 ].vUV = D3DXVECTOR2( 1, 0 );
        pVB[ iVBIndex + 3 ].fLife = fFade;
        pVB[ iVBIndex + 3 ].fRot = fRot;
        pVB[ iVBIndex + 3 ].Color = vColor;

        iVBIndex += 6;

        g_NumActiveParticles ++;
    }
}