VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MC02 Talk-Listen Example

Table of Contents

This is a HLA only example.

MC02 Talk Example

MC02 is an complex DDM extension to RPR which creates all sorts of regions for different types of entities. This is a talk program which uses a subset of the MC02 DDM standard to publish entities in a DDM area related to their force type instead of their geographic location, like the DDMTalk example. This program only works in HLA and is closely related to the Talk example.

MC02 Listen Example

MC02 is a complex DDM extension to RPR which creates all sorts of regions for different types of entities. MC02 Listen is exactly like Listen , but adds HLA MC02 DDM to the mix.

MC02 Talk-Listen Example Code

MC02 Talk Example Code

/****************************************************************************
* Copyright (c) 1992-2025 MAK Technologies, Inc
* All rights reserved.
****************************************************************************/
#include <vl/topoView.h>
#include "mc02Regions.h"
int main( int argc, char* argv[] )
{
// Used for error handling
DtINIT_MINIDUMPER( "MC02-Talk" );
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link MC02 Talk");
appInit.setExecName("VR-LinkMC02");
appInit.setFedFileName("VR-LinkMC02.fed");
//require for mc02 to send messages
appInit.setUseAdvisories(false);
appInit.parseCmdLine();
DtExerciseConn exConn(appInit);
//force ignoreAdvisories
exConn.ignoreAdvisories();
DtEntityPublisher* blueF18 = 0;
DtEntityPublisher* redF18 = 0;
DtDDMRegionSP blueRegion;
DtDDMRegionSP redRegion;
try
{
std::shared_ptr<DtBlueAirRegion> baRegion(new DtBlueAirRegion(&exConn));
blueRegion = baRegion;
baRegion->notifyRtiOfUpdate();
DtDDMRegionSet blueRegSet;
blueRegSet.insert(baRegion);
blueF18 = new DtEntityPublisher(f18Type, &exConn, DtDrDrmRvw, DtForceFriendly,
DtEntityPublisher::guiseSameAsType(), "Blue F18", &blueRegSet);
std::shared_ptr<DtRedAirRegion> raRegion(new DtRedAirRegion(&exConn));
redRegion = raRegion;
raRegion->notifyRtiOfUpdate();
DtDDMRegionSet redRegSet;
redRegSet.insert(raRegion);
redF18 = new DtEntityPublisher(f18Type, &exConn, DtDrDrmRvw, DtForceOpposing,
DtEntityPublisher::guiseSameAsType(), "Red F18", &redRegSet);
}
catch (DtException& regionException)
{
DtWarn << "Caught exception: " << regionException << std::endl;
}
// Hold on to its state repository, where we can set data.
DtEntityStateRepository *blueEsr = blueF18->entityStateRep();
// 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 blueTopoView(blueEsr, refLatitude, refLongitude);
DtTopoView redTopoView(redEsr, refLatitude, refLongitude);
// We can use the ESR to set state.
blueEsr->setMarkingText("Blue");
redEsr->setMarkingText("Red");
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
DtVector bluePosition(0, 0, -100);
DtVector redPosition(20, 0, -100);
DtVector32 velocity(20, 0, 0);
// Main loop
DtTime dt = 0.05;
DtTime simTime = 0;
while (simTime <= 10.0)
{
// Tell VR-Link the current value of simulation time.
clock->setSimTime(simTime);
// Process any incoming messages.
exConn.drainInput();
// Set the current position information.
blueTopoView.setLocation(bluePosition);
redTopoView.setLocation(redPosition);
blueTopoView.setVelocity(velocity);
redTopoView.setVelocity(velocity);
// Call tick, which insures that any data that needs to be
// updated is sent.
blueF18->tick();
redF18->tick();
// Set up for next iteration.
bluePosition[0] += velocity[0] * dt;
redPosition[0] += velocity[0] * dt;
simTime += dt;
// Wait till real time equals simulation time of next step.
DtSleep(simTime - clock->elapsedRealTime());
}
return 0;
}

MC02 Listen Example Code

/****************************************************************************
* Copyright (c) 1992-2025 MAK Technologies, Inc
* All rights reserved.
****************************************************************************/
#include <vl/topoView.h>
#include <iostream>
#include "mc02Regions.h"
int keybrdTick();
int main( int argc, char* argv[] )
{
// Used for error handling
DtINIT_MINIDUMPER( "MC02-Listen" );
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link MC02 Listen");
appInit.setExecName("VR-LinkMC02");
appInit.setFedFileName("VR-LinkMC02.fed");
appInit.parseCmdLine();
DtExerciseConn exConn(appInit);
DtDDMRegionSP blueRegion;
try
{
std::shared_ptr<DtBlueAirRegion> baRegion(new DtBlueAirRegion(&exConn));
baRegion->notifyRtiOfUpdate();
blueRegion = baRegion;
DtDDMRegionSet blueRegSet;
blueRegSet.insert(blueRegion);
rel = new DtReflectedEntityList(&exConn, false, &blueRegSet);
}
catch (DtException& regionException)
{
DtWarn << "Caught exception: " << regionException << std::endl;
return 1;
}
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
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();
// Find the first entity in the reflected entity list.
DtReflectedEntity *first = rel->first();
if (first)
{
// Grab its state repository, where we can inspect its data.
// Create a topographic view on the state repository, so we
// can look at position information in topographic coordinates.
double refLatitude = DtDeg2Rad( 35.699760);
double refLongitude = DtDeg2Rad(-121.326577);
DtTopoView topoView(esr, refLatitude, refLongitude);
// Print the position.
// Since it returns a DtString, we need to force it to const char*
// with a cast.
std::cout << "Position of first entity: "
<< topoView.location().string() << std::endl;
std::cout << "\tName: " << first->globalId() << std::endl;
}
// Sleep till next iteration.
DtSleep(0.1);
}
return 0;
}
int keybrdTick()
{
char *keyPtr = DtPollBlockingInputLine();
if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q'))
return -1;
else
return 0;
}

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)