コード例 #1
0
ファイル: polytubefx.cpp プロジェクト: rickyharis39/nolf2
bool CPolyTubeFX::Update(float tmFrameTime)
{
	// Base class update first
	if (!CBaseFX::Update(tmFrameTime)) 
		return false;

	if ((!m_hTexture) && (!m_bLoadFailed))
	{
		m_pLTClient->GetTexInterface()->CreateTextureFromName(m_hTexture, GetProps()->m_sPath);

		if (m_hTexture)
		{
			// Retrieve texture dims
			uint32 nHeight;
			m_pLTClient->GetTexInterface()->GetTextureDims(m_hTexture, m_dwWidth, nHeight);
		}
		else
		{
			m_bLoadFailed = true;
		}
	}

	if ((m_collPathPts.GetSize() < 2) && IsShuttingDown())
	{
		m_collPathPts.RemoveAll();
		return true;
	}
	
	float tmAddPtInterval = GetProps()->m_tmAddPtInterval * 2.0f;

	LTRotation rRot;
	m_pLTClient->GetObjectRotation( m_hObject, &rRot );

	//increase the emission time elapse
	m_tmElapsedEmission += tmFrameTime;

	if (!IsShuttingDown() && 
	    (m_collPathPts.GetSize() < GetProps()->m_nMaxTrailLength) && 
		((m_tmElapsedEmission > GetProps()->m_tmAddPtInterval) || (m_collPathPts.GetSize() == 1)))
	{
		LTVector vNew = m_vPos;
		
		// Only add the new point if it's not the same as the last one....

		// Add a new trail section

		PT_TRAIL_SECTION ts;
		ts.m_vPos		= vNew;
		ts.m_tmElapsed	= 0.0f;

		switch( GetProps()->m_eAllignment )
		{
			case ePTA_Up:
				ts.m_vBisector = rRot.Up();
			break;

			case ePTA_Right:
				ts.m_vBisector = rRot.Right();
			break;

			case ePTA_Forward:
				ts.m_vBisector = rRot.Forward();
			break;

			case ePTA_Camera:
			default:
				ts.m_vBisector.Init();
			break;
		}
		
		
		// Compute u coordinate

		if (m_collPathPts.GetSize())
		{
			LTVector vPrev = m_collPathPts.GetTail()->m_Data.m_vPos;
			float fUPrev = m_collPathPts.GetTail()->m_Data.m_uVal;
			
			float fWidth = (float)m_dwWidth;
			float fScalar = fWidth / GetProps()->m_fTrailWidth;

			ts.m_uVal = fUPrev + ((((vNew - vPrev).Mag()) / fWidth) * fScalar);

		}
		else
		{
			ts.m_uVal = 0.0f;
		}

		m_collPathPts.AddTail(ts);
		
		m_tmElapsedEmission = 0.0f;
	}

	// Render the tube....

	if (m_collPathPts.GetSize() < 2) return true;

	CLinkListNode<PT_TRAIL_SECTION> *pNode = m_collPathPts.GetHead();

	// Fudge the last point to be the current one...

	if( !IsShuttingDown() )
		m_collPathPts.GetTail()->m_Data.m_vPos = m_vPos;

	// Transform the path

	LTMatrix mCam;
	if( m_bReallyClose || (GetProps()->m_eAllignment != ePTA_Camera))
	{
		mCam.Identity();
	}
	else
	{
		mCam = GetCamTransform(m_pLTClient, m_hCamera);
	}
	 
	while (pNode)
	{
		MatVMul(&pNode->m_Data.m_vTran, &mCam, &pNode->m_Data.m_vPos);
		pNode = pNode->m_pNext;
	}

	// Do some precalculations

	pNode = m_collPathPts.GetHead();

	float fCurU = 0.0f;

	while (pNode)
	{
		pNode->m_Data.m_tmElapsed += tmFrameTime;

		if( GetProps()->m_eAllignment == ePTA_Camera )
		{
			LTVector vBisector;
			vBisector.z = 0.0f;

			// Compute the midpoint vectors

			if (pNode == m_collPathPts.GetHead())
			{
				LTVector vStart = pNode->m_Data.m_vTran;
				LTVector vEnd   = pNode->m_pNext->m_Data.m_vTran;
				
				vBisector.x = vEnd.y - vStart.y;
				vBisector.y = -(vEnd.x - vStart.x);
			}
			else if (pNode == m_collPathPts.GetTail())
			{
				LTVector vEnd   = pNode->m_Data.m_vTran;
				LTVector vStart = pNode->m_pPrev->m_Data.m_vTran;
				
				vBisector.x = vEnd.y - vStart.y;
				vBisector.y = -(vEnd.x - vStart.x);
			}
			else
			{
				LTVector vPrev  = pNode->m_pPrev->m_Data.m_vTran;
				LTVector vStart = pNode->m_Data.m_vTran;
				LTVector vEnd   = pNode->m_pNext->m_Data.m_vTran;

				float x1 = vEnd.y - vStart.y;
				float y1 = -(vEnd.x - vStart.x);
				float z1 = vStart.z - vEnd.z;

				float x2 = vStart.y - vPrev.y;
				float y2 = -(vStart.x - vPrev.x);
				float z2 = vPrev.z - vEnd.z;
				
				vBisector.x = (x1 + x2) / 2.0f;
				vBisector.y = (y1 + y2) / 2.0f;
			}

			pNode->m_Data.m_vBisector = vBisector;
		}
		
		LTFLOAT fWidth = CalcCurWidth();
		pNode->m_Data.m_vBisector.Norm( fWidth );

		// Setup the colour
		
		float r, g, b, a;			
		CalcColour(pNode->m_Data.m_tmElapsed, GetProps()->m_tmSectionLifespan, &r, &g, &b, &a);			

		int ir = (int)(r * 255.0f);
		int ig = (int)(g * 255.0f);
		int ib = (int)(b * 255.0f);
		int ia = (int)(a * 255.0f);

		pNode->m_Data.m_red = Clamp( ir, 0, 255 );
		pNode->m_Data.m_green = Clamp( ig, 0, 255 );
		pNode->m_Data.m_blue = Clamp( ib, 0, 255 );
		pNode->m_Data.m_alpha = Clamp( ia, 0, 255 );
	
		pNode = pNode->m_pNext;
	}

	pNode = m_collPathPts.GetHead();

	pNode = m_collPathPts.GetHead();

	// Delete any dead nodes

	while (pNode->m_pNext)
	{
		CLinkListNode<PT_TRAIL_SECTION> *pDelNode= NULL;

		if (pNode->m_Data.m_tmElapsed >= GetProps()->m_tmSectionLifespan)
		{
			pDelNode = pNode;
		}
		
		pNode = pNode->m_pNext;

		if (pDelNode) m_collPathPts.Remove(pDelNode);
	}

	// Increment the offset
	m_uOffset += tmFrameTime * GetProps()->m_uAdd;

	// Success !!

	return true;
}
コード例 #2
0
ファイル: lightningfx.cpp プロジェクト: emoose/lithtech
void CLightningFX::PreRender( float tmFrameTime )
{
	
	LTVector vPulse;
	LTVector vF(0.0f, 0.0f, 1.0f);
	LTVector vU(0.0f, 1.0f, 0.0f);
	LTVector vR(1.0f, 0.0f, 0.0f);

	
	// Transform the bolt 

	LTMatrix mCam;
	if( m_bReallyClose )
	{
		mCam.Identity();
	}
	else
	{
		mCam = GetCamTransform(m_pLTClient, m_hCamera);
	}
	 
	
	CLightningBolt *pBolt = LTNULL;
	LightningBolts::iterator iter;
	for( iter = m_lstBolts.begin(); iter != m_lstBolts.end(); ++iter )
	{
		pBolt = *iter;

		// Skip this bolt if there are not enough segments...

		if( pBolt->m_collPathPts.GetSize() < 2 || !pBolt->m_bActive )
			continue;

		CLinkListNode<PT_TRAIL_SECTION> *pNode = pBolt->m_collPathPts.GetHead();

		//as long as some amount of time has passed, apply a pulse onto the bolt to make
		//it jitter
		if(tmFrameTime > 0.001f)
		{
			while (pNode)
			{
				vPulse = pNode->m_Data.m_vPos;
				vPulse += (vF * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse ));
				vPulse += (vU * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse ));
				vPulse += (vR * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse ));

				if( pNode == pBolt->m_collPathPts.GetHead() || !pNode->m_pNext )
				{
					MatVMul(&pNode->m_Data.m_vTran, &mCam, &pNode->m_Data.m_vPos);
				}
				else
				{
					MatVMul(&pNode->m_Data.m_vTran, &mCam, &vPulse);
				}

				pNode = pNode->m_pNext;
			}
		}

		// Do some precalculations

		float fScale;
		CalcScale( pBolt->m_tmElapsed, pBolt->m_fLifetime, &fScale );
		float fWidth = pBolt->m_fWidth * fScale;

		// Setup the colour
		
		float r, g, b, a;			
		CalcColour( pBolt->m_tmElapsed, pBolt->m_fLifetime, &r, &g, &b, &a );			

		int ir = Clamp( (int)(r * 255.0f), 0, 255 );
		int ig = Clamp( (int)(g * 255.0f), 0, 255 );
		int ib = Clamp( (int)(b * 255.0f), 0, 255 );
		int ia = Clamp( (int)(a * 255.0f), 0, 255 );

		LTVector vStart, vEnd, vPrev, vBisector;
		vBisector.z = 0.0f;

		pNode = pBolt->m_collPathPts.GetHead();

		while( pNode )
		{
			if( GetProps()->m_eAllignment == ePTA_Camera )
			{
				// Compute the midpoint vectors

				if( pNode == pBolt->m_collPathPts.GetHead() )
				{
					vStart = pNode->m_Data.m_vTran;
					vEnd   = pNode->m_pNext->m_Data.m_vTran;
					
					vBisector.x = vEnd.y - vStart.y;
					vBisector.y = -(vEnd.x - vStart.x);
				}
				else if( pNode == pBolt->m_collPathPts.GetTail() )
				{
					vEnd   = pNode->m_Data.m_vTran;
					vStart = pNode->m_pPrev->m_Data.m_vTran;
					
					vBisector.x = vEnd.y - vStart.y;
					vBisector.y = -(vEnd.x - vStart.x);
				}
				else
				{
					vPrev  = pNode->m_pPrev->m_Data.m_vTran;
					vStart = pNode->m_Data.m_vTran;
					vEnd   = pNode->m_pNext->m_Data.m_vTran;

					float x1 = vEnd.y - vStart.y;
					float y1 = -(vEnd.x - vStart.x);
					float z1 = vStart.z - vEnd.z;

					float x2 = vStart.y - vPrev.y;
					float y2 = -(vStart.x - vPrev.x);
					float z2 = vPrev.z - vEnd.z;
					
					vBisector.x = (x1 + x2) / 2.0f;
					vBisector.y = (y1 + y2) / 2.0f;
				}

				pNode->m_Data.m_vBisector = vBisector;
			}
			
			// Set the width for this section...

			pNode->m_Data.m_vBisector.Norm( fWidth );
			
			// Set the color for this section...

			pNode->m_Data.m_red = ir;
			pNode->m_Data.m_green = ig;
			pNode->m_Data.m_blue = ib;
			pNode->m_Data.m_alpha = ia;
		
			pNode = pNode->m_pNext;
		}
	}
}
コード例 #3
0
ファイル: screentrail.cpp プロジェクト: Arc0re/lithtech
void RenderPolyTrail(ILTClient *pClientDE, 
					 CLinkList<TRAIL_SECTION> *pList, 
					 HOBJECT hCamera, 
					 float fTrailWidth,
					 uint8 r,
					 uint8 g,
					 uint8 b,
					 uint8 a,
					 HTEXTURE hTexture,
					 uint32 dwExtraFlags)
{
	CLinkListNode<TRAIL_SECTION> *pNode = pList->GetHead();

	// Transform the path

	LTMatrix mCam = GetCamTransform(pClientDE, hCamera);

	while (pNode)
	{
		MatVMul(&pNode->m_Data.m_vTran, &mCam, &pNode->m_Data.m_vPos);	
		
		pNode = pNode->m_pNext;
	}

	// Do some precalculations

	pNode = pList->GetHead();

	float fCurU = 0.0f;
	
	while (pNode)
	{	
		LTVector vBisector;
		vBisector.z = 0.0f;

		// Compute the midpoint vectors

		if (pNode == pList->GetHead())
		{
			LTVector vStart = pNode->m_Data.m_vTran;
			LTVector vEnd   = pNode->m_pNext->m_Data.m_vTran;
			
			vBisector.x = vEnd.y - vStart.y;
			vBisector.y = -(vEnd.x - vStart.x);
		}
		else if (pNode == pList->GetTail())
		{
			LTVector vEnd   = pNode->m_Data.m_vTran;
			LTVector vStart = pNode->m_pPrev->m_Data.m_vTran;
			
			vBisector.x = vEnd.y - vStart.y;
			vBisector.y = -(vEnd.x - vStart.x);
		}
		else
		{
			LTVector vPrev  = pNode->m_pPrev->m_Data.m_vTran;
			LTVector vStart = pNode->m_Data.m_vTran;
			LTVector vEnd   = pNode->m_pNext->m_Data.m_vTran;

			float x1 = vEnd.y - vStart.y;
			float y1 = -(vEnd.x - vStart.x);

			float x2 = vStart.y - vPrev.y;
			float y2 = -(vStart.x - vPrev.x);
			
			vBisector.x = (x1 + x2) / 2.0f;
			vBisector.y = (y1 + y2) / 2.0f;
		}

		vBisector.Norm(fTrailWidth);
		pNode->m_Data.m_vBisector = vBisector;

		pNode->m_Data.m_red   = r;
		pNode->m_Data.m_green = g;
		pNode->m_Data.m_blue  = b;
		pNode->m_Data.m_alpha = a;

		pNode = pNode->m_pNext;
	}

	pNode = pList->GetHead();

	if (pList->GetSize() < 2) return;

	pNode = pList->GetHead();

	ILTDrawPrim *pDrawPrimLT;
	pDrawPrimLT = pClientDE->GetDrawPrim();

	pDrawPrimLT->SetTexture(hTexture);
	pDrawPrimLT->SetTransformType(DRAWPRIM_TRANSFORM_CAMERA);
	pDrawPrimLT->BeginDrawPrim();


	if (g_bAppFocus)
	{
		uint32 nTris = 0;
		uint32 nVerts = 0;

		LT_POLYGT3 *pTri = g_pTris;
		LTVector *pVerts = g_pVerts;

		while (pNode->m_pNext)
		{
			LTVector vStart = pNode->m_Data.m_vTran;
			LTVector vEnd   = pNode->m_pNext->m_Data.m_vTran;
		
			LTVector vBisector1 = pNode->m_Data.m_vBisector;
			LTVector vBisector2 = pNode->m_pNext->m_Data.m_vBisector;

			*pVerts ++ = vStart + vBisector1;
			*pVerts ++ = vEnd + vBisector2;
			*pVerts ++ = vEnd - vBisector2;
			*pVerts ++ = vStart - vBisector1;

			uint8 r1 = pNode->m_Data.m_red;
			uint8 g1 = pNode->m_Data.m_green;
			uint8 b1 = pNode->m_Data.m_blue;
			uint8 a1 = pNode->m_Data.m_alpha;
			float u1 = pNode->m_Data.m_uVal;

			uint8 r2 = pNode->m_pNext->m_Data.m_red;
			uint8 g2 = pNode->m_pNext->m_Data.m_green;
			uint8 b2 = pNode->m_pNext->m_Data.m_blue;
			uint8 a2 = pNode->m_pNext->m_Data.m_alpha;
			float u2 = pNode->m_pNext->m_Data.m_uVal;
			
			SetupVert(pTri, 0, g_pVerts[nVerts].x, g_pVerts[nVerts].y, g_pVerts[nVerts].z, r1, g1, b1, a1, u1, 0.0f);
			SetupVert(pTri, 1, g_pVerts[nVerts + 1].x, g_pVerts[nVerts + 1].y, g_pVerts[nVerts + 1].z, r2, g2, b2, a2, u2, 1.0f);
			SetupVert(pTri, 2, g_pVerts[nVerts + 2].x, g_pVerts[nVerts + 2].y, g_pVerts[nVerts + 2].z, r2, g2, b2, a2, u2, 1.0f);

			pTri ++;
			nTris ++;

			SetupVert(pTri, 0, g_pVerts[nVerts].x, g_pVerts[nVerts].y, g_pVerts[nVerts].z, r1, g1, b1, a1, u1, 0.0f);
			SetupVert(pTri, 1, g_pVerts[nVerts + 2].x, g_pVerts[nVerts + 2].y, g_pVerts[nVerts + 2].z, r2, g2, b2, a2, u2, 1.0f);
			SetupVert(pTri, 2, g_pVerts[nVerts + 3].x, g_pVerts[nVerts + 3].y, g_pVerts[nVerts + 3].z, r1, g1, b1, a1, u1, 0.0f);

			pTri ++;
			nTris ++;

			nVerts += 4;

			pNode = pNode->m_pNext;

			//see if we need to flush our buffer
			if(nTris >= MAX_BUFFER_TRIS - 2)
			{
				pDrawPrimLT->DrawPrim(g_pTris, nTris);
				nTris = 0;
			}
		}

		// Draw the polylist
		if(nTris > 0)
		{
			pDrawPrimLT->DrawPrim(g_pTris, nTris);
			nTris = 0;
		}
	}

	pDrawPrimLT->BeginDrawPrim();
}