当前位置: 首页>>代码示例>>C++>>正文


C++ ParticleEmitter::Update方法代码示例

本文整理汇总了C++中ParticleEmitter::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleEmitter::Update方法的具体用法?C++ ParticleEmitter::Update怎么用?C++ ParticleEmitter::Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParticleEmitter的用法示例。


在下文中一共展示了ParticleEmitter::Update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Resources


//.........这里部分代码省略.........
    dustParticle.minLifetime = 6.f;
    dustParticle.maxLifetime = 10.f;
    dustParticle.minVelocity = glm::vec3(-0.025f, -0.01f, -0.025f);
    dustParticle.maxVelocity = glm::vec3(0.025f, -0.1f, 0.025f);
    dustParticle.minSize = glm::vec2(0.025f, 0.025f);
    dustParticle.maxSize = glm::vec2(0.05f, 0.05f);
    dustParticle.uniformScaling = true;
    dustParticle.color = glm::vec3(0.2f, 1.f, 0.f);
    
    // Particle system.
    particleSystem = new ParticleSystem(dustParticle, 1000);
    
    // Ducks
    duckFile = new VorbisFile("Resources/Audio/Duck.ogg");
    for (int i=0; i<10; i++) {
        ducks.push_back(new Duck(duckFile));
        glm::vec3 position;
        do {
            position = glm::vec3(rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f);
        } while (terrainObject->GetY(position.x, position.z) > water->Position().y - 0.2f);
        ducks[i]->SetPosition(position);
        ducks[i]->SetRotation(rand() / static_cast<float>(RAND_MAX) * 360.f, 0.f, 0.f);
    }
    
    // Lily pads
    for (int i=0; i<50; i++) {
        lilypads.push_back(new LilyPad());
        glm::vec3 position;
        do {
            position = glm::vec3(rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f, water->Position().y + 0.05f, rand() / static_cast<float>(RAND_MAX) * 200.f - 100.f);
        } while (terrainObject->GetY(position.x, position.z) > water->Position().y - 0.2f);
        lilypads[i]->SetPosition(position);
        lilypads[i]->SetRotation(rand() / static_cast<float>(RAND_MAX) * 360.f, 270.f, 0.f);
        lilypads[i]->SetScale(2.f, 2.f, 1.f);
    }
    
    explosionTexture = Resources().CreateTexture2DFromFile("Resources/FireParticle.png");
    
    // Particle type.
    ParticleType explosionParticle;
    explosionParticle.texture = explosionTexture;
    explosionParticle.minLifetime = .1f;
    explosionParticle.maxLifetime = .2f;
    explosionParticle.minVelocity = glm::vec3(-1.f, 1.f, -1.f);
    explosionParticle.maxVelocity = glm::vec3(1.f, -1.f, 1.f);
    explosionParticle.minSize = glm::vec2(0.025f, 0.025f);
    explosionParticle.maxSize = glm::vec2(0.05f, 0.05f);
    explosionParticle.uniformScaling = true;
    explosionParticle.color = glm::vec3(1.f, 0.5f, 0.5f);
    
    // Particle system.
    explosionParticleSystem = new ParticleSystem(explosionParticle, 1000);
    emitterAttached = false;
    
    // Initiate players
    numberOfPlayers = GameSettings::GetInstance().GetLong("Players");
    
    playerIndex = 0;
    glm::vec3 randPos;
    
    for (int i = 0; i < numberOfPlayers; i++){
        do {
			if (i > 0){
				randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
				while (glm::length(playerObjects[i-1].Position() - randPos) > 25.f)
					randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
			} else {
				randPos = glm::vec3(rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f, water->Position().y, rand() / static_cast<float>(RAND_MAX)* 200.f - 100.f);
			}
        } while (terrainObject->GetY(randPos.x, randPos.z) < water->Position().y + 0.2f);
        playerObjects.push_back(PlayerObject{ glm::vec3(randPos.x, terrainObject->GetY(randPos.x, randPos.z) + 0.01f, randPos.z) });
    }
    
    playerIterator = playerObjects.begin();
    
    // Golf ball.
    golfBall = new GolfBall(GolfBall::TWOPIECE, terrainObject, water);
    golfBall->SetPosition(playerObjects[0].Position() + glm::vec3(0.f, golfBall->Radius(), 0.f));
    
    // Camera.
    player = new ThirdPersonPlayer(golfBall);
    player->SetMovementSpeed(2.f);
    wind = glm::vec3(static_cast<float>(rand() % 30 + (-15)), 0.f, static_cast<float>(rand() % 30 + (-15)));
    
    // Emitters.
    ParticleEmitter* emitter = new CuboidParticleEmitter(glm::vec3(0.f, 0.f, 0.f), glm::vec3(40.f, 15.f, 40.f), 0.01, 0.02, true);
    particleSystem->AddParticleEmitter(emitter);
    emitter->Update(5.0, particleSystem, golfBall);
    
    // Sound
    golfHitFile = new VorbisFile("Resources/Audio/GolfBallHit.ogg");
    golfHitBuffer = new SoundBuffer(golfHitFile);
    golfHitSound = new Sound(golfHitBuffer);
    waterFile = new VorbisFile("Resources/Audio/Water.ogg");
    waterBuffer = new SoundBuffer(waterFile);
    waterSound = new Sound(waterBuffer);
    waterSound->SetGain(0.15f);
    waterSound->SetLooping(AL_TRUE);
    waterSound->Play();
}
开发者ID:Chainsawkitten,项目名称:UltimateGolf19XX,代码行数:101,代码来源:TestScene.cpp

示例2: DEBUGMSG

RESULT
ParticleManager::Update( UINT64 elapsedMS )
{
    RESULT rval = S_OK;


    //
    // TODO: if our update frequency is less than 60Hz, we should
    // spread out the emitter updates, rather than updating ALL of them
    // every fourth frame (for example).
    // 
    
    static UINT64 lastUpdateTimeMS = 0;
    if ((elapsedMS - lastUpdateTimeMS) < m_updateIntervalMS)
    {
        return S_OK;
    }
    lastUpdateTimeMS = elapsedMS;


    // Release ParticleEmitters that were marked as done on previous frame.
    ParticleEmitterListIterator ppParticleEmitter;
    for (ppParticleEmitter = m_pendingReleaseParticleEmittersList.begin(); ppParticleEmitter != m_pendingReleaseParticleEmittersList.end(); ++ppParticleEmitter)
    {
        ParticleEmitter* pParticleEmitter = *ppParticleEmitter;
        if (!pParticleEmitter)
            continue;
        
        DEBUGMSG(ZONE_PARTICLES, "Releasing ParticleEmitter [%s], refCount = %d", pParticleEmitter->GetName().c_str(), pParticleEmitter->GetRefCount());
        
        //pParticleEmitter->Stop();
        
        CHR(Release( pParticleEmitter ));
    }
    m_pendingReleaseParticleEmittersList.clear();



    // Update every running ParticleEmitter.
    for (ppParticleEmitter = m_runningParticleEmittersList.begin(); ppParticleEmitter != m_runningParticleEmittersList.end(); /*++ppParticleEmitter*/)
    {
        ParticleEmitter* pParticleEmitter = *ppParticleEmitter;
        if (!pParticleEmitter)
        {
            ppParticleEmitter = m_runningParticleEmittersList.erase( ppParticleEmitter );
            continue;
        } 

//        if (Log::IsZoneEnabled(ZONE_PARTICLES | ZONE_VERBOSE))
//        {
//            char str[1024];
//            sprintf(str, "PE: %s", pParticleEmitter->GetName().c_str());
//            DebugRender.Text(str, Color::White(), 1.0f, 1.0f);
//        }
        
        
        if (FAILED(pParticleEmitter->Update( elapsedMS )))
        {
            pParticleEmitter->Stop();

            //
            // NOTE: if you erase a list member while iterating the list,
            // be sure to properly increment the iterator as seen below.
            //
            ppParticleEmitter = m_runningParticleEmittersList.erase( ppParticleEmitter );
        }
        else 
        {
            ++ppParticleEmitter;
        }
    }

Exit:
    return rval;
}
开发者ID:kabinud,项目名称:HappyGame,代码行数:75,代码来源:ParticleManager.cpp

示例3:

	BOOST_FOREACH(ParticleEmitter& emitter, mParticleEmitters) {
		emitter.Update(time_diff, mPosition, mDirection, !mStopEmitting);
	}
开发者ID:Blarget2,项目名称:gamejam,代码行数:3,代码来源:ParticleSystem.cpp


注:本文中的ParticleEmitter::Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。