Ejemplo n.º 1
0
int CParticleSystem::Render (void)
{
if (!m_bValid)
	return 0;

	int	h = 0;

if (m_emitters.Buffer ()) {
	if (!particleImageManager.Load (m_nType))
		return 0;
	if ((m_nObject >= 0) && (m_nObject < 0x70000000) &&
		 ((OBJECTS [m_nObject].info.nType == OBJ_NONE) ||
		  (OBJECTS [m_nObject].info.nSignature != m_nSignature) ||
		  (particleManager.GetObjectSystem (m_nObject) < 0)))
		SetLife (0);
	CParticleEmitter *emitterP = m_emitters.Buffer ();
	for (int i = m_nEmitters; i; i--, emitterP++)
		h += emitterP->Render (-1);
	}
#if DBG
if (!h)
	return 0;
#endif
return h;
}
Ejemplo n.º 2
0
int CParticleImageManager::Load (int nType)
{
nType = particleImageManager.GetType (nType);

	tParticleImageInfo&	pii = ParticleImageInfo (nType);

if (pii.bHave)
	return 1;
if (!LoadAddonBitmap (&pii.bmP, pii.szName, &pii.bHave))
	return 0;
#if MAKE_SMOKE_IMAGE
{
	tTgaHeader h;

TGAInterpolate (bmP, 2);
if (TGAMakeSquare (bmP)) {
	memset (&h, 0, sizeof (h));
	SaveTGA (ParticleImageInfo (nType).szName, gameFolders.szDataDir, &h, bmP);
	}
}
#endif
pii.bmP->SetFrameCount ();
pii.bmP->SetupTexture (0, 1);
pii.xBorder = 
pii.yBorder = 0;
if (nType <= SMOKE_PARTICLES)
	;//pii.nFrames = 8; 
else if (nType == BUBBLE_PARTICLES)
	;//pii.nFrames = 4;
else if (nType == WATERFALL_PARTICLES)
	;//pii.nFrames = 8;
else if (nType == FIRE_PARTICLES) {
	;//pii.nFrames = 4; 
	pii.xBorder = 1.0f / float (pii.bmP->Width ());
	pii.yBorder = 1.0f / float (pii.bmP->Height ());
	}
else {
	pii.nFrames = pii.bmP->FrameCount ();
	pii.bAnimate = pii.nFrames > 1;
	}
return 1;
}
Ejemplo n.º 3
0
int CParticle::Create (CFixVector *vPos, CFixVector *vDir, CFixMatrix *mOrient,
							  short nSegment, int nLife, int nSpeed, char nParticleSystemType, char nClass,
						     float nScale, tRgbaColorf *colorP, int nCurTime, int bBlowUp,
							  float fBrightness, CFixVector *vEmittingFace)
{

	static tRgbaColorf	defaultColor = {1,1,1,1};

	tRgbaColorf	color;
	CFixVector	vDrift;
	int			nRad, nFrames, nType = particleImageManager.GetType (nParticleSystemType);

if (nScale < 0)
	nRad = (int) -nScale;
else if (gameOpts->render.particles.bSyncSizes)
	nRad = (int) PARTICLE_SIZE (gameOpts->render.particles.nSize [0], nScale);
else
	nRad = (int) nScale;
if (!nRad)
	nRad = I2X (1);
m_nType = nType;
m_bEmissive = (nParticleSystemType == LIGHT_PARTICLES);
m_nClass = nClass;
m_nSegment = nSegment;
m_nBounce = 0;
color = colorP ? *colorP : defaultColor;
m_color [0] =
m_color [1] = color;
if ((nType == BULLET_PARTICLES) || (nType == BUBBLE_PARTICLES)) {
	m_bBright = 0;
	m_nFade = -1;
	}
else {
	m_bBright = (nType == SMOKE_PARTICLES) ? (rand () % 50) == 0 : 0;
	if (colorP) {
		if (nType != LIGHT_PARTICLES) {
			m_color [0].red *= RANDOM_FADE;
			m_color [0].green *= RANDOM_FADE;
			m_color [0].blue *= RANDOM_FADE;
			}
		m_nFade = 0;
		}
	else {
		m_color [0].red = 1.0f;
		m_color [0].green = 0.5f;
		m_color [0].blue = 0.0f;
		m_nFade = 2;
		}
	if (m_bEmissive)
		m_color [0].alpha = (float) (SMOKE_START_ALPHA + 64) / 255.0f;
	else if (nParticleSystemType != GATLING_PARTICLES) {
		if (!colorP)
			m_color [0].alpha = (float) (SMOKE_START_ALPHA + randN (64)) / 255.0f;
		else {
			if (colorP->alpha < 0)
				m_color [0].alpha = -colorP->alpha;
			else {
				if (2 == (m_nFade = (char) colorP->alpha)) {
					m_color [0].red = 1.0f;
					m_color [0].green = 0.5f;
					m_color [0].blue = 0.0f;
					}
				m_color [0].alpha = (float) (SMOKE_START_ALPHA + randN (64)) / 255.0f;
				}
			}
		}
#if 1
	if (gameOpts->render.particles.bDisperse && !m_bBright) {
		fBrightness = 1.0f - fBrightness;
		m_color [0].alpha += fBrightness * fBrightness / 8.0f;
		}
#endif
	}
//nSpeed = (int) (sqrt (nSpeed) * (float) I2X (1));
nSpeed *= I2X (1);
if (vDir) {
	CAngleVector	a;
	CFixMatrix		m;
	float				d;
	a [PA] = randN (I2X (1) / 4) - I2X (1) / 8;
	a [BA] = randN (I2X (1) / 4) - I2X (1) / 8;
	a [HA] = randN (I2X (1) / 4) - I2X (1) / 8;
	m = CFixMatrix::Create (a);
	vDrift = m * (*vDir);
	CFixVector::Normalize (vDrift);
	d = (float) CFixVector::DeltaAngle (vDrift, *vDir, NULL);
	if (d) {
		d = (float) exp ((I2X (1) / 8) / d);
		nSpeed = (fix) ((float) nSpeed / d);
		}
#if 0
	if (!colorP)	// hack for static particleSystem w/o user defined color
		m_color [0].green =
		m_color [0].blue = 1.0f;
#endif
	vDrift *= nSpeed;
	if ((nType == SMOKE_PARTICLES) || (nType == BUBBLE_PARTICLES))
		m_vDir = *vDir * (I2X (3) / 4 + I2X (randN (16)) / 64);
	else
		m_vDir = *vDir;
	m_bHaveDir = 1;
	}
else {
	CFixVector	vOffs;
	vDrift [X] = nSpeed - randN (2 * nSpeed);
	vDrift [Y] = nSpeed - randN (2 * nSpeed);
	vDrift [Z] = nSpeed - randN (2 * nSpeed);
	vOffs = vDrift;
	m_vDir.SetZero ();
	m_bHaveDir = 1;
	}
m_vDrift = vDrift;
if (vEmittingFace)
	m_vPos = *RandomPointOnQuad (vEmittingFace, vPos);
else if (nType != BUBBLE_PARTICLES)
	m_vPos = *vPos + vDrift * (I2X (1) / 64);
else {
	//m_vPos = *vPos + vDrift * (I2X (1) / 32);
	nSpeed = vDrift.Mag () / 16;
	vDrift = CFixVector::Avg ((*mOrient).RVec () * (nSpeed - randN (2 * nSpeed)), (*mOrient).UVec () * (nSpeed - randN (2 * nSpeed)));
	m_vPos = *vPos + vDrift + (*mOrient).FVec () * (I2X (1) / 2 - randN (I2X (1)));
#if 1
	m_vDrift.SetZero ();
#else
	CFixVector::Normalize (m_vDrift);
	m_vDrift *= I2X (32);
#endif
	}
if ((nType != BUBBLE_PARTICLES) && mOrient) {
		CAngleVector	vRot;
		CFixMatrix		mRot;

	vRot [BA] = 0;
	vRot [PA] = 2048 - ((d_rand () % 9) * 512);
	vRot [HA] = 2048 - ((d_rand () % 9) * 512);
	mRot = CFixMatrix::Create (vRot);
	m_mOrient = *mOrient * mRot;
	}
if (nLife < 0)
	nLife = -nLife;
if (nType == SMOKE_PARTICLES) {
	if (gameOpts->render.particles.bDisperse)
		nLife = (nLife * 2) / 3;
	nLife = nLife / 2 + randN (nLife / 2);
	}
m_nLife =
m_nTTL = nLife;
m_nMoved = nCurTime;
m_nDelay = 0; //bStart ? randN (nLife) : 0;
if (nType == SMOKE_PARTICLES)
	nRad += randN (nRad);
else if (nType == BUBBLE_PARTICLES)
	nRad = nRad / 10 + randN (9 * nRad / 10);
else
	nRad *= 2;
if ((m_bBlowUp = bBlowUp)) {
	m_nRad = nRad / 2;
	m_nWidth =
	m_nHeight = m_nRad;
	m_nRad += m_nRad / bBlowUp;
	}
else {
	m_nWidth =
	m_nHeight = nRad;
	m_nRad = nRad / 2;
	}
nFrames = nParticleFrames [0][nType];
if (nType == BULLET_PARTICLES) {
	m_nFrame = 0;
	m_nRotFrame = 0;
	m_nOrient = 3;
	}
else if (nType == BUBBLE_PARTICLES) {
	m_nFrame = rand () % (nFrames * nFrames);
	m_nRotFrame = 0;
	m_nOrient = 0;
	}
else if (nType == LIGHT_PARTICLES) {
	m_nFrame = 0;
	m_nRotFrame = 0;
	m_nOrient = 0;
	}
else {
	m_nFrame = rand () % (nFrames * nFrames);
	m_nRotFrame = m_nFrame / 2;
	m_nOrient = rand () % 4;
	}
#if 1
if (m_bEmissive)
	m_color [0].alpha *= ParticleBrightness (colorP);
else if (nParticleSystemType == SMOKE_PARTICLES)
	m_color [0].alpha /= colorP ? color.red + color.green + color.blue + 2 : 2;
else if (nParticleSystemType == BUBBLE_PARTICLES)
	m_color [0].alpha /= 2;
else if (nParticleSystemType == LIGHT_PARTICLES)
	m_color [0].alpha /= 5;
#	if 0
else if (nParticleSystemType == GATLING_PARTICLES)
	;//m_color [0].alpha /= 6;
#	endif
#endif
return 1;
}