std::shared_ptr<void> MainThreadStage() { if (!*ps_desc_.ps) { ParticleSystemPtr ps = MakeSharedPtr<ParticleSystem>(NUM_PARTICLES); ps->ParticleAlphaFromTex(ps_desc_.ps_data->particle_alpha_from_tex); ps->ParticleAlphaToTex(ps_desc_.ps_data->particle_alpha_to_tex); ps->ParticleColorFrom(ps_desc_.ps_data->particle_color_from); ps->ParticleColorTo(ps_desc_.ps_data->particle_color_to); ParticleEmitterPtr emitter = ps->MakeEmitter(ps_desc_.ps_data->emitter_type); ps->AddEmitter(emitter); emitter->Frequency(ps_desc_.ps_data->frequency); emitter->EmitAngle(ps_desc_.ps_data->angle); emitter->MinPosition(ps_desc_.ps_data->min_pos); emitter->MaxPosition(ps_desc_.ps_data->max_pos); emitter->MinVelocity(ps_desc_.ps_data->min_vel); emitter->MaxVelocity(ps_desc_.ps_data->max_vel); emitter->MinLife(ps_desc_.ps_data->min_life); emitter->MaxLife(ps_desc_.ps_data->max_life); ParticleUpdaterPtr updater = ps->MakeUpdater(ps_desc_.ps_data->updater_type); ps->AddUpdater(updater); checked_pointer_cast<PolylineParticleUpdater>(updater)->SizeOverLife(ps_desc_.ps_data->size_over_life_ctrl_pts); checked_pointer_cast<PolylineParticleUpdater>(updater)->MassOverLife(ps_desc_.ps_data->mass_over_life_ctrl_pts); checked_pointer_cast<PolylineParticleUpdater>(updater)->OpacityOverLife(ps_desc_.ps_data->opacity_over_life_ctrl_pts); *ps_desc_.ps = ps; } return std::static_pointer_cast<void>(*ps_desc_.ps); }
void ParticleEffect::load(const ParticleEffectTypePtr& effectType) { if(!effectType) stdext::throw_exception("effect type not found"); for(const OTMLNodePtr& childNode : effectType->getNode()->children()) { if(childNode->tag() == "System") { ParticleSystemPtr system = ParticleSystemPtr(new ParticleSystem); system->load(childNode); m_systems.push_back(system); } } }
bool ParticleManager::load(const std::string& filename) { try { OTMLDocumentPtr doc = OTMLDocument::parse(filename); for(const OTMLNodePtr& node : doc->children()) { if(node->tag() == "ParticleSystem") { ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem); particleSystem->load(node); m_systems.push_back(particleSystem); } } return true; } catch(Exception& e) { logError("could not load particles: ", e.what()); return false; } }
void ParticleEmitter::update(float elapsedTime, const ParticleSystemPtr& system) { m_elapsedTime += elapsedTime; // check if finished if(m_duration > 0 && m_elapsedTime >= m_duration + m_delay) { m_finished = true; return; } if(!m_active && m_elapsedTime > m_delay) m_active = true; if(!m_active) return; int nextBurst = std::floor((m_elapsedTime - m_delay) * m_burstRate) + 1; const ParticleType *type = m_particleType.get(); for(int b = m_currentBurst; b < nextBurst; ++b) { // every burst created at same position. float pRadius = stdext::random_range(type->pMinPositionRadius, type->pMaxPositionRadius); float pAngle = stdext::random_range(type->pMinPositionAngle, type->pMaxPositionAngle); Point pPosition = m_position + Point(pRadius * std::cos(pAngle), pRadius * std::sin(pAngle)); for(int p = 0; p < m_burstCount; ++p) { float pDuration = stdext::random_range(type->pMinDuration, type->pMaxDuration); // particles initial velocity float pVelocityAbs = stdext::random_range(type->pMinVelocity, type->pMaxVelocity); float pVelocityAngle = stdext::random_range(type->pMinVelocityAngle, type->pMaxVelocityAngle); PointF pVelocity(pVelocityAbs * std::cos(pVelocityAngle), pVelocityAbs * std::sin(pVelocityAngle)); // particles initial acceleration float pAccelerationAbs = stdext::random_range(type->pMinAcceleration, type->pMaxAcceleration); float pAccelerationAngle = stdext::random_range(type->pMinAccelerationAngle, type->pMaxAccelerationAngle); PointF pAcceleration(pAccelerationAbs * std::cos(pAccelerationAngle), pAccelerationAbs * std::sin(pAccelerationAngle)); ParticlePtr particle(new Particle(pPosition, type->pStartSize, type->pFinalSize, pVelocity, pAcceleration, pDuration, type->pIgnorePhysicsAfter, type->pColors, type->pColorsStops, type->pCompositionMode, type->pTexture)); system->addParticle(particle); } } m_currentBurst = nextBurst; }
bool OpenGLGraphics::compare_particle_systems(ParticleSystemPtr o1, ParticleSystemPtr o2) { return o1->texture() < o2->texture(); }
/** * SplashManager initialisation */ void SplashManager::init() { if (!initialised_) { static bool first = true; if (first) { MF_WATCH( "Client Settings/Water/Splash/enable splash", s_enableSplash, Watcher::WT_READ_WRITE, "enable splashes" ); MF_WATCH( "Client Settings/Water/Splash/variable speed", s_enableVelocity, Watcher::WT_READ_WRITE, "enable adjustments to the splash particle speed based on impact strength" ); MF_WATCH( "Client Settings/Water/Splash/splash spacing", s_splashSpacing, Watcher::WT_READ_WRITE, "splash spacing" ); MF_WATCH( "Client Settings/Water/Splash/splash scale", s_splashScale, Watcher::WT_READ_WRITE, "splash scale" ); MF_WATCH( "Client Settings/Water/Splash/splash height", s_splashHeight, Watcher::WT_READ_WRITE, "splash height" ); MF_WATCH( "Client Settings/Water/Splash/avg vel", s_avgVelocity, Watcher::WT_READ_WRITE, "splash avg vel" ); first = false; } waterSplash_.splash_ = new MetaParticleSystem(); waterSplash_.splash_->load( s_waterSplash.value(), "" ); waterSplash_.attachment_ = new SplashMatrixLiaison; waterSplash_.splash_->attach( waterSplash_.attachment_ ); waterSplash_.impact_ = new MetaParticleSystem(); waterSplash_.impact_->load( s_waterImpact.value(), "" ); waterSplash_.impact_->attach( waterSplash_.attachment_ ); if (waterSplash_.splash_) { for (uint32 i=0; i<waterSplash_.splash_->nSystems(); i++) { ParticleSystemPtr ps = waterSplash_.splash_->systemFromIndex(i); if (ps) { SourcePSA * pSplashSource_ = static_cast<SourcePSA*>(&*ps->pAction(PSA_SOURCE_TYPE_ID)); VectorGenerator* vel = pSplashSource_->getVelocitySource(); if (vel->nameID() == PointVectorGenerator::nameID_) { PointVectorGenerator* pointVel = static_cast<PointVectorGenerator*>(vel); pointVGen_.push_back( std::make_pair(pointVel, pointVel->position().y) ); } else if (vel->nameID() == CylinderVectorGenerator::nameID_) { CylinderVectorGenerator* cylVel = static_cast<CylinderVectorGenerator*>(vel); cylinderVGen_.push_back( std::make_pair( cylVel, Vector2(cylVel->origin().y, cylVel->destination().y) ) ); } } } } initialised_ = true; } }