![]() |
VR-Link API Documentation for HLA Evolved
|
A simple talk program which uses DDM.
This program only works in HLA and is closely related to the Talk example.
//******************************************************************** // Copyright (c) 2005 MaK Technologies, Inc. // All rights reserved. //******************************************************************** #include <vlpi/appearance.h> #include <vl/exerciseConn.h> #include <vl/exConnInit.h> #include <matrix/geodCoord.h> #include <vl/entityPub.h> #include <vl/entitySR.h> #include <vlpi/EntityTypes.h> #include <vl/geodeticRegion.h> #include <vl/topoView.h> #include <vl/emittrSysPub.h> #include <vl/emitterSysSR.h> #include <vl/radioXmitPub.h> #include <vlutil/vlSmartPointers.h> int keybrdTick() { char *keyPtr = DtPollBlockingInputLine(); if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q')) return -1; else return 0; } int main(int argc, char* argv[]) { DtVrlApplicationInitializer appInit(argc, argv, "VR-Link DDM Talk"); appInit.setExecName("VR-LinkDDM"); #if !DtHLA_1516 appInit.setFedFileName("VR-LinkDDM.fed"); #else #if DtHLA_1516_EVOLVED appInit.setFedFileName("VR-LinkDDM_evolved.xml"); #else appInit.setFedFileName("VR-LinkDDM.xml"); #endif #endif appInit.parseCmdLine(); DtExerciseConn exConn(appInit); // Set use geographic DDM. Entities will automatically be published // in geographic regions sized according to velocity exConn.setUseGeographicDdm(true); exConn.setDdmPlayBoxLowerBound(DtGeodeticCoord(DtDeg2Rad(30.0), DtDeg2Rad(-130.0), 0)); exConn.setDdmPlayBoxUpperBound(DtGeodeticCoord(DtDeg2Rad(40.0), DtDeg2Rad(-120.0), 0)); DtEntityType f18Type(DtPlatform, DtPlatformDomainAir, DtUnitedStates, DtFighter, DtF18, 0, 0); // Create an entity publisher for the entity we are simulating. DtEntityPublisher entityPub(f18Type, &exConn, DtDrDrmRvw, DtForceFriendly, DtEntityPublisher::guiseSameAsType(), "F18 Entity"); DtEntityStateRepository* esr = entityPub.esr(); // Create an emitter system that uses the F18's region DtEmitterSystemPublisher * emitterSys; try { emitterSys = new DtEmitterSystemPublisher(&exConn, 0, &(entityPub.publishingRegions())); } #ifdef DtHLA_1516_EVOLVED catch( rti1516e::Exception& ex ) #elif defined DtHLA_1516 catch( rti1516::Exception& ex ) #elif defined DtHLA catch( RTI::Exception& ex ) #endif { DtInfo << "Exception Caught: Make sure that DDM is enabled.\n"; emitterSys = NULL; return 0; } DtEmitterSystemRepository* emitSR = emitterSys->esr(); emitSR->setEmitterNumber(23); // Create a topographic view on the state repository, so we // can set position information in topographic coordinates. double refLatitude = DtDeg2Rad( 35.699760); double refLongitude = DtDeg2Rad(-121.326577); DtTopoView topoView(esr, refLatitude, refLongitude); // We can use the ESR to set state. esr->setMarkingText("VR-Link"); // Initialize VR-Link time. DtClock* clock = exConn.clock(); DtVector position(0, 0, -100); DtVector velocity(40, 0, 0); // Main loop DtTime dt = 1.0; DtTime simTime = 0; while (1) { // Check if user hit 'q' to quit. if (keybrdTick() == -1) break; // Tell VR-Link the current value of simulation time. clock->setSimTime(simTime); // Process any incoming messages. exConn.drainInput(); // Set the current position information. topoView.setLocation(position); topoView.setVelocity(velocity); // Call tick, which insures that any data that needs to be // updated is sent. entityPub.tick(); emitterSys->tick(); // Set up for next iteration. position[0] += velocity[0] * dt; simTime += dt; // Wait till real time equals simulation time of next step. DtSleep(simTime - clock->elapsedRealTime()); } return 0; }