VR-Link API Documentation for DIS
Embark Example

This example creates an aircraft carrier and an embarked helicopter.

It demonstrates creation of an embarked entity. This example works in DIS and HLA using Version 2.0017 of the RPR FOM. Embarkation is not supported in earlier versions of the RPR FOM.

In this example we create an aircraft carrier located in the Indian Ocean on the Makland Terrain Database. We also create a helicoper and embark it on the deck of the carrier.

To exit, press the 'q' key. This example works with the MAK Stealth and the VR-Forces products.


//********************************************************************
// Copyright (c) 2007 MaK Technologies, Inc.
// All rights reserved.
//********************************************************************
// This example creates an aircraft carrier and an embarked helicopter.
// The example is designed to demonstrate the creation of an embarked
// entity. This example will work in DIS, and HLA using Version 2.0017 of
// the RPR FOM. Embarkation is not supported in earlier versions of the RPR
// FOM.
// The aircraft carrier will sit in the Indian Ocean, and can be viewed from
// the Makland Terrain distributed with the MAK Stealth and VR-Forces.
#include <vl/topoView.h>
// A simple function to test if the user wants to exit.
int keybrdTick()
{
char *keyPtr = DtPollInputLine();
if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q'))
return -1;
else
return 0;
}
int main(int argc, char** argv)
{
try
{
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link Embark");
appInit.parseCmdLine();
DtExerciseConn exConn(appInit);
// Create an aircraft carrier.
DtEntityPublisher carrierPub(
DtCarrier,1,0,0),
#ifdef DtHLA
"Carrier"
#else
DtObjectId(3, 2, 1)
#endif
);
// Set location using geocentric coordinates to Indian Ocean -- This puts
// it off the cost of Makland.
DtTopoView ctv(carrierPub.entityStateRep(),
DtDeg2Rad(10.02175), DtDeg2Rad(60.0161));
ctv.setOrientation(DtTaitBryan(0.0,0.0,0.0));
ctv.setLocation(DtVector(0.0,0.0,0.0));
carrierPub.entityStateRep()->setEntityId("3:2:1");
carrierPub.entityStateRep()->setMarkingText("Carrier");
// Create an entity publisher for the entity we are simulating.
DtUnitedStates, 21, 3, 0, 0),
#ifdef DtHLA
"Helicopter"
#else
DtObjectId(3, 2, 2)
#endif
);
helPub.entityStateRep()->setEntityId("3:2:2");
helPub.entityStateRep()->setMarkingText("Helicopter");
// "Because the IsPartOf and RelativeSpatial attributes are optional, an
// entity that is using them must also continue to send updates for the
// Spatial attribute, with normal world-coordinate spatial information.
// This allows federates that do not subscribe to IsPartOf and RelativeSpatial
// to still be aware of the location of the entity. A federate that is
// subscribed to the IsPartOf and RelativeSpatial attributes can ignore the
// normal Spatial attribute, choosing to compute the entity's world location
// by adding its relative location to the world location of the host entity."
// (From: RPR FOM GRIM 2.0 Draft 17)
DtTopoView htv(helPub.entityStateRep(),
DtDeg2Rad(10.02175), DtDeg2Rad(60.0161));
htv.setOrientation(DtTaitBryan(0.0,0.0,0.0));
htv.setLocation(DtVector(0.0,0.0,-33.0));
// Tell the entity what it is attached to. This relationship is the responsibility of the attached
// entity. No information needs to be set in the host.
helPub.entityStateRep()->setHostGlobalId(carrierPub.globalId());
helPub.entityStateRep()->setRelativeAlgorithm(DtDrStatic);
// set the relative location of the entity. In this case we know we
// are 33 meters up from the location of the AC.
helPub.entityStateRep()->setRelativeLocation(DtVector(0,0,-33.0));
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
// Main loop
DtTime dt = 1.0;
DtTime simTime = 0;
while (!keybrdTick())
{
clock->setSimTime(simTime);
exConn.drainInput();
carrierPub.tick();
helPub.tick();
simTime += dt;
DtSleep(simTime - clock->elapsedRealTime());
}
}
DtCATCH_AND_WARN(std::cout);
return 0;
}


Document ID: Generated on Wed Oct 23 22:25:48 EDT 2013 from SVN revision 132765
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)