// Add a particle emitter to the world with a default size, emit rate and // starting velocity. FaucetEmitter* LiquidFunScene::AddEmitter( const b2Vec2& origin, const std::vector<b2ParticleColor> &colors, const float colorCycleRate) { // Initial velocity of each emitted particle. static const b2Vec2 k_startingVelocity(0, -5.0); // Faucet size as a fraction of the world's maximum dimension. static const float32 k_faucetSize = 0.01f; // Number of particles to emit per second. static const float32 k_emitRate = 10.0f; return AddEmitter(origin, m_worldExtentMax * k_faucetSize, k_emitRate, k_startingVelocity, colors, colorCycleRate); }
void ParticleGroup::Init( LPDIRECT3DDEVICE9 pDevice ) { m_pDevice = pDevice; SetTexture("Flare.tga"); m_CommonUp.x = 0; m_CommonUp.y = 1; m_CommonUp.z = 0; m_CommonDirection.x = 0; m_CommonDirection.y = 0; m_CommonDirection.z = -1; m_fTexAnimDuration = 5.0f; string Type = "点发射器"; ParticleEmitter *pEmitter = CreateEmitter(Type); AddEmitter(pEmitter); pEmitter->LoadFromFile(".\\Particle.ini","Fire"); }
bool CParticleSystem::OnDependencyListChange( void* pComponentAddr, EDependencyChangeAction actionType, CComponentBase* pComponent) { bool bRet = super::OnDependencyListChange( pComponentAddr, actionType, pComponent ); if ( !bRet ) { if ( &m_emitterVector == pComponentAddr ) { BEATS_ASSERT(dynamic_cast<CParticleEmitter*>(pComponent) != NULL); CParticleEmitter* pEmitter = (CParticleEmitter*)pComponent; if (actionType == eDCA_Add) { AddEmitter( pEmitter ); } else if ( actionType == eDCA_Change || actionType == eDCA_Delete ) { RemoveEmitter( pEmitter ); } bRet = true; } } return bRet; }
result nekoParticleInstance::LoadParticle(const char8 *fileName, bool forUseOnly) { char8 *fileData; TiXmlDocument doc; if(forUseOnly) { if(FAILED(GetNekoNovel()->GetFileSystem()->LoadData( (string("ÆÄƼŬ\\") + fileName).c_str(), &fileData))) return E_NOT_EXIST; doc.Parse(fileData); // ¸Þ¸ð¸® ¾ø¾Ö±â.. delete []fileData; mForUseOnly = true; } else { doc.LoadFile(fileName); } mFileName = fileName; if(doc.Error()) { LogPrint(LOG_LEVEL_WARN, "'%s' ÆÄÀÏÀº XML ±¸¹®ÀÌ À߸øµÇ¾ú½À´Ï´Ù.", fileName); return E_FAIL; } TiXmlElement *root = doc.FirstChildElement("NekoNovel_Particle"); if(!root) { LogPrint(LOG_LEVEL_WARN, "'%s' ÆÄÀÏ¿¡ ÆÄƼŬ Á¤º¸°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.", fileName); return E_FAIL; } Clear(); TiXmlElement *emitter = root->FirstChildElement("Emitter"); TiXmlElement *events; TiXmlElement *event; while(emitter) { nekoParticleEmitter *emt = AddEmitter(emitter->Attribute("Name")); emt->mEmitDelay = atof(emitter->Attribute("EmitDelay")); emt->mMinDir.x = atof(emitter->Attribute("MinDirX")); emt->mMinDir.y = atof(emitter->Attribute("MinDirY")); emt->mMaxDir.x = atof(emitter->Attribute("MaxDirX")); emt->mMaxDir.y = atof(emitter->Attribute("MaxDirY")); emt->mMinScale = atof(emitter->Attribute("MinScale")); emt->mMaxScale = atof(emitter->Attribute("MaxScale")); emt->mMaxCount = atoi(emitter->Attribute("MaxCount")); emt->mLoop = stricmp(emitter->Attribute("Loop"), "true") == 0; emt->mSpawnPos.x = atof(emitter->Attribute("SpawnPosX")); emt->mSpawnPos.y = atof(emitter->Attribute("SpawnPosY")); emt->mSpawnRadius.x = atof(emitter->Attribute("SpawnRadiusX")); emt->mSpawnRadius.y = atof(emitter->Attribute("SpawnRadiusY")); emt->mMinLifeTime = atof(emitter->Attribute("MinLifeTime")); emt->mMaxLifeTime = atof(emitter->Attribute("MaxLifeTime")); if(emitter->Attribute("MinFirstAppearTime")) emt->mMinFirstAppearTime = atof(emitter->Attribute("MinFirstAppearTime")); if(emitter->Attribute("MaxFirstAppearTime")) emt->mMaxFirstAppearTime = atof(emitter->Attribute("MaxFirstAppearTime")); emt->mMinStartColor = _atoi64(emitter->Attribute("MinStartColor")); emt->mMaxStartColor = _atoi64(emitter->Attribute("MaxStartColor")); emt->mMinEndColor = _atoi64(emitter->Attribute("MinEndColor")); emt->mMaxEndColor = _atoi64(emitter->Attribute("MaxEndColor")); emt->mRotation = atof(emitter->Attribute("Rotation")); emt->mRotationSpeed = atof(emitter->Attribute("RotationSpeed")); emt->mScaleSpeed = atof(emitter->Attribute("ScaleSpeed")); emt->mGravity.x = atof(emitter->Attribute("GravityX")); emt->mGravity.y = atof(emitter->Attribute("GravityY")); emt->mSrcBlend = atoi(emitter->Attribute("SrcBlend")); emt->mDestBlend = atoi(emitter->Attribute("DestBlend")); emt->SetTexture(emitter->Attribute("Image")); events = emitter->FirstChildElement("Events"); if(events) { event = events->FirstChildElement("Event"); while(event) { nekoParticleEvent pevt; pevt.mTime = atof(event->Attribute("Time")); pevt.mFlags = atoi(event->Attribute("Flags")); pevt.mMinDir.x = atof(event->Attribute("MinDirX")); pevt.mMinDir.y = atof(event->Attribute("MinDirY")); pevt.mMaxDir.x = atof(event->Attribute("MaxDirX")); pevt.mMaxDir.y = atof(event->Attribute("MaxDirY")); pevt.mGravity.x = atof(event->Attribute("GravityX")); pevt.mGravity.y = atof(event->Attribute("GravityY")); pevt.mRotationSpeed = atof(event->Attribute("RotationSpeed")); pevt.mScaleSpeed = atof(event->Attribute("ScaleSpeed")); pevt.mColor = _atoi64(event->Attribute("Color")); emt->ImportEvent(pevt); event = event->NextSiblingElement("Event"); } } emt->FillNodes(); emitter = emitter->NextSiblingElement("Emitter"); } //LogPrint(LOG_LEVEL_INFO, "ÆÄƼŬ ºÒ·¯¿À±â°¡ ¿Ï·áµÇ¾ú½À´Ï´Ù. '%s'.", fileName); return S_OK; }
// Creates a physics world and lays outt he void LiquidFunScene::LayoutLevel(int level) { // Scale the dimensions of the world to fit the view. const CCSize viewSize = CCDirector::sharedDirector()->getVisibleSize(); const float aspectRatio = viewSize.width / viewSize.height; m_worldExtents.x = k_worldWidth; m_worldExtents.y = k_worldWidth / aspectRatio; m_worldExtentMin = b2Vec2Min(m_worldExtents); m_worldExtentMax = b2Vec2Max(m_worldExtents); m_worldExtentsInWalls = m_worldExtents; m_worldOffsetInWalls.Set(0.0f, 0.0f); // Create a world. m_world = new b2World(k_gravity); m_world->SetParticleRadius(m_worldExtentMin * k_particleSize); m_world->SetParticleDamping(0.2f); // Enable the Box2D rendering layer. Box2DGLESDebugDrawLayer* box2dLayer = new Box2DGLESDebugDrawLayer( m_world, b2Vec2Min(b2Vec2(viewSize.width / m_worldExtents.x, viewSize.height / m_worldExtents.y))); box2dLayer->init(); addChild(box2dLayer); GLESDebugDraw* const debugDraw = box2dLayer->GetGLESDebugDraw(); // Turn off AABB drawing. debugDraw->SetFlags(debugDraw->GetFlags() & ~b2Draw::e_aabbBit); // Render particles as solid circles. debugDraw->SetSolidParticlesEnable(true); // Create boundaries CreateWalls(); CreateBalls(5, 0.075f); CreateBlockOfParticles(); // Define map-specific stuff switch (level) { case 0: { // Add an emitter in the middle static const float k_colorCycleRate = 5.0f; std::vector<b2ParticleColor> colors; colors.push_back(b2ParticleColor(0xff, 0x00, 0x00, 0xff)); colors.push_back(b2ParticleColor(0xff, 0xff, 0xff, 0xff)); colors.push_back(b2ParticleColor(0x00, 0x00, 0xff, 0xff)); colors.push_back(b2ParticleColor(0x00, 0xff, 0x00, 0xff)); colors.push_back(b2ParticleColor(0x22, 0xff, 0x44, 0xff)); AddEmitter(ConvertRelativePositionToWorld(b2Vec2(0.5f, 0.1f)), colors, k_colorCycleRate); // Add a kill field to the bottom right of the screen. b2CircleShape circle; circle.m_radius = m_worldExtentMax * 0.025f; b2Transform circleLocationSize; circleLocationSize.SetIdentity(); circleLocationSize.Set(ConvertRelativePositionToWorld( b2Vec2(0.8f, 0.9f)), 0.0f); AddParticleKillField(circleLocationSize, circle, sizeof(circle)); break; } default: CCLOG("ERROR: Invalid level %d defined.", level); break; } }