VR-Link API Documentation for HLA 1.3
Replace Dead Reckoner Example

At times, users may want to replace the dead reckoner or smoother in reflected objects.

This must be done on a per entity basis, and is best done in the entity addition callback. The following code demonstrates how this may be done

// Required header for all entities
#include <vl/entitySR.h>

// Header files for reflected entities
#include <vl/reflEntList.h>
#include <vl/reflectedEnt.h>

// Header files for dead-reckoner and smoother, so we can 
// create new ones
#include <vlpi/deadReckoner.h>
#include <vlpi/smoother.h>

// Used for DtInfo in this example
#include <vlutil/vlPrint.h>

// STL includes
#include <vector>

// Here is a simple dead-reckoner class
class DtNewDeadReckoner : public DtDeadReckoner
{
public:
   DtNewDeadReckoner() :
      DtDeadReckoner()
   {
      DtInfo << "Created DtNewDeadReckoner" << std::endl;
   }
   
   virtual ~DtNewDeadReckoner() {}
};

// Here is a simple smoother class
class DtNewSmoother : public DtSmoother
{
public:
   DtNewSmoother() :
      DtSmoother()
   {
      DtInfo << "Created DtNewSmoother" << std::endl;
   }
   
   virtual ~DtNewSmoother() {}
};

// It should be noted that the state repository will not take ownership of any
// dead reckoners/smoothers set in it by the user.  This list is used to hold
// all smoothers/dead-reckoners to delete them at the end
std::vector<DtApproximator*> approximators;

// This callback will replace the dead-reckoner and smoother.  Of course, the
// useSmoother() call will simply overwrite the dead-reckoner, but both calls
// are made to demonstrate the API.
void addEntityCallback(DtReflectedEntity* ent, void* usr)
{
   // Replace the dead reckoner.
   DtNewDeadReckoner* newDeadReckoner = new DtNewDeadReckoner;
   ent->esr()->useDeadReckoner(newDeadReckoner);
   approximators.push_back(newDeadReckoner);

   // Replace the smoother.
   DtNewSmoother* newSmoother = new DtNewSmoother;
   ent->esr()->useSmoother(newSmoother);
   approximators.push_back(newSmoother);
}


// This function passes the reflected entity list, on which we will add
// an entity addition callback
void replaceDeadReckonerExample(DtReflectedEntityList *reflEntList)
{
   // Just add an entity addition callback.  The logic is done within
   // the callback.
   reflEntList->addEntityAdditionCallback(addEntityCallback, 0);

   // All entities should now be using the new smoother. At the end of execution,
   // we will delete all pointers created by us.
   for (unsigned int index = 0; index < approximators.size(); ++index)
   {
      DtApproximator* approxToDelete = approximators[index];
      DtDELETE(approxToDelete);
   }
}

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)