VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Embark Example

Table of Contents

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 and later. Embarkation is not supported in earlier versions of the RPR FOM.

Creating an Embarked Entity

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.

How to Run the Example

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

Sample Data

Embark Example Code

/****************************************************************************
* Copyright (c) 2017 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>
int main( int argc, char* argv[] )
{
// Used for error handling
DtINIT_MINIDUMPER( "Embark" );
try
{
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link Embark");
#if DtDIS
// Set the default DIS version
appInit.setDisVersionToSend( 7 );
#else
// Set the default FED File, executable, and version
appInit.setFedFileName( DtDefaultRpr2Fom );
appInit.setExecName( "MAK-One-2024" );
appInit.setRprFomVersion( 2.0 );
appInit.setRprFomRevision( 1 );
#endif
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 (input.keybrdTick() != -1)
{
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 Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)