void ForestWindEmitter::_renderEmitterInfo( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat )
{
   if ( overrideMat )
      return;

   GFXTransformSaver saver;

   GFXDrawUtil *drawer = GFX->getDrawUtil();

   AssertFatal( drawer, "Got NULL GFXDrawUtil!" );

   const Point3F &pos = getPosition();
   const VectorF &windVec = mWind->getDirection();

   GFXStateBlockDesc desc;
   desc.setBlend( true );
   desc.setZReadWrite( true, false );

   // Draw an arrow pointing
   // in the wind direction.
   drawer->drawArrow( desc, pos, pos + (windVec * mWindStrength), ColorI( 0, 0, 255, 255 ) );//Point3F( -235.214, 219.589, 34.0991 ), Point3F( -218.814, 244.731, 37.5587 ), ColorI( 255, 255, 0, 255 ) );//
   drawer->drawArrow( desc, pos, pos + (mWind->getTarget() * mWindStrength ), ColorI( 255, 0, 0, 85 ) );

   
   S32 useRadius = mWindRadius;
   // Draw a 2D circle for the wind radius.
   if ( isRadialEmitter() )
   {
	   //WLE - Vince 
	   //So the problem is that when your inside the sphere it won't render so it might make someone 
	   //think that it's not working right.  So what I did was determine if the camera is inside the sphere.
	   //If the camera is inside the sphere, then I find the distance from the center of the sphere to the camera
	   //Round down and use that as the radius to draw the sphere.
	   //That way if someone zooms in or out, their screen is still showing the sphere.
      GameConnection * gc = GameConnection::getConnectionToServer();
      GameBase* gb = gc->getCameraObject();
       if (gb)
	   {
		  Point3F camPos = gb->getPosition();
		  if ( getPosition().isInsideSphere( camPos, mWindRadius ) )
			  useRadius =  getPosition().distanceTo(camPos);
	   }
      drawer->drawSphere( desc, useRadius, pos, ColorI( 255, 0, 0, 80 ) );
   }
}
void ForestWindEmitter::_renderEmitterInfo( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat )
{
   if ( overrideMat )
      return;

   GFXTransformSaver saver;

   GFXDrawUtil *drawer = GFX->getDrawUtil();

   AssertFatal( drawer, "Got NULL GFXDrawUtil!" );

   const Point3F &pos = getPosition();
   const VectorF &windVec = mWind->getDirection();

   GFXStateBlockDesc desc;
   desc.setBlend( true );
   desc.setZReadWrite( true, false );

   // Draw an arrow pointing
   // in the wind direction.
   drawer->drawArrow( desc, pos, pos + (windVec * mWindStrength), ColorI( 0, 0, 255, 255 ) );//Point3F( -235.214, 219.589, 34.0991 ), Point3F( -218.814, 244.731, 37.5587 ), ColorI( 255, 255, 0, 255 ) );//
   drawer->drawArrow( desc, pos, pos + (mWind->getTarget() * mWindStrength ), ColorI( 255, 0, 0, 85 ) );

   S32 useRadius = mWindRadius;
   // Draw a 2D circle for the wind radius.
   if ( isRadialEmitter() )
   {
      // If the camera is close to the sphere, shrink the sphere so it remains visible.
      GameConnection* gc = GameConnection::getConnectionToServer();
      GameBase* gb;
      if ( gc && (gb = gc->getCameraObject()) )
      {
         F32 camDist = (gb->getPosition() - getPosition()).len();
         if ( camDist < mWindRadius )
            useRadius = camDist;
      }
      drawer->drawSphere( desc, useRadius, pos, ColorI( 255, 0, 0, 80 ) );
   }
}
Beispiel #3
0
void ForestWindMgr::processTick()
{
   const F32 timeDelta = 0.032f;

   if ( mEmitters.empty() )
      return;

   PROFILE_SCOPE(ForestWindMgr_AdvanceTime);

   // Advance all ForestWinds.
   {
      PROFILE_SCOPE(ForestWindMgr_AdvanceTime_ForestWind_ProcessTick);

      ForestWindEmitterList::iterator iter = mEmitters.begin();
      for ( ; iter != mEmitters.end(); iter++ )
      {
         if (  (*iter)->getWind() &&
               (*iter)->isEnabled() )
         {
            (*iter)->updateMountPosition();

            ForestWind *wind = (*iter)->getWind();
            if ( wind )
               wind->processTick();
         }
      }
   }   

   // Assign the new global wind value used by the particle system.
   {
      ForestWindEmitter *pWindEmitter = getGlobalWind();
      if ( pWindEmitter == NULL )      
         ParticleEmitter::setWindVelocity( Point3F::Zero );
      else
      {
         ForestWind *pWind = pWindEmitter->getWind();
         ParticleEmitter::setWindVelocity( pWind->getDirection() * pWind->getStrength() );
      }
   }

   // Get the game connection and camera object
   // in order to retrieve the camera position.
   GameConnection *conn = GameConnection::getConnectionToServer();
   if ( !conn )
      return;

   GameBase *cam = conn->getCameraObject();
   if ( !cam )
      return;   

   const Point3F &camPos = cam->getPosition();

      

   // Gather TreePlacementInfo for trees near the camera.
   {
      PROFILE_SCOPE( ForestWindMgr_AdvanceTime_GatherTreePlacementInfo );
      
      smAdvanceSignal.trigger( camPos, smWindEffectRadius, &mPlacementInfo );
   }

   // Prepare to build a new local source map.
   {
      PROFILE_SCOPE( ForestWindMgr_AdvanceTime_SwapSources );
      AssertFatal( mPrevSources->isEmpty(), "prev sources not empty!" );
      
      swap( mSources, mPrevSources );      

      AssertFatal( mSources->isEmpty(), "swap failed!" );
   }

   // Update wind for each TreePlacementInfo
   {
      PROFILE_SCOPE( ForestWindMgr_AdvanceTime_UpdateWind );

      for( S32 i = 0; i < mPlacementInfo.size(); i++ )
      {
         const TreePlacementInfo &info = mPlacementInfo[i];      
         updateWind( camPos, info, timeDelta );    
      }

      mPlacementInfo.clear();
   }

   // Clean up any accumulators in the
   // previous local source map.
   {
      PROFILE_SCOPE( ForestWindMgr_AdvanceTime_Cleanup );

      IdToWindMap::Iterator sourceIter = mPrevSources->begin();
      for( ; sourceIter != mPrevSources->end(); sourceIter++ )
      {
         ForestWindAccumulator *accum = (*sourceIter).value;

         AssertFatal( accum, "Got null accumulator!" );
         delete accum;
      }

      mPrevSources->clear();
   }
}