Пример #1
0
void ParticleSystem::DrawParticle( particle *part, Vector &right, Vector &up )
{
	float fSize = part->m_fSize;
	Vector point1, point2, point3, point4;
	Vector origin = part->origin;

	// nothing to draw?
	if ( fSize == 0 ) return;

	// frustrum visible check
	if( !ParticleIsVisible( part )) return;

	float fCosSize = CosLookup( part->m_fAngle ) * fSize;
	float fSinSize = SinLookup( part->m_fAngle ) * fSize;

	// calculate the four corners of the sprite
	point1 = origin + fSinSize * up;
	point1 = point1 + (-fCosSize) * right;
	
	point2 = origin + fCosSize * up;
	point2 = point2 + fSinSize * right;

	point3 = origin + (-fSinSize) * up;	
	point3 = point3 + fCosSize * right;

	point4 = origin + (-fCosSize) * up;
	point4 = point4 + (-fSinSize) * right;

	int iContents = 0;

	g_engfuncs.pTriAPI->Enable( TRI_SHADER );

	for ( particle *pDraw = part; pDraw; pDraw = pDraw->m_pOverlay )
	{
		if( pDraw->pType->m_SpriteIndex == 0 )
			continue;

		if ( pDraw->pType->m_iDrawCond )
		{
			if ( iContents == 0 )
				iContents = POINT_CONTENTS( origin );

			if ( iContents != pDraw->pType->m_iDrawCond )
				continue;
		}
                    
		int numFrames = GetModelFrames( pDraw->pType->m_SpriteIndex );

		// ALERT( at_console, "UpdParticle %d: age %f, life %f, R:%f G:%f, B, %f \n", pDraw->pType->m_hSprite, part->age, part->age_death, pDraw->m_fRed, pDraw->m_fGreen, pDraw->m_fBlue);

		// if we've reached the end of the sprite's frames, loop back
		while ( pDraw->frame > numFrames )
			pDraw->frame -= numFrames;

		while ( pDraw->frame < 0 )
			pDraw->frame += numFrames;

		HSPRITE m_hSprite;

		m_hSprite = g_engfuncs.pTriAPI->GetSpriteTexture( pDraw->pType->m_SpriteIndex, int( pDraw->frame ));
		g_engfuncs.pTriAPI->RenderMode( pDraw->pType->m_iRenderMode );
		g_engfuncs.pTriAPI->Color4f( pDraw->m_fRed, pDraw->m_fGreen, pDraw->m_fBlue, pDraw->m_fAlpha );
			
		g_engfuncs.pTriAPI->Bind( m_hSprite, int( pDraw->frame ));
		
		g_engfuncs.pTriAPI->Begin( TRI_QUADS );
		g_engfuncs.pTriAPI->TexCoord2f ( 0, 0 );
		g_engfuncs.pTriAPI->Vertex3fv( point1 );

		g_engfuncs.pTriAPI->TexCoord2f ( 1, 0 );
		g_engfuncs.pTriAPI->Vertex3fv ( point2 );

		g_engfuncs.pTriAPI->TexCoord2f ( 1, 1 );
		g_engfuncs.pTriAPI->Vertex3fv ( point3 );

		g_engfuncs.pTriAPI->TexCoord2f ( 0, 1 );
		g_engfuncs.pTriAPI->Vertex3fv ( point4 );
		g_engfuncs.pTriAPI->End();
	}
	g_engfuncs.pTriAPI->Disable( TRI_SHADER );
}
Пример #2
0
void ParticleSystem::DrawParticle(particle *part, vec3_t &right, vec3_t &up)
{
	float fSize = part->m_fSize;
	vec3_t point1,point2,point3,point4;
	vec3_t origin = part->origin;

	// nothing to draw?
	if (fSize == 0) return;

	//frustrum visible check
	if(!ParticleIsVisible(part)) return;

	float fCosSize = CosLookup(part->m_fAngle)*fSize;
	float fSinSize = SinLookup(part->m_fAngle)*fSize;

	// calculate the four corners of the sprite
	VectorMA (origin, fSinSize, up, point1);
	VectorMA (point1, -fCosSize, right, point1);
	
	VectorMA (origin, fCosSize, up, point2);
	VectorMA (point2, fSinSize, right, point2);
	
	VectorMA (origin, -fSinSize, up, point3);
	VectorMA (point3, fCosSize, right, point3);

	VectorMA (origin, -fCosSize, up, point4);
	VectorMA (point4, -fSinSize, right, point4);

	struct model_s * pModel;
	int iContents = 0;

	for (particle *pDraw = part; pDraw; pDraw = pDraw->m_pOverlay)
	{
		if (pDraw->pType->m_hSprite == 0)
			continue;

		if (pDraw->pType->m_iDrawCond)
		{
			if (iContents == 0)
				iContents = gEngfuncs.PM_PointContents(origin, NULL);

			if (iContents != pDraw->pType->m_iDrawCond)
				continue;
		}

		pModel = (struct model_s *)gEngfuncs.GetSpritePointer( pDraw->pType->m_hSprite );

		// if we've reached the end of the sprite's frames, loop back
		while (pDraw->frame > pModel->numframes) pDraw->frame -= pModel->numframes;

		while (pDraw->frame < 0) pDraw->frame += pModel->numframes;

		if ( !gEngfuncs.pTriAPI->SpriteTexture( pModel, int(pDraw->frame) ))continue;

		gEngfuncs.pTriAPI->RenderMode(pDraw->pType->m_iRenderMode);
		gEngfuncs.pTriAPI->Color4f( pDraw->m_fRed, pDraw->m_fGreen, pDraw->m_fBlue, pDraw->m_fAlpha );
		gEngfuncs.pTriAPI->Begin( TRI_QUADS );
			gEngfuncs.pTriAPI->TexCoord2f (0, 0);
			gEngfuncs.pTriAPI->Vertex3fv(point1);

			gEngfuncs.pTriAPI->TexCoord2f (1, 0);
			gEngfuncs.pTriAPI->Vertex3fv (point2);

			gEngfuncs.pTriAPI->TexCoord2f (1, 1);
			gEngfuncs.pTriAPI->Vertex3fv (point3);

			gEngfuncs.pTriAPI->TexCoord2f (0, 1);
			gEngfuncs.pTriAPI->Vertex3fv (point4);
		gEngfuncs.pTriAPI->End();
	}
}
Пример #3
0
void CParticleSystem :: DrawParticle( CParticle *part, Vector &right, Vector &up )
{
	float fSize = part->m_fSize;

	// nothing to draw?
	if( fSize <= 0 ) return;

	// frustrum visible check
	if( !ParticleIsVisible( part ))
		return;

	Vector point1, point2, point3, point4;
	Vector origin = part->origin;

	float fCosSize = CosLookup( part->m_fAngle ) * fSize;
	float fSinSize = SinLookup( part->m_fAngle ) * fSize;

	// calculate the four corners of the sprite
	point1 = origin + up * fSinSize + right * -fCosSize;
	point2 = origin + up * fCosSize + right * fSinSize;
	point3 = origin + up * -fSinSize + right * fCosSize;	
	point4 = origin + up * -fCosSize + right * -fSinSize;

	int iContents = CONTENTS_NONE;
	model_t *pModel;

	for( CParticle *pDraw = part; pDraw; pDraw = pDraw->m_pOverlay )
	{
		if( !pDraw->pType->m_hSprite )
			continue;

		if( pDraw->pType->m_iDrawCond )
		{
			if( pDraw->pType->m_iDrawCond == CONTENT_SPOTLIGHT )
			{
				if( !R_CountPlights( ))
					continue;	// fast reject

				for( int i = 0; i < MAX_PLIGHTS; i++ )
				{
					plight_t *pl = &cl_plights[i];

					if( pl->die < GET_CLIENT_TIME() || !pl->radius )
						continue;

					if( !R_CullSphereExt( pl->frustum, part->origin, part->m_fSize + 1, pl->clipflags ))
						break; // cone intersected with particle

				}

				if( i == MAX_PLIGHTS )
					continue;	// no intersection
			}
			else
			{
				if( iContents == CONTENTS_NONE )
					iContents = POINT_CONTENTS( origin );

				if( iContents != pDraw->pType->m_iDrawCond )
					continue;
			}
		}

		pModel = (model_t *)gEngfuncs.GetSpritePointer( pDraw->pType->m_hSprite );

		// if we've reached the end of the sprite's frames, loop back
		while (pDraw->frame > pModel->numframes)
			pDraw->frame -= pModel->numframes;

		while (pDraw->frame < 0)
			pDraw->frame += pModel->numframes;

		if( !TriSpriteTexture( pModel, (int)pDraw->frame ))
			continue;

		gEngfuncs.pTriAPI->RenderMode( pDraw->pType->m_iRenderMode );

		if( m_iLightingModel >= 1 )
		{
			color24 lightColor;
			Vector lightingColor;

			if( m_iLightingModel == 1 )
				R_LightForPoint( part->origin, &lightColor, false, true, fSize + 1 );
			else R_LightForPoint( part->origin, &lightColor, false, true, 0.0f );
			
			// FIXME: this code is totally wrong.
			// We need a fake lightmap here like in sprite implementation
			lightingColor.x = pDraw->m_fRed * lightColor.r * (1.0f / 255.0f);
			lightingColor.y = pDraw->m_fGreen * lightColor.g * (1.0f / 255.0f);
			lightingColor.z = pDraw->m_fBlue * lightColor.b * (1.0f / 255.0f);
			pglColor4f( lightingColor.x, lightingColor.y, lightingColor.z, pDraw->m_fAlpha );
		}
		else pglColor4f( pDraw->m_fRed, pDraw->m_fGreen, pDraw->m_fBlue, pDraw->m_fAlpha );

		pglBegin( GL_QUADS );
			pglTexCoord2f( 0.0f, 0.0f );
			pglVertex3fv( point1 );

			pglTexCoord2f( 1.0f, 0.0f );
			pglVertex3fv( point2 );

			pglTexCoord2f( 1.0f, 1.0f );
			pglVertex3fv( point3 );

			pglTexCoord2f( 0.0f, 1.0f );
			pglVertex3fv( point4 );
		pglEnd();

		if( m_iLightingModel >=2 && R_CountPlights( ))
		{
			for( int i = 0; i < MAX_PLIGHTS; i++ )
			{
				plight_t *pl = &cl_plights[i];

				if( pl->die < GET_CLIENT_TIME() || !pl->radius )
					continue;

				if( R_CullSphereExt( pl->frustum, part->origin, part->m_fSize + 1, pl->clipflags ))
					continue;

				R_BeginDrawProjection( pl );

				pglBegin( GL_QUADS );
					pglVertex3fv( point1 );
					pglVertex3fv( point2 );
					pglVertex3fv( point3 );
					pglVertex3fv( point4 );
				pglEnd();

				R_EndDrawProjection();
			}
		}
	}
}