Moving Space Dust Effect         How to code a particle effect attached to a moving SceneNode, so that the particle effect follows it
Print

This snippet shows how to code a particle effect attached to a moving SceneNode, so that the particle effect follows it.
Perfect for a space dust effect, or for rain.

Captain Nemo:

Here is a snippet from my own code. The particle system is attached to a child scene node of the camera. If a particle is further away from the camera than some specified distance I mirror it along its direction vector to the camera. E.g. if the particle is in front of the camera I position it behind the camera, if it's to the left I position it to the right etc.

This code also changes the size of the particles to avoid them becoming too large if they are close to the camera.

bool XXX::frameStarted(const FrameEvent& evt) 
{  
   const float maxDist  = 250.0; 
   const float mirrorDist = maxDist*0.99; 
   const float dimFactor = 0.8*0.005*0.005;    
   const float maxDist2 = maxDist*maxDist; 
   Camera* cam = mCamera->getCamera(); 
   const Vector3& camPos = cam->getWorldPosition(); 
 
   ParticleIterator pit = mParticleSystem->_getIterator(); 
 
   while (!pit.end()) 
   { 
      Particle* particle = pit.getNext(); 
      Vector3& pos = particle->position; 
      particle->timeToLive = 999999.0f; 
      Vector3 pDir = pos-camPos; 
      float dist = pDir.squaredLength(); 
      float dim = dist*dimFactor; 
      particle->setDimensions(dim, dim); 
 
      if (dist > maxDist2) { 
         pDir.normalise(); 
         Vector3 p = camPos-pDir*mirrorDist;       
         particle->position = p; 
      } 
   }          
 
   return true;    
}

Copied with permission from this topic: http://www.ogre3d.org/phpBB2/viewtopic.php?t=19122(external link)

 


Contributors to this page: jacmoe133512 points  and OgreWikiBot .
Page last modified on Saturday 02 of January, 2010 07:11:19 UTC by jacmoe133512 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.