TEST_F(ParticleTest, testParticleSystem) { ParticleSystem system(10000); TestParticleEnv env; const int bubbles = 10000; for (int i = 0; i < bubbles; ++i) { system.spawn(ParticlePtr(new Bubble(env))); } ASSERT_EQ(bubbles, system.getParticleAmount()); ASSERT_TRUE(system.hasParticles()); system.update(1); system.render(&_testFrontend, 0, 0, 1.0f); system.clear(); ASSERT_FALSE(system.hasParticles()); }
void Emitter::Play() { if(particles.empty() && maxParticles > 0) return; for(int i = 0; i < emissionRate && (!particles.empty() || maxParticles == 0); i++) { ParticlePtr particle; if(maxParticles > 0) { particle = particles.front(); particles.pop_front(); } else { particle = ParticlePtr(new Particle()); } InitParticle(particle); emittedParticles.push_front(particle); particle->SetIsVisible(true); } }
void ParticleSystem::fuel(int particles, sf::Vector2f ySpawnRange, sf::Vector2f xSpawnRange) { for (int i = 0; i < particles; i++) { /* Randomizer initialization */ std::random_device rd; std::mt19937 gen(rd()); UniRealDist yposition(ySpawnRange.x, ySpawnRange.y); UniRealDist xposition(xSpawnRange.x, xSpawnRange.y); UniRealDist yspeed(10.0f, 40.0f); m_particleSpeed = yspeed(gen); /* Generate a new particle and put it at the generation point */ Particle *particle; particle = new Particle(); particle->drawVertex.position.x = xposition(gen); particle->drawVertex.position.y = yposition(gen); particle->vel.x = 0.0f; particle->vel.y = 1.0f; /* switch (m_shape) { case Shape::CIRCLE: { // Generate a random angle UniRealDist randomAngle(0.0f, (2.0f * 3.14159265)); float angle = randomAngle(gen); // Use the random angle as a thrust vector for the particle // UniRealDist randomAngleCos(0.0f, cos(angle)); // UniRealDist randomAngleSin(0.0f, sin(angle)); particle->vel.x = (float)(rand() % 100) * 0.01f; // randomAngleCos(gen); particle->vel.y = (float)(rand() % 100) * 0.01f; // randomAngleSin(gen); break; } case Shape::SQUARE: { // Square generation UniRealDist randomSide(-1.0f, 1.0f); particle->vel.x = randomSide(gen); particle->vel.y = randomSide(gen); break; } default: { particle->vel.x = 0.5f; // Easily detected particle->vel.y = 0.5f; // Easily detected } } */ // We don't want lame particles. Reject, start over. if (particle->vel.x == 0.0f && particle->vel.y == 0.0f) { delete particle; continue; } /* Randomly change the colors of the particles */ const auto a = (((m_particleSpeed - 10.0f) / 30.0f) * 255.0f) + 0; particle->drawVertex.color.r = 255; particle->drawVertex.color.g = 255 - a; particle->drawVertex.color.b = 255 - a; particle->drawVertex.color.a = 255; m_particles.push_back(ParticlePtr(particle)); } return; }