VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Replace Dead Reckoner Example

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

The following code demonstrates how this may be done

// Required header for all entities
// Header files for reflected entities
// Header files for dead-reckoner and smoother, so we can
// create new ones
// 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() :
{
DtInfo << "Created DtNewDeadReckoner" << std::endl;
}
virtual ~DtNewDeadReckoner() {}
};
// Here is a simple smoother class
class DtNewSmoother : public DtTrigonometricSmoother
{
public:
DtNewSmoother() :
{
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)
{
// Dead Reckoners can be replaced globally. You no longer need
// to replace each dead reckoner individually
DtNewDeadReckoner* newDeadReckoner = new DtNewDeadReckoner;
DtNewSmoother* newSmoother = new DtNewSmoother;
DtDELETE(newDeadReckoner);
DtDELETE(newSmoother);
// Just add an entity addition callback. This callback shows
// how you can replace a single dead reckoner. However, because we are
// changing it globally we do not need to do this so it is commented out.
// 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 Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (www.mak.com)