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.
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 F16 Visual Definition.
myEntityDisplayName = "Entity From Facade";
DtElementID elementId = myAgentManager.createNewUniqueId();
myEntityFacade = new DtEntity3dFacade( myAgentManager, elementId, true );
reportElementCreated( elementId, parentElementId, DtElementEntry::Entity );
myEntityFacade->setArticulatedModelDefinition("FixedWingF-16UnarmedGrey");
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.
As labels are pinned or unpinned, the togglePinnedLabel slot is called. This slot updates the visibility of both the indicator and the info label, and also tells the driver to listen or stop listening to the mouse hover signals (detailed below).
std::vector<DtUniqueID> objects;
objects.push_back( myEntityFacade->elementId() );
DtObserver* currentObserver =
myAgentManager.de().driverManager().inputDriver().currentObserver();
currentObserver->setPrimaryAttachment( objects );
The driver manager updates the example driver by calling its onTick() method. The driver's onTick() method updates the F16's position using updatePosition(), and updates the text displayed on the F16's entity info label.
updatePosition();
{
std::vector<DtUniqueID> objects;
objects.push_back( myEntityFacade->elementId() );
DtObserver* currentObserver =
myAgentManager.de().driverManager().inputDriver().currentObserver();
currentObserver->setPrimaryAttachment( objects );
}
if ( line3D )
{
std::vector<double> segments;
segments.push_back(1.0);
}
return true;
}
{
{
{
}
{
}
myEntityFacade = 0;
}
return true;
}
{
{
}
return true;
}
{
}
const DtSelectionManager::IdSet& sel )
{
DtSelectionManager::IdSet::const_iterator i = sel.begin();
DtSelectionManager::IdSet::const_iterator e = sel.end();
for ( ; i != e; ++i )
{
{
}
}
}
{
DtWidgetSignaler& widgetSignaler =
widgetSignaler );
if ( active )
{
signals.signal_mouseLeave.connect( boost::bind(
}
else
{
signals.signal_mouseEnter.disconnect( boost::bind(
signals.signal_mouseLeave.disconnect( boost::bind(
}
}
{
{
DtOverlayGroupManager& groupManager =
DtStateVisualizer::EntityVisualizerType );
}
{
}
}
{
DtReferenceEllipsoid refEllip( DtWGS84 );
DtGeodeticCoord geod( &refEllip );
DtVector localp;
DtTaitBryan hpr;
const DtCoordinateSystem& coordSys =
const char* entityFormatString =
"Marking :%s\n"
"Heading :%.2f Deg\n"
"Lat|Lon :%.2fN %.fE\n"
"Alt. :%.1f m above sea level";
std::string buffer;
buffer.resize( 1024, '0' );
{
int charsWritten = sprintf(
const_cast<char*>(buffer.c_str()), entityFormatString,
DtRad2Deg(geod.lat()),
DtRad2Deg(geod.lon()),
);
buffer.resize(charsWritten,'0');
}
return DtUnicode::fromUtf8(buffer);
}
{
myLastUpdateTime = now;
}
{
DtCoordinateConverter* coordConverter;
if ( coordConverter->type() == DtCoordinateConverter::Geocentric )
{
DtGeodeticCoord geod( DtDeg2Rad( 10.0 ), DtDeg2Rad(60.0), 0.0 );
coordConverter->setupTopoFrame( geod.geocentric() );
}
else
{
coordConverter->setupTopoFrame( position );
}
coordConverter->enuToCig_coordTrans( position,
myPosition );
The driver's generateInfoString() method essentially performs some formatting and unit conversion on the information it has about the aircraft's position and orientation in the scene. The value returned from this method is then simply set on the entity info widget (if there is one present - if the mouse isn't hovering, there won't be an info widget).
The driver's updatePosition() method first determines how long it's been since the last update, and updates the aircraft's clock angle based on its angular velocity. The clock angle is the bearing to the aircraft from the point at the center of the aircraft's orbit (0 for north, and increasing in the clockwise direction). It then determines the aircraft's offset from the center of its orbit.
The aircraft's orbit is circular, so computing the heading is as easy as adding 90 degrees (Pi/2) to the clock angle. Once this has been done, the heading and roll can be used to determine the net orientation of the F16.
Now that the F16's position and orientation have been computed, the aircraft can be repositioned in the scene. Finally, the current time is set as the last update time in preparation for the next update.
Positioning the aircraft takes place in the repositionAircraft(..) method. This method first determines the type of coordinate system using the DtCoordinateConverter, then converts the position and orientation to local database (CIG) coordinates. Finally, the CIG coordinates are set on the entity facade, performing the actual reposition.
The driver is stopped by the driver manager callings its onStop() method. This cleans up the entity facade allocated on the heap.
if ( myEntityFacade )
{
if ( myEntityInfoWidget )
{
myEntityFacade->sceneObjectAgent().removeModel(
myEntityInfoWidget->model() );
delete myEntityInfoWidget;
myEntityInfoWidget;
}
if ( myEntityIndicator )
{
setHoverSignalsActive( false );
myEntityFacade->sceneObjectAgent().removeModel(
myEntityIndicator->model() );
delete myEntityIndicator;
myEntityIndicator = 0;
}
reportElementDestroyed( myEntityFacade->elementId() );
delete myEntityFacade;
myEntityFacade = 0;
}
return true;
The example driver is created, added to the driver manager, and started in the main program.
Building the Example
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is an application. You can run it by running ./bin/exampleDistributedObject.exe (on Windows) or ./bin/exampleDistributedObject (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleDriver.cxx
int main( int argc, char* argv[] )
{
}
DtExampleDriver.h
#pragma once
#include <matrix/vlTaitBryan.h>
#include <matrix/vlVector.h>
#include <string>
namespace makVrv
{
class DtEntity3dFacade;
}
{
public:
virtual const std::string&
className()
const;
protected:
protected:
};
DtExampleDriver.cxx
using namespace makVrv;
: makVrv::
DtDriver( am,
"DtExampleDriver" )
, myEntityFacade( 0 )
, myEntityIndicator( 0 )
, myEntityInfoWidget( 0 )
, myEntityDisplayName( "" )
, myEntityInfoWidgetPinnedFlag( false )
, myPosition()
, myOrientation()
, myOrbitCenter( 2000.0, 1400.0, 350.0 )
, myAngularVelocity( 0.2 )
, myLastUpdateTime( 0.0 )
, myClockAngle( 0.0 )
, myHeading( 0.0 )
, myRadius( 1000.0 )
, myRoll( 0.5 )
{
}
{
}
{
static std::string name = "DtExampleDriver";
return name;
}
{
maklandPath += "/terrains/MaklandNoSpeedtrees.mtf";
DtStateVisualizer::EntityVisualizerType );
selMgr.signal_entityInfoToggled.connect( boost::bind(
{
std::vector<DtUniqueID> objects;
}
if ( line3D )
{
std::vector<double> segments;
segments.push_back(1.0);
}
return true;
}
{
{
{
}
{
}
myEntityFacade = 0;
}
return true;
}
{
{
}
return true;
}
{
}
{
DtSelectionManager::IdSet::const_iterator i = sel.begin();
DtSelectionManager::IdSet::const_iterator e = sel.end();
for ( ; i != e; ++i )
{
{
}
}
}
{
widgetSignaler );
if ( active )
{
signals.signal_mouseLeave.connect( boost::bind(
}
else
{
signals.signal_mouseEnter.disconnect( boost::bind(
signals.signal_mouseLeave.disconnect( boost::bind(
}
}
{
{
DtStateVisualizer::EntityVisualizerType );
}
{
}
}
{
DtReferenceEllipsoid refEllip( DtWGS84 );
DtGeodeticCoord geod( &refEllip );
DtVector localp;
DtTaitBryan hpr;
const char* entityFormatString =
"Marking :%s\n"
"Heading :%.2f Deg\n"
"Lat|Lon :%.2fN %.fE\n"
"Alt. :%.1f m above sea level";
std::string buffer;
buffer.resize( 1024, '0' );
{
int charsWritten = sprintf(
const_cast<char*>(buffer.c_str()), entityFormatString,
DtRad2Deg(geod.lat()),
DtRad2Deg(geod.lon()),
);
buffer.resize(charsWritten,'0');
}
return DtUnicode::fromUtf8(buffer);
}
{
myLastUpdateTime = now;
}
{
if ( coordConverter->
type() == DtCoordinateConverter::Geocentric )
{
DtGeodeticCoord geod( DtDeg2Rad( 10.0 ), DtDeg2Rad(60.0), 0.0 );
}
else
{
}
}