![]() |
VR-Link API Documentation for HLA 1516
|
DDM Listen is exactly like Listen , but adds HLA DDM to the mix.
//******************************************************************** // Copyright (c) 2005 MaK Technologies, Inc. // All rights reserved. //******************************************************************** #include <vl/exerciseConn.h> #include <vl/exConnInit.h> #include <matrix/geodCoord.h> #include <vl/entitySR.h> #include <vl/reflEntList.h> #include <vl/reflectedEnt.h> #include <vl/geodeticRegion.h> #include <vl/refEmitLst.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 Listen"); 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); // Switch needs be set in order to pull reflected objects off of the // reflected lists when they go out of scope try { exConn.rtiAmb()->enableAttributeScopeAdvisorySwitch(); } catch( ... ) { DtWarn << "Caught an exception attempting to enable the Attribute Scope Advisory Switch."; DtWarn << " Please make sure Force Full Compliance is turned on." << std::endl; return 0; } // Set playbox (area of interest... used for normalization) exConn.setDdmPlayBoxLowerBound(DtGeodeticCoord(DtDeg2Rad(30.0), DtDeg2Rad(-130.0), 0)); exConn.setDdmPlayBoxUpperBound(DtGeodeticCoord(DtDeg2Rad(40.0), DtDeg2Rad(-120.0), 0)); DtReflectedEntityList* reflEntList = 0; DtReflectedEmitterSystemList* reflEmitList = 0; DtGeodeticRegionSP firstRegion; DtGeodeticRegionSP secondRegion; try { // Smart pointers are used to create/pass around regions, since they can // be created and passed around so much DtDDMRegionSet regions; firstRegion = DtGeodeticRegionSP(new DtGeodeticRegion(&exConn)); secondRegion = DtGeodeticRegionSP(new DtGeodeticRegion(&exConn)); DtDDMRegionSet firstRegionSet; firstRegionSet.insert(firstRegion); // Set region bounds (two identical regions for now) firstRegion->setRegionBounds(DtGeodeticCoord(DtDeg2Rad(35.7), DtDeg2Rad(-122.0), 0), DtGeodeticCoord(DtDeg2Rad(35.7075), DtDeg2Rad(-121.0), 0)); secondRegion->setRegionBounds(DtGeodeticCoord(DtDeg2Rad(35.7), DtDeg2Rad(-122.0), 0), DtGeodeticCoord(DtDeg2Rad(36.0), DtDeg2Rad(-121.0), 0)); // Create an array of regions regions.insert(firstRegion); regions.insert(secondRegion); // Reflected entity list subscribes to both lists reflEntList = new DtReflectedEntityList(&exConn, false, ®ions); // Emitter system only interested in first list reflEmitList = new DtReflectedEmitterSystemList(&exConn, true, &firstRegionSet); } catch (DtException& except) { // If region creation fails, continue, but without regions DtWarn << "Cannot create region: " << except << std::endl; reflEntList = new DtReflectedEntityList(&exConn); reflEmitList = new DtReflectedEmitterSystemList(&exConn); } // if at this point the smart pointers are null // then something happened and we need to exit if( firstRegion == NULL || secondRegion == NULL ) { DtWarn << "Exception occurred: regions were not created, exiting." << std::endl; return 0; } // Let's update the second region secondRegion->setRegionBounds(DtGeodeticCoord(DtDeg2Rad(35.725), DtDeg2Rad(-122.0), 0), DtGeodeticCoord(DtDeg2Rad(36.0), DtDeg2Rad(-121.0), 0)); DtClock* clock = exConn.clock(); // Main loop int forever = 1; while (forever) { // Check if user hit 'q' to quit. if (keybrdTick() == -1) break; // Tell VR-Link the current value of simulation time. clock->setSimTime(clock->elapsedRealTime()); // Process any incoming messages. exConn.drainInput(); DtReflectedEntity* firstEntity = reflEntList->first(); if (firstEntity) { DtGeodeticCoord entLoc; entLoc.setGeocentric(firstEntity->esr()->location()); DtInfo << "Entity in scope. Location: " << DtRad2Deg(entLoc.lat()) << ", " << DtRad2Deg(entLoc.lon()) << std::endl; } DtReflectedEmitterSystem* firstEmitter = reflEmitList->first(); if (firstEmitter) { DtInfo << "Emitter in scope. Emitter number: " << static_cast<int>(firstEmitter->esr()->emitterNumber()) << std::endl; } // Sleep till next iteration. DtSleep(1.0); } delete reflEntList; delete reflEmitList; return 0; }