Vicuna: New particle system

I just added the basis for the new particle system in Vicuna. The user can tweak properties such as the texture file, acceleration, start and end color, how the particle blend with the scene, if the emitter can die or not and when, the particle’s lifetime, the rate at which particles appear, the speed of the particles, the size of the point sprite, how fast they rotate and the randomness factor of how they change in time. Particles are drawn in batches using pixel shaders which make the system efficient.

Here’s a quick screenshot of the result:

Here’s how easy it is to generate them:

const VCNBool PlayState::InitializeParticles()
{
  VCNNodeCore* nodeCore = VCNNodeCore::GetInstance();
  ParticleSystem* particleSys = nodeCore->CreateNode<ParticleSystem>();
  nodeCore->GetRootNode()->AttachChild( particleSys->GetNodeID() );
 
  // Generate some particle emitters in batches around the map.
  Terrain* mTerrain = WORLD()->GetTerrain();
  const float raddist = 8.0f;
  const float halfSize = mTerrain->GetSize() / 2.0f - 2.0f;
  const int batches = 35;
  for (int i = 0; i < batches; ++i)
  {
    const float spotcenterx = util::Random(-halfSize, halfSize);
    const float spotcentery = util::Random(-halfSize, halfSize);
    for (int j = 0, batchsize = 10 + rand() % 20; j < batchsize; ++j)
    {
      // Generate a random position in the radius of the spot.
      const float x = util::clamp(spotcenterx + util::Random(-raddist, raddist), -halfSize, halfSize);
      const float y = util::clamp(spotcentery + util::Random(-raddist, raddist), -halfSize, halfSize);
      const float h = mTerrain->GetHeightAt(x, y);
 
      FlameNode* flameNode = nodeCore->CreateNode<FlameNode>();
      if ( flameNode )
      {
        flameNode->SetTranslation( Vector3(x, h+0.5f, y) );
        flameNode->CreateEmitter( particleSys->GetManager() );
 
        particleSys->AttachChild( flameNode->GetNodeID() );
      }
    }
  }
 
  return true;
}
This entry was posted in C++, Coding and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *