This example creates a new driver.
This driver will load the Makland terrain database and create an F-16 entity on start, attach the main observer to it, and then move the F16 a small amount each time that it's ticked. This example adds a driver via a plugin.
The example driver's onStart() method loads the database first.
DtScene& sceneDriver = myAgentManager.de().scene();
It then creates a new entity facade and tells it to use the f-16_Falcon Visual Definition.
Using the coordinate system information provided by the loaded terrain database, the driver provides an initial position and orientation in the coordinate system of the database.
The current observer is then attached to the newly created entity, and reset to provide a perspective view.
std::vector<DtUniqueID> objects;
The driver manager ticks the example driver by calling its onTick() method. The onTick() method updates the driver's local kinematic member variables and then passes them on to the entity facade.
The driver is stopped by the driver manager callings its onStop() method. This cleans up the entity facade allocated on the heap.
The example driver is created, added to the driver manager, and started in the main program.
{
de.driverManager().addDriver(driver);
de.driverManager().startDriver(driver);
The plugin registers the install function to be called after the DtDe has been initialized.
if (de.isInMasterMode())
{
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin/exampleDriverPlugin_stealth.bat (on Windows) or ./bin/exampleDriverPlugin_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleGLDrawingPlugin.cxx
#ifdef _WIN32
#ifdef EXAMPLEDRIVERPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEDRIVERPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEDRIVERPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEDRIVERPLUGIN
#endif
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEDRIVERPLUGIN
#include <matrix/vlVector.h>
#include <math.h>
#include <boost/bind.hpp>
using namespace makVrv;
{
public:
: makVrv::
DtDriver( am,
"DtExampleDriver" )
, myEntityFacade( 0 )
, myEntityHATLineFacade( 0 )
, myOrbitCenter( 2000.0, 1400.0, 350.0 )
, myAngularVelocity( 0.2 )
, myLastUpdateTime( 0.0 )
, myClockAngle( 0.0 )
, myRadius( 1000.0 )
, myRoll( 0.5 )
{
}
{
if ( myEntityFacade )
delete myEntityFacade;
myEntityFacade = 0;
}
{
}
virtual bool onStart()
{
DtScene& sceneDriver = myAgentManager.de().scene();
std::string maklandPath = myAgentManager.de().dePathConfiguration().userPath();
maklandPath += "//terrains//Makland.mtf";
myAgentManager.de().sharedState().modelSetRealizationManager().modelSetRealizations();
int parentElementId = 0;
DtElementID elementId = myAgentManager.createNewUniqueId();
setsToRealize, false );
if(myEntityFacade->findFacadeFor3d())
{
myEntityFacade->findFacadeFor3d()->setArticulatedModelDefinition("FixedWingF-16UnarmedGrey");
}
if(myEntityFacade->findFacadeForColorized())
{
myEntityFacade->findFacadeForColorized()->setArticulatedModelDefinition("FixedWingAttackNotional");
myEntityFacade->findFacadeForColorized()->setModelScalingEnabled(true);
}
if(myEntityFacade->findFacadeFor2d())
{
myEntityFacade->findFacadeFor2d()->setIconModelDefinition("2525bIcons");
myEntityFacade->findFacadeFor2d()->setFillGlyph(
DtUnicodeChar((
wchar_t)0x0022));
myEntityFacade->findFacadeFor2d()->setOutlineGlyph(
DtUnicodeChar((
wchar_t)0x40C6));
myEntityFacade->findFacadeFor2d()->setDamageGlyph(
DtUnicodeChar((
wchar_t)0x0061));
}
if(myEntityFacade->findFacadeFor3d())
{
myEntityHATLineFacade =
new DtEntityHATLineFacade( myAgentManager, myEntityFacade->findFacadeFor3d()->modelSet(),
myEntityFacade->findFacadeFor3d()->sceneObjectAgent().uniqueId() );
}
myLastUpdateTime = myAgentManager.de().simulationTime();
updatePosition();
{
std::vector<DtUniqueID> objects;
objects.push_back(myEntityFacade->elementId());
}
return true;
}
virtual bool onStop()
{
if ( myEntityFacade )
delete myEntityFacade;
myEntityFacade = 0;
return true;
}
virtual bool onTick()
{
updatePosition();
return true;
}
protected:
virtual void updatePosition()
{
double now = myAgentManager.de().simulationTime();
double dt = now - myLastUpdateTime;
myClockAngle += myAngularVelocity * dt;
DtVector
offset( myRadius*sin(myClockAngle), myRadius*cos(myClockAngle), 0 );
double heading = myClockAngle + M_PI_2;
DtTaitBryan ori( heading, 0, myRoll );
repositionAircraft( myOrbitCenter+
offset, ori );
myLastUpdateTime = now;
}
void repositionAircraft( DtVector position, DtTaitBryan ori )
{
coordConverter = myAgentManager.de().sharedState().coordinateSystem().converter();
{
DtGeodeticCoord geod( DtDeg2Rad( 10.0 ), DtDeg2Rad(60.0), 0.0 );
}
else
{
}
myEntityFacade->setPosition( position );
myEntityFacade->setOrientation( ori );
}
protected:
double myAngularVelocity;
DtVector myOrbitCenter;
double myLastCommLineTime;
double myLastUpdateTime;
double myClockAngle;
double myRadius;
double myRoll;
};
{
}
{
{
}
}
{
return true;
}