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

Talk is a simple listen-only VR-Link application which has been extended to take advantage of HLA Evolved Specific functionality.

There is virtually no difference between this and the regular talk example, as the HLA Evolved features are provided automatically by VR-Link. The ListenEvolved example takes advantage of these features to provide more information.


/****************************************************************************
* Copyright (c) 2017 VT MAK
* All rights reserved.
****************************************************************************/
#include <vl/topoView.h>
#include <iostream>
int main(int argc, char** argv)
{
try
{
// Create a connection to the exercise or federation execution.
DtVrlApplicationInitializer appInit( argc, argv, "VR-Link Talk" );
// HLA Evolved has both a federate name, which must be unique, and a
// federate type, which does not have to be.
appInit.setFederateType( "Talk Evolved Example" );
// Set the default FED File, executable, and version
appInit.setFedFileName( DtDefaultRpr2Fom );
appInit.setExecName( "MAK-RPR-2.0" );
appInit.setRprFomVersion( 2.0 );
appInit.setRprFomRevision( 1 );
// Process the command line. This will actually set values in the
// DtVrlApplicationInitializer class and should be called before
// creating the DtExerciseConn instance.
appInit.parseCmdLine();
// The DtExerciseConn instance is perhaps the most important class
// in any VR-Link exercise. Think of it as the hub which holds
// everything else together. Technically this instance is what's
// responsible for connecting this federate to another federate via
// a network, or an RTI. After exConn is created, and if no error
// has occurred this simulator will be a live federate.
DtExerciseConn exConn(appInit);
// Create an entity publisher for the entity we are simulating.
DtEntityPublisher entityPub(f18Type, &exConn,
// Hold on to the entity's state repository, where we can set data.
// 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");
topoView.setOrientation(DtTaitBryan(0.0, 0.0, 0.0));
// Initialize VR-Link time.
DtClock* clock = exConn.clock();
DtVector position(0, 0, -100);
DtVector32 velocity(20, 0, 0);
// Send a Fire Interaction.
fire.setAttackerId(entityPub.globalId());
exConn.sendStamped(fire);
// 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.
topoView.setLocation(position);
topoView.setVelocity(velocity);
// Call tick, which insures that any data that needs to be
// updated is sent.
entityPub.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());
}
}
DtCATCH_AND_WARN(std::cout);
return 0;
}

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)