Ejemplo n.º 1
0
void Balls::Update(float timeDelta, int numParticletoEmit, D3DXVECTOR3* EmitPosition)
{
	for (vector<Particle>::iterator citor = buffer.begin(); citor != buffer.end(); ++citor)
	{
		if (citor->isLive) // Only update live particles
		{
			
			citor->age += timeDelta ;
			citor->position.x = citor->velocity.x * citor->age * 10.0f;
			citor->position.y = citor->velocity.y * citor->age * 10.0f + citor->gravity.y * citor->age * citor->age * 10.0f ;

			if (citor->age > citor->lifeTime)
			{
				citor->isLive = false ;
			}
		}
		else
			ResetParticle((Particle*)(&(*citor)), EmitPosition) ;
	}

	// Emit new particle
	for (int i = 0 ; i < numParticletoEmit && buffer.size() < vbSize; ++i)
	{
		Particle particle ;
		ResetParticle(&particle, EmitPosition) ;
		buffer.push_back(particle) ;
	}
}
Ejemplo n.º 2
0
bool SnowParticle::AddParticle()
{
	Particle particle;
	ResetParticle(&particle);
	m_snowPartices.push_back(particle);
	return true;
}
Ejemplo n.º 3
0
ParticleSystem::ParticleSystem(int maxNum, float spread, float life,
						float vx, float vy, float vz, 	
						float ax, float ay, float az, 
						float r, float g, float b)
{
		maxNumParticles = maxNum;
		particles = new Particl[maxNumParticles];
		
		this->spread = spread;
		this->ax = ax;
		this->ay = ay;
		this->az = az;

		this->vx = vx; 
		this->vy = vy;
		this->vz = vz;
		this->life = life;

		this->r = r;
		this->g = g;
		this->b = b;

		for(int i = 0; i < maxNumParticles; i++)
		{
			ResetParticle(i);
		}
}
Ejemplo n.º 4
0
void SpriteGun::Reset() {
  m_IsAlive = false;
  m_Frame = 0;
  m_Life = 0.0;
	for (unsigned int idx=0; idx<m_NumParticles; idx++) {
		ResetParticle(idx);
	}
}
Ejemplo n.º 5
0
void SpriteGun::Build(int n) {
	m_NumParticles = n;
	m_ShootInterval = 1.0;
	m_FrameCounter = 0;
	for (unsigned int idx=0; idx<m_NumParticles; idx++) {
		m_AtlasSprites.push_back(new AtlasSprite(m_ShotFooFoo));
	  m_AtlasSprites[idx]->m_Parent = this;
		ResetParticle(idx);
	}
}
Ejemplo n.º 6
0
// ----------------------------------------------------------------------
// CRainfall::UpdateEngine
// Implementation of CParticleEngine::UpdateEngine(GLfloat aElapsedTime)
// ----------------------------------------------------------------------
//
void CRainfall::UpdateEngine(GLfloat aDeltaTimeSecs)
	{
    for ( GLint i = 0; i < iParticlesCount; i++ )
		{
        iParticles[i].iPosition += (iParticles[i].iVelocity * aDeltaTimeSecs);
        if ( iParticles[i].iPosition.iY < iGroundLevel )
			{
			ResetParticle(i);
			}
		}
	}
Ejemplo n.º 7
0
void SpriteGun::Fire() {
  m_IsAlive = true;
  int shot = 0;
  for (unsigned int i=0; i<m_NumParticles; i++) {
    if (shot == 0 && (m_TimeSinceLastShot > (1.0 / 20.0) && !m_AtlasSprites[i]->m_IsAlive)) {
      LOGV("shoot\n");
      ResetParticle(i);
      ShootParticle(i);
      shot++;
    }
  }
}
Ejemplo n.º 8
0
void Snow::Update(float timeDelta)
{
	list<Attribute>::iterator it = m_lParticles.begin();
	while (it != m_lParticles.end())
	{
		it->_pos += timeDelta*it->_velocity;
		if (!m_BBox.isPointInside(it->_pos))
		{
			ResetParticle(&(*it));
		}
		it++;
	}
}
Ejemplo n.º 9
0
bool ETHParticleManager::Play(const Vector2 &v2Pos, const Vector3 &v3Pos, const float angle)
{
	if (m_pSound)
		m_pSound->Play();
	Matrix4x4 rot = RotateZ(DegreeToRadian(angle));
	m_finished = false;
	for (int t=0; t<m_system.nParticles; t++)
	{
		m_particles[t].repeat = 0;
		m_particles[t].released = false;
		ResetParticle(t, v2Pos, v3Pos, angle, rot);
	}
	return true;
}
Ejemplo n.º 10
0
void Balls::Update(float timeDelta)
{
	for (vector<Particle>::iterator citor = buffer.begin(); citor != buffer.end(); ++citor)
	{
		if (citor->isLive) // Only update live particles
		{
			citor->position += timeDelta * citor->velocity * 20.0f;
			citor->age += timeDelta ;
			if (citor->age > citor->lifeTime)
			{
				citor->isLive = false ;
			}
		}
		else
			ResetParticle((Particle*)(&(*citor))) ;
	}
}
Ejemplo n.º 11
0
    void ParticleEngine::OnLoop()
    {
        if(ActiveEmmitting || Active)
        {

            unsigned int totalDead = 0;

            if( Active)
            {
                if(!CapHit)
                {
                    if(SDL_GetTicks() > (LastUpDate + Rate))
                    {
                        LastUpDate = SDL_GetTicks();
                        for(int i =0; i < emmitionVolume; i++)
                        {

                            particles.push_back(GenerateNewParticle());
                        }
                    }
                }
            }

            std::list<Particle*>::iterator itor = particles.begin();
            for(; itor != particles.end(); ++itor)
            {
                (*itor)->OnLoop();

                if((*itor)->duration <= 0)
                {
                    ++totalDead;
                    if(Active == true)
                    {
                       CapHit= true;
                       ResetParticle((*itor));
                    }
                }
            }

            if(particles.size() == totalDead)
            {
                ActiveEmmitting = false ;
            }
        }

    }
Ejemplo n.º 12
0
//更新粒子的状态
void SnowParticle::Update(float elapsed)
{
	for (std::vector<Particle>::iterator it = m_snowPartices.begin();
		it != m_snowPartices.end();
		it++)
	{
		if (it->isLive)
		{
			//更新雪花的位置,age
			it->age += 0.1f;
			it->color += it->colorFade;
			it->position += it->velocity * 1.0f;
			if (it->age > it->lifeTime)
				it->isLive = false;
		}
		else
		{
			ResetParticle(static_cast<Particle*>(&(*it)));
		}
	}
}
Ejemplo n.º 13
0
ParticleSystem::ParticleSystem(int maxNum, float spread,  
						float vx, float vy, float vz, 	
						float ax, float ay, float az)
{
		maxNumParticles = maxNum;
		particles = new Particle[maxNumParticles];
		
		this->spread = spread;
		this->ax = ax;
		this->ay = ay;
		this->az = az;

		this->vx = vx; 
		this->vy = vy;
		this->vz = vz;

		for(int i = 0; i < maxNumParticles; i++)
		{
			ResetParticle(i);				
		}
}
Ejemplo n.º 14
0
void ParticleSystem::Update()
{
	for(int i = 0; i < maxNumParticles; i++)
	{
		if (particles[i].lifespan < life)
		{
			particles[i].x += particles[i].vx;
			particles[i].y += particles[i].vy;
			particles[i].z += particles[i].vz;
	
			particles[i].vx += ax;	
			particles[i].vy += ay;
			particles[i].vz += az;

			particles[i].lifespan += 1;
		}
		else
		{
			ResetParticle(i);
		}
	}
}
Ejemplo n.º 15
0
/*virtual*/ void ParticleEmitter::Update(float deltaTimeInSeconds)
{
	int arraySize = m_particles.GetCount();
    for(int i = 0; i < arraySize; ++i)
    {
        Particle& p = m_particles[i];
        p.currentLife -= deltaTimeInSeconds;
        if (p.currentLife <= 0.0f)
		{
            ResetParticle(i);
		}
		ShEntity2::Translate(
			p.entity, 
			CShVector3(
				p.velocity.m_x * deltaTimeInSeconds, 
				p.velocity.m_y * deltaTimeInSeconds, 
				0.0f
			)
		);
        float ratio = p.currentLife / m_maxLifetime;
		ShEntity2::SetAlpha(p.entity, ratio);
    }
}
Ejemplo n.º 16
0
void Balls::Update(float timeDelta, int numParticletoEmit)
{
	for (vector<Particle>::iterator citor = buffer.begin(); citor != buffer.end(); ++citor)
	{
		if (citor->isLive) // Only update live particles
		{
			citor->position += timeDelta * citor->velocity * 20.0f;
			citor->age += timeDelta ;
			if (citor->age > citor->lifeTime)
			{
				citor->isLive = false ;
			}
		}
		else
			ResetParticle((Particle*)(&(*citor))) ;
	}

	// Emit new particle
	for (int i = 0 ; i < numParticletoEmit && buffer.size() < vbSize; ++i)
	{
		AddParticle() ;
	}
}
    Particle *CannonSmokeParticleSystem::GenerateNewParticle()
    {
        SDL_Color particleColor= {255,255,255};
        Vector3 particleVelocity;

        if(smokeDirection == Left)
        {
            particleVelocity = Vector3((-5.0f + emitterSpeed.x), (RandomReal(1.0f,2.0f) + (emitterSpeed.y/2.0f)),0.0f);
        }
        else if (smokeDirection == Right)
        {
            particleVelocity = Vector3((5.0f + emitterSpeed.x), (RandomReal(1.0f,2.0f) + (emitterSpeed.y/2.0f)),0.0f);
        }

        int RandomTextureIndex = rand() % (textureCount);

#ifdef DEBUG_MODE
        printf("EmitterLocation X:%f, Y:%f\n", emetterLocation.x, emetterLocation.y);
#endif
        Particle *returnParticle = new Particle (textures[RandomTextureIndex],
                                                 emetterLocation,
                                                 particleVelocity,//Vector3(1.0f * (float)(rand()*2.0f-1.0f),1.0f * (float)(rand()*2.0f-1.0f),0.0f),
                                                 0.0f,
                                                 RandomReal(1.0f,2.0f),
                                                 particleColor,
                                                 RandomReal(0.25f,0.5f),
                                                 (rand()%40+1),
                                                 45
                                                 );

        ResetParticle(returnParticle);

        return (returnParticle);


    }
Ejemplo n.º 18
0
bool ETHParticleManager::CreateParticleSystem(
	const ETHParticleSystem& partSystem,
	const Vector2& v2Pos,
	const Vector3& v3Pos,
	const float angle,
	const float entityVolume,
	const float scale)
{
	GS2D_UNUSED_ARGUMENT(v3Pos);
	if (partSystem.nParticles <= 0)
	{
		ETH_STREAM_DECL(ss) << GS_L("ETHParticleManager::CreateParticleSystem: The number of particles must be greater than 0.");
		m_provider->Log(ss.str(), Platform::FileLogger::ERROR);
		return false;
	}

	m_finished = false;
	m_killed = false;
	m_nActiveParticles = 0;
	m_soundVolume = 1.0f;
	m_isSoundLooping = false;
	m_isSoundStopped = false;
	m_generalVolume = 1.0f;
	m_system = partSystem;
	m_entityVolume = entityVolume;

	m_system.Scale(scale);

	if (m_system.bitmapFile.empty())
	{
		m_system.bitmapFile = ETH_DEFAULT_PARTICLE_BITMAP;
	}

	ETHGraphicResourceManagerPtr graphics = m_provider->GetGraphicResourceManager();
	ETHAudioResourceManagerPtr samples = m_provider->GetAudioResourceManager();
	Platform::FileIOHubPtr fileIOHub = m_provider->GetFileIOHub();
	Platform::FileManagerPtr fileManager = m_provider->GetFileManager();

	// if there's no resource path, search the current module's path
	const str_type::string& resourcePath = fileIOHub->GetResourceDirectory();
	const str_type::string& programPath  = fileIOHub->GetProgramDirectory();
	const str_type::string currentPath = (resourcePath.empty() && !fileManager->IsPacked()) ? programPath : resourcePath;

	m_pBMP = graphics->GetPointer(m_provider->GetVideo(), m_system.bitmapFile, currentPath,
		ETHDirectories::GetParticlesDirectory(), (m_system.alphaMode == Video::AM_ADD));

	// find the particle sound effect
	if (m_system.soundFXFile != GS_L(""))
	{
		m_pSound = samples->GetPointer(m_provider->GetAudio(), m_provider->GetFileIOHub(), m_system.soundFXFile,
			ETHDirectories::GetSoundFXDirectory(), Audio::SOUND_EFFECT);
	}

	if (m_system.allAtOnce)
	{
		m_nActiveParticles = m_system.nParticles;
	}
	else
	{
		m_nActiveParticles = 0;
	}

	m_particles.resize(m_system.nParticles);

	Matrix4x4 rot = RotateZ(DegreeToRadian(angle));
	for (int t = 0; t < m_system.nParticles; t++)
	{
		m_particles[t].id = t;
		m_particles[t].released = false;
		ResetParticle(t, v2Pos, Vector3(v2Pos,0), angle, rot);
	}
	return true;
}
Ejemplo n.º 19
0
bool ETHParticleManager::UpdateParticleSystem(
	const Vector2& v2Pos,
	const Vector3& v3Pos,
	const float angle,
	const unsigned long lastFrameElapsedTime)
{
	bool anythingDrawn = false;
	const unsigned long cappedLastFrameElapsedTime = Min(lastFrameElapsedTime, static_cast<unsigned long>(250));
	const float frameSpeed = static_cast<float>((static_cast<double>(cappedLastFrameElapsedTime) / 1000.0) * 60.0);

	Matrix4x4 rot = RotateZ(DegreeToRadian(angle));
	m_nActiveParticles = 0;
	for (int t = 0; t < m_system.nParticles; t++)
	{
		PARTICLE& particle = m_particles[t];

		if (m_system.repeat > 0)
			if (particle.repeat >= m_system.repeat)
				continue;

		// check how many particles are active
		if (particle.size > 0.0f && particle.released)
		{
			if (!Killed() || (Killed() && particle.elapsed < particle.lifeTime))
				m_nActiveParticles++;
		}

		anythingDrawn = true;

		particle.elapsed += lastFrameElapsedTime;

		if (!particle.released)
		{
			// if we shouldn't release all particles at the same time, check if it's time to release this particle
			const float releaseTime = 
				((m_system.lifeTime + m_system.randomizeLifeTime) * (static_cast<float>(particle.id) / static_cast<float>(m_system.nParticles)));

			if (particle.elapsed > releaseTime || m_system.allAtOnce)
			{
				particle.elapsed = 0.0f;
				particle.released = true;
				PositionParticle(t, v2Pos, angle, rot, v3Pos);
			}
		}

		if (particle.released)
		{
			particle.dir += (m_system.gravityVector * frameSpeed);
			particle.pos += (particle.dir * frameSpeed);
			particle.angle += (particle.angleDir * frameSpeed);
			particle.size  += (m_system.growth * frameSpeed);
			const float w = particle.elapsed / particle.lifeTime;
			particle.color = m_system.color0 + (m_system.color1 - m_system.color0) * w;

			// update particle animation if there is any
			if (m_system.spriteCut.x > 1 || m_system.spriteCut.y > 1)
			{
				if (m_system.animationMode == ETHParticleSystem::PLAY_ANIMATION)
				{
					particle.currentFrame = static_cast<unsigned int>(
						Min(static_cast<int>(static_cast<float>(m_system.GetNumFrames()) * w),
							m_system.GetNumFrames() - 1));
				}
			}

			particle.size = Min(particle.size, m_system.maxSize);
			particle.size = Max(particle.size, m_system.minSize);

			if (particle.elapsed > particle.lifeTime)
			{
				particle.repeat++;
				if (!Killed())
					ResetParticle(t, v2Pos, v3Pos, angle, rot);
			}
		}
	}
	m_finished = !anythingDrawn;

	// manages the sound
	HandleSoundPlayback(v2Pos, frameSpeed);

	return true;
}
Ejemplo n.º 20
0
void Balls::AddParticle()
{
	Particle particle ;
	ResetParticle(&particle) ;
	buffer.push_back(particle) ;
}