Ejemplo n.º 1
0
void PlaySpace::spawnExplosion(Vec2F position, float size, float force, Color fireColor)
{
	RangeI amountParticles = RangeI(size/10, size/10+size/20);
	//castParticles(gAssets.ExplosionCloud,          position, gRNG.getNumber(amountParticles), {0.f, force*2}, (fireColor+Colors::White)/2, {size/800, size/600}, {0.75f, 1.25f});
	castParticles(gAssets.ExplosionCloudAdditive,  position, gRNG.getNumber(amountParticles), {0.f, force*0.5f}, fireColor, {size/1000, size/700}, {0.75f, 1.25f});
	castParticles(gAssets.ExplosionSparks,         position, gRNG.getNumber(amountParticles), RangeF{force*1, force*3} + 10, fireColor);
	
	spawnParticle(gAssets.ExplosionFlash,          position, size/100, Angle::FromTurn(gRNG.getFloat()), fireColor, 1.f, true);
	spawnParticle(gAssets.ExplosionShockwave,      position, force/80, Angle::FromTurn(gRNG.getFloat()), fireColor, 1.f, true);
	spawnParticle(gAssets.GlowParticle,            position, size/13 , Angle::FromTurn(gRNG.getFloat()), fireColor, 4.f, true);

	gAssets.SoundExplosion02.play(position);
}
Ejemplo n.º 2
0
void ParticleSpawner::step(float dtime, ClientEnvironment* env)
{
	m_time += dtime;

	static thread_local const float radius =
			g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE;

	bool unloaded = false;
	bool is_attached = false;
	v3f attached_pos = v3f(0,0,0);
	float attached_yaw = 0;
	if (m_attached_id != 0) {
		if (ClientActiveObject *attached = env->getActiveObject(m_attached_id)) {
			attached_pos = attached->getPosition() / BS;
			attached_yaw = attached->getYaw();
			is_attached = true;
		} else {
			unloaded = true;
		}
	}

	if (m_spawntime != 0) {
		// Spawner exists for a predefined timespan
		for (std::vector<float>::iterator i = m_spawntimes.begin();
				i != m_spawntimes.end();) {
			if ((*i) <= m_time && m_amount > 0) {
				m_amount--;

				// Pretend to, but don't actually spawn a particle if it is
				// attached to an unloaded object or distant from player.
				if (!unloaded)
					spawnParticle(env, radius, is_attached, attached_pos, attached_yaw);

				i = m_spawntimes.erase(i);
			} else {
				++i;
			}
		}
	} else {
		// Spawner exists for an infinity timespan, spawn on a per-second base

		// Skip this step if attached to an unloaded object
		if (unloaded)
			return;

		for (int i = 0; i <= m_amount; i++) {
			if (rand() / (float)RAND_MAX < dtime)
				spawnParticle(env, radius, is_attached, attached_pos, attached_yaw);
		}
	}
}
Ejemplo n.º 3
0
// manage particle engine each frame; do not call until you want particles to begin spawning
void Graphics::manageParticles(int which)
{
	// static int counter = 0;
	switch (which)
	{
	case SNOW:
		float loops = particleDensity;
		if (loops < 1 && loops > 0)
			loops = (rand() % abs(static_cast<int>(loops * 100 - 100)) == 1 ? 1 : 0);
		while (loops-- > 0)
		{
			spawnParticle(which);
		}
		for (int i = 0; i < particles.size(); i++)
		{
			if (particles[i].first->txRect.y > Level::geth('p'))
			{
				delete particles[i].first;
				particles[i].first = NULL;
				particles.erase(particles.begin() + i);
				i--;
			}
			else
			{
				if(rand() % 8 == 1)
					particles[i].first->txRect.x += (particles[i].second / 2 * (rand() % 2 == 0 ? -1 : 1));
				particles[i].first->txRect.y += particles[i].second;
			}
		}
		break;
	}
}
Ejemplo n.º 4
0
void ParticleEmitter::emit()
{
	int spawn_count = m_spawn_count.getRandom();
	for (int i = 0; i < spawn_count; ++i)
	{
		spawnParticle();
	}
}
Ejemplo n.º 5
0
void PlaySpace::spawnParticle(Particle def, Vec2F position, float scale, Angle rotation, Color col, float lifetime, bool important)
{
	def.Position = position;
	def.Size = scale;
	def.Rotation = rotation;
	def.Colorization = col;
	def.LifeTimeMult = lifetime;
	spawnParticle(def, important);
}
Ejemplo n.º 6
0
std::shared_ptr<Ego::Particle> ParticleHandler::spawnGlobalParticle(const Vector3f& spawnPos, const Facing& spawnFacing,
                                                                    const LocalParticleProfileRef& pip_index, int multispawn, const bool onlyOverWater)
{
    //Get global particle profile
    PIP_REF globalProfile = ((pip_index.get() < 0) || (pip_index.get() > MAX_PIP)) ? MAX_PIP : static_cast<PIP_REF>(pip_index.get());

    return spawnParticle(spawnPos, spawnFacing, INVALID_PRO_REF, globalProfile, ObjectRef::Invalid, GRIP_LAST, Team::TEAM_NULL,
                         ObjectRef::Invalid, ParticleRef::Invalid, multispawn, ObjectRef::Invalid, onlyOverWater);
}
Ejemplo n.º 7
0
void ParticleEmitter::update(float deltaTime) {
	VBE_ASSERT(period > 0, "Invalid particle emitter period. Period must be bigger than 0.");
	currWorldPos = vec3f(fullTransform*vec4f(0, 0, 0, 1));
	while(state < deltaTime) {
		state += period;
		spawnParticle(state, deltaTime);
	}
	state -= deltaTime;
	oldWorldPos = currWorldPos;

}
bool ParticleEmitterPressure::stepEmissionSite(
	SiteData& siteData,
	ParticleData& spawnData,
	PxU32& spawnNum, 
	const PxU32 spawnMax,
	const PxVec3 &sitePos, 
	const PxVec3 &siteVel,
	const PxReal dt)
{
	PxReal maxDistanceMoved = 5.0f * mSpacingZ;	// don't generate long particle beams

	/**
	 * Find displacement vector of the particle's motion this frame
	 * this is not necessarily v*stepSize because a collision might have occured
	 */
	PxVec3 displacement = siteData.position - sitePos;
	PxVec3 normal = displacement;
	PxReal distanceMoved = normal.normalize();

	if (distanceMoved > maxDistanceMoved)
		distanceMoved = maxDistanceMoved;
	
	/**
	 * Place particles along line between emission point and new position
	 * starting backwards from the new position
	 * spacing between the particles is the rest spacing of the fluid 
	 */
	PxReal lastPlaced = 0.0f;
	while((lastPlaced + mSpacingZ) <= distanceMoved)
	{
		PxVec3 pos = sitePos + normal * (distanceMoved - (lastPlaced + mSpacingZ));

		PxVec3 posNoise;
		posNoise.x = randInRange(-mRandomPos.x, mRandomPos.x);
		posNoise.y = randInRange(-mRandomPos.y, mRandomPos.y);		
		
		pos += mAxisX*posNoise.x + mAxisY*posNoise.y;

		bool isSpawned = spawnParticle(spawnData, spawnNum, spawnMax, pos, siteVel);
		if(isSpawned)
		{
			updatePredecessor(siteData, pos, siteVel);
			lastPlaced += mSpacingZ;
		}
		else
		{
			return false;
		}
	}
	return true;
}
Ejemplo n.º 9
0
std::shared_ptr<Ego::Particle> ParticleHandler::spawnLocalParticle(const Vector3f& pos, const Facing& facing, const PRO_REF iprofile, const LocalParticleProfileRef& pip_index,
                                                                   const ObjectRef chr_attach, Uint16 vrt_offset, const TEAM_REF team,
                                                                   const ObjectRef chr_origin, const ParticleRef prt_origin, int multispawn, const ObjectRef oldtarget)
{
    if(!ProfileSystem::get().isValidProfileID(iprofile)) {
		Log::get().debug("spawnLocalParticle() - cannot spawn particle with invalid PRO_REF %d\n", iprofile);
        return Ego::Particle::INVALID_PARTICLE;
    }

    //Local character pip
    PIP_REF ipip = ProfileSystem::get().getProfile(iprofile)->getParticleProfile(pip_index); 

    return spawnParticle(pos, facing, iprofile, ipip, chr_attach, vrt_offset, team, chr_origin, prt_origin, multispawn, oldtarget);
}
Ejemplo n.º 10
0
void ParticleSystem::spawnCycle(UpdateInfo info)
{
	// Spawn particles
	if (age <= duration && info.elapsedGameTime - lastSpawnEvent >= spawnRate)
	{
		int particlesToSpawn = (info.elapsedGameTime - lastSpawnEvent) / spawnRate;

		for (int i = 0; i < particlesToSpawn; i++)
		{
			spawnParticle();
		}

		lastSpawnEvent = info.elapsedGameTime;
	}
}
Ejemplo n.º 11
0
void ParticleEmitter::spawnParticles(float time_delta)
{
	m_next_spawn_time -= time_delta;

	while (m_next_spawn_time < 0)
	{
		m_next_spawn_time += m_spawn_period.getRandom();

		int spawn_count = m_spawn_count.getRandom();
		for (int i = 0; i < spawn_count; ++i)
		{
			spawnParticle();
		}
	}
}
Ejemplo n.º 12
0
void Sampler::playSound(float volume, float pitch) {

	int note = valueToNote(pitch);
	playbackSpeed = noteToSpeed(note);
	sample.trigger(volume);
	noteLastTime = ofGetElapsedTimef();
	lastNote = vision.levels.size() - pitch*vision.levels.size();

	// do some stuff here
	ofPoint pos, force;
	if(vision.getBiggestFlowPoint(&pos, &force)) {
		// correct the y pos
		float y = (float)((float)lastMaxLevel+0.5)/vision.levels.size();
		pos.y = y;
		spawnParticle(pos, volume);
	}
}
Ejemplo n.º 13
0
void ParticleEmitter::update()
{
	if(disableTimer >= 0)
	{
		disableTimer -= dt;
		if(disableTimer < 0)
			enabled = false;
	}
	
	if(!enabled) return;
	
	state += dt;
	while(state > period)
	{
		state -= period;
		spawnParticle();
	}
}
//Replenishes particles, spawning new particles while the number of active particles is below the max amount of particles allowed with;
//the time since the last update call
void ParticleSystem::replenishParticles(float dt) {

	int numParticlesToSpawn;
	//work out the number of particles that can be spawned in the length of time it took since the last update if the system is spawning faster than the systems FPS
	if (EmissionRate < dt)
		numParticlesToSpawn = dt / EmissionRate;
	else
		numParticlesToSpawn = 1;

	//if the system can spawn more particles and the cooldown for spawning particles has been passed, then spawn a new particle
	while ((numParticlesToSpawn > 0 || EmissionRate == 0) && _totalActiveParticles < MaxParticles) {

		//decrement the num of particles to spawn count
		numParticlesToSpawn--;
		spawnParticle();
	}

	//reset the emission count
	_emissionCountdown = EmissionRate;
}
Ejemplo n.º 15
0
void PlaySpace::castParticles(const Particle& def, Vec2F position, int amount, RangeF power, Color col, RangeF scale, RangeF lifetime, float turbulenceFactor)
{
	for(int i = 0; i < amount; ++i)
	{
		Noise1D turbulence;
		turbulence.Octaves = 2;
		turbulence.Interval = 0.25f;
		
		Particle p(def);
		float angleF = gRNG.getFloat();
		Angle angle = Angle::FromTurn(angleF);
		float angTurb = turbulence.calc(angleF);
		
		p.Colorization = col;
		p.Position = position;
		p.Size = gRNG.getNumber(scale);
		p.Speed = angle.toDirection() * power.interpolate(gRNG.getFloat()  * ((1-turbulenceFactor) + angTurb*angTurb*turbulenceFactor));
		p.Rotation = angle;
		p.LifeTimeMult = gRNG.getNumber(lifetime);
		spawnParticle(p, false);
	}
}
Ejemplo n.º 16
0
// manage particle engine each frame; do not call until you want particles to begin spawning
void Graphics::manageParticles(int which)
{
	SDL_Rect part = { 0, 0, 0, 0 };
	float loops = particleDensity;
	// static int counter = 0;
	switch (which)
	{
	case SNOW_PART:
		if (loops < 1 && loops > 0)
			loops = (rand() % abs(static_cast<int>(loops * 100 - 100)) == 1 ? 1 : 0);
		while (loops-- > 0)
		{
			spawnParticle(which);
		}
		for (int i = 0; i < particles.size(); i++)
		{
			if (particles[i].first->txRect.y > Level::geth('p'))
			{
				delete particles[i].first;
				particles[i].first = NULL;
				particles.erase(particles.begin() + i);
				i--;
			}
			else
			{
				if(rand() % 8 == 1)
					particles[i].first->txRect.x += (particles[i].second / 2 * (rand() % 2 == 0 ? -1 : 1));
				particles[i].first->txRect.y += particles[i].second;

				if (Game::checkCollision(viewport, particles[i].first->txRect))
				{
					part = particles[i].first->txRect;
					particles[i].first->txRect = { particles[i].first->txRect.x - viewport.x, particles[i].first->txRect.y - viewport.y, particles[i].first->txRect.w, particles[i].first->txRect.h };
					particles[i].first->txRender();
					particles[i].first->txRect = part;
				}
			}
		}
		break;
	case SAND_PART:
		if (loops < 1 && loops > 0)
			loops = (rand() % abs(static_cast<int>(loops * 100 - 100)) == 1 ? 1 : 0);
		while (loops-- > 0)
		{
			part.y = rand() % (Game::gPlayer->rect.y + viewport.h) + (Game::gPlayer->rect.y - viewport.h);
			part.w /= (rand() % 9 + 1);
			if (part.w <= 0)
				part.w = 1;
			part.h = part.w;
			part.x = Game::gPlayer->rect.x + viewport.w + part.w;
			spawnParticle(which, &part);
		}
		for (int i = 0; i < particles.size(); i++)
		{
			if (particles[i].first->txRect.x + particles[i].first->txRect.w < Game::gPlayer->rect.x - viewport.w)
			{
				delete particles[i].first;
				particles[i].first = NULL;
				particles.erase(particles.begin() + i);
				i--;
			}
			else
			{
				if (rand() % 8 == 1)
					particles[i].first->txRect.y += (particles[i].second / 2 * (rand() % 2 == 0 ? -1 : 1));
				particles[i].first->txRect.x -= particles[i].second;

				if (Game::checkCollision(viewport, particles[i].first->txRect))
				{
					part = particles[i].first->txRect;
					particles[i].first->txRect = { particles[i].first->txRect.x - viewport.x, particles[i].first->txRect.y - viewport.y, particles[i].first->txRect.w, particles[i].first->txRect.h };
					particles[i].first->txRender();
					particles[i].first->txRect = part;
				}
			}
		}
		break;
	}
}
Ejemplo n.º 17
0
void ParticleEmitterRate::stepInternal(ParticleData& particles, PxReal dt, const PxVec3& externalAcceleration, PxReal maxParticleVelocity)
{
	PX_ASSERT(mNumX > 0 && mNumY > 0);
	PxU32 numEmittedParticles = 0;

	//figure out how many particle have to be emitted with the given rate.
	mParticlesToEmit += mRate*dt;
	PxU32 numEmit = (PxU32)(mParticlesToEmit);
	if(numEmit == 0)
		return;
	
	PxU32 numLayers = (PxU32)(numEmit / (mNumX * mNumY)) + 1;
	PxReal layerDistance = dt * mVelocity / numLayers;

	PxU32 sparseMax = 0;

	//either shuffle or draw without repeat (approximation)
	bool denseEmission = (PxU32(PARTICLE_EMITTER_SPARSE_FACTOR*numEmit) > mNumSites);
	if(denseEmission)
	{
		initDenseSites();
	}
	else
	{
		sparseMax = PARTICLE_EMITTER_SPARSE_FACTOR*numEmit;
		mSites.resize(sparseMax);
	}

	// generate particles
	PxU32 l = 0;
	while(numEmit > 0)
	{
		PxVec3 layerVec = mAxisZ * (layerDistance * (PxReal)l);
		l++;

		if(denseEmission)
			shuffleDenseSites();
		else
			initSparseSiteHash(numEmit, sparseMax);

		for (PxU32 i = 0; i < mNumSites && numEmit > 0; i++)
		{
			PxU32 emissionSite;
			if (denseEmission)
				emissionSite = mSites[i];
			else
				emissionSite = pickSparseEmissionSite(sparseMax);

			PxU32 x = emissionSite / mNumY;
			PxU32 y = emissionSite % mNumY;

			PxReal offset = 0.0f;
			if (y%2) offset = mSpacingX * 0.5f;
				
			if (isOutsideShape(x,y,offset)) 
				continue;

			//position noise
			PxVec3 posNoise;
			posNoise.x = randInRange(-mRandomPos.x, mRandomPos.x);
			posNoise.y = randInRange(-mRandomPos.y, mRandomPos.y);	
			posNoise.z = randInRange(-mRandomPos.z, mRandomPos.z);	

			PxVec3 emissionPoint = mBasePos + layerVec + 
				mAxisX*(posNoise.x+offset+mSpacingX*x) + mAxisY*(posNoise.y+mSpacingY*y) + mAxisZ*posNoise.z;

			PxVec3 particleVelocity;
			computeSiteVelocity(particleVelocity, emissionPoint);

			bool isSpawned = spawnParticle(particles, numEmittedParticles, particles.maxParticles - particles.numParticles, emissionPoint, particleVelocity);
			if(isSpawned)
			{
				numEmit--;
				mParticlesToEmit -= 1.0f;
			}
			else
				return;
		}
	}
}
void ParticleEmitterPressure::stepInternal(ParticleData& particles, PxReal dt, const PxVec3& externalAcceleration, PxReal maxParticleVelocity)
{
	PX_ASSERT(mNumX > 0 && mNumY > 0);
	
	mSimulationAcceleration = externalAcceleration;
	mSimulationMaxVelocity = maxParticleVelocity;
	
	PxU32 numEmittedParticles = 0;

	PxU32 maxParticlesPerStep = (PxU32)physx::shdfnd::floor(mMaxRate*dt);
	PxU32 maxParticles = PxMin(particles.maxParticles - particles.numParticles, maxParticlesPerStep);

	PxU32 siteNr = 0;	
	for(PxU32 y = 0; y != mNumY; y++)
	{
		PxReal offset = 0.0f;
		if (y%2) offset = mSpacingX * 0.5f;

		for(PxU32 x = 0; x != mNumX; x++)
		{
			if (isOutsideShape(x,y,offset))
				continue;

			SiteData& siteData = mSites[siteNr];

			//position noise
			PxVec3 posNoise;
			posNoise.x = randInRange(-mRandomPos.x, mRandomPos.x);
			posNoise.y = randInRange(-mRandomPos.y, mRandomPos.y);
			
			//special code for Z noise 
			if (!siteData.predecessor) 
				siteData.noiseZ = randInRange(-mRandomPos.z, mRandomPos.z);
			else
			{
				PxReal noiseZOffset = PxMin(mMaxZNoiseOffset, mRandomPos.z);
				siteData.noiseZ += randInRange(-noiseZOffset, noiseZOffset);
				siteData.noiseZ = PxClamp(siteData.noiseZ, mRandomPos.z, -mRandomPos.z);
			}

			posNoise.z = siteData.noiseZ;

			//set position
			PxVec3 sitePos = mBasePos + mAxisX*(offset+mSpacingX*x) + mAxisY*(mSpacingY*y) + mAxisZ*siteData.noiseZ;
			PxVec3 particlePos = sitePos + mAxisX*posNoise.x + mAxisY*posNoise.y;

			PxVec3 siteVel;
			computeSiteVelocity(siteVel, particlePos);

			if (siteData.predecessor)
			{
				predictPredecessorPos(siteData, dt);
			}
			else			{
				bool isSpawned = spawnParticle(particles, numEmittedParticles, maxParticles, particlePos, siteVel);
				if(isSpawned)
				{
					updatePredecessor(siteData, particlePos, siteVel);
				}
				else
				{
					siteData.predecessor = false;
					return;
				}
			}
			
			bool allSpawned = stepEmissionSite(siteData, particles, numEmittedParticles, maxParticles, sitePos, siteVel, dt);
			if(!allSpawned)
				return;

			siteNr++;
		}
	}
}