Game Development Community

dev|Pro Game Development Curriculum

Fix for projectile splash when no emitter trails are defined

by Josh Moore · 09/30/2004 (7:47 pm) · 3 comments

In projectile.cc find this section of code:

else if (!fromWater && toWater && bool(mParticleEmitter) && bool(mParticleWaterEmitter))     // entering water
   {
      // cast the ray to get the surface point of the water
      RayInfo rInfo;
      if (gClientContainer.castRay(from, to, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

            // create an emitter for the particles out of water and the particles in water
            mParticleEmitter->emitParticles(from, rInfo.point, axis, vel, ms);
            mParticleWaterEmitter->emitParticles(rInfo.point, to, axis, vel, ms);
      }
   }
   else if (fromWater && !toWater && bool(mParticleEmitter) && bool(mParticleWaterEmitter))     // leaving water
   {
      // cast the ray in the opposite direction since that point is out of the water, otherwise
      //  we hit water immediately and wont get the appropriate surface point
      RayInfo rInfo;
      if (gClientContainer.castRay(to, from, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

            // create an emitter for the particles out of water and the particles in water
            mParticleEmitter->emitParticles(rInfo.point, to, axis, vel, ms);
            mParticleWaterEmitter->emitParticles(from, rInfo.point, axis, vel, ms);
      }
   }

and replace it with this:

else if (!fromWater && toWater )//&& bool(mParticleEmitter) && bool(mParticleWaterEmitter))     // entering water
   {
      // cast the ray to get the surface point of the water
      RayInfo rInfo;
      if (gClientContainer.castRay(from, to, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

         if(bool(mParticleEmitter) && bool(mParticleWaterEmitter))
         {
            // create an emitter for the particles out of water and the particles in water
            mParticleEmitter->emitParticles(from, rInfo.point, axis, vel, ms);
            mParticleWaterEmitter->emitParticles(rInfo.point, to, axis, vel, ms);
         }
      }
   }
   else if (fromWater && !toWater )//&& bool(mParticleEmitter) && bool(mParticleWaterEmitter))     // leaving water
   {
      // cast the ray in the opposite direction since that point is out of the water, otherwise
      //  we hit water immediately and wont get the appropriate surface point
      RayInfo rInfo;
      if (gClientContainer.castRay(to, from, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

         if(bool(mParticleEmitter) && bool(mParticleWaterEmitter))
         {
            // create an emitter for the particles out of water and the particles in water
            mParticleEmitter->emitParticles(rInfo.point, to, axis, vel, ms);
            mParticleWaterEmitter->emitParticles(from, rInfo.point, axis, vel, ms);
         }
      }
   }

#1
10/02/2004 (3:27 pm)
Cha Ching.... worked like a charm! Only one little issue - the word wrap on the code gave me some trouble. As soon as I figure out what text was on the wrong line, it splashed just like it was supposed to. I think this should be incorporated into the HEAD.

Thanks, Joe
#2
10/19/2006 (11:45 am)
Really useful resource :-)

Thanks...
#3
12/24/2007 (12:44 am)
Any resource that fixes what's broken gets a 5 in my book :)