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

Table of Contents

This example shows how describes how command-line/MTL parameters could be added to a VR-Link application.

It shows how to specify behavior-specific parameters either by parsing command-line arguments or parsing an MTL file.

Subclassing the VRL Application Initializer

DtLauncherInitializer derives from DtVrlApplicationInitializer and describes how command line/MTL parameters could be added to a VR-Link application. The DtVrlApplicationInitializer contains default behavior for protocol specific parameters, so we can specify behavior particular to the F18 application in the derived DtLauncherInitializer class. Within the new Launcher Initializer class, we add a parseCmdLine() function to handle parsing the command line arguments specified in this class and DtVrlApplicationInitializer. Additionally, we need to register the new variables so they can be parsed correctly when loadMtlFile() is called (defined in DtVrlApplicationInitializer) with an MTL file name. This will parse the MTL file specified and set those variables registered.

How to Run the Example

  1. Launch a simulation viewer such as VR-Vantage or VR-Forces for the protocol of choice. It is recommended to view this using the Ground_DB II.mtf terrain
  2. Launch the launcher example from the VR-Link install's bin64 directory for the same protocol.
  3. In the viewer, notice that the Scud missile launcher launches the missile with the specified parameters.

Example Code

Main Application

/****************************************************************************
* Copyright (c) 1992-2025 MAK Technologies, Inc
* All rights reserved.
****************************************************************************/
#include "launcherInit.h"
#include "missile.h"
#include <vlutil/vlUtil.h>
#include <vl/topoView.h>
int main( int argc, char* argv[] )
{
// Used for error handling
DtINIT_MINIDUMPER( "Launcher" );
DtLauncherInitializer init( argc, argv );
#if DtDIS
// Set the default DIS version
init.setDisVersionToSend( 7 );
#else
// Set the default FED File, executable, and version
init.setFedFileName( DtDefaultRpr2Fom );
#endif
init.parseCmdLine();
DtExerciseConn exConn( init );
//static int stationList[] = {512, 0}; //unused...? remove?
DtEntityType launcherType(1, 1, 225, 28, 2, 2, 2); //M901 Patriot Launcher
DtEntityPublisher launcher(launcherType, &exConn,
DtDrDrmRvw, DtForceOther, launcherType);
DtEntityStateRepository* esr = launcher.esr();
DtTopoView topoView(esr, DtDeg2Rad(init.refLatitude()), DtDeg2Rad(init.refLongitude()));
topoView.setLocation(DtVector(0,0,-32));
topoView.setOrientation(DtTaitBryan(0,0,0));
DtEntityType missileType(2, 1, 225, 1, 16, 2, 0);
esr->attPartList()->getPart(4736).setEntityType(missileType);
Missile* pacMissile = NULL;
DtClock* clock = exConn.clock();
DtTime dt = 0.05;
DtTime simTime = 0;
while(simTime <= init.lifeTime())
{
clock->setSimTime(simTime);
// process incoming data
exConn.drainInput();
if (simTime > init.erectorStartTime() &&
simTime < init.erectorStopTime())
{
esr->setAppearance(6356992); // (0110000100000000);
(float) (0.15 * (simTime - init.erectorStartTime())));
primLauncher.setParameter(DtApElevationRate, (float) 0.15);
}
else
{
primLauncher.setParameter(DtApElevationRate, (float) 0.0);
}
if (simTime > init.missileSwapTime() &&
simTime < (init.missileSwapTime() + .05))
{
if (!pacMissile)
{
pacMissile = new Missile(&exConn, &launcher, init);
}
}
if (simTime > init.fireTime() &&
simTime < (init.fireTime() + 0.05))
{
fire.setAttackerId(launcher.globalId());
// Haven't created the missile yet, so don't know its ID.
fire.setEventId(exConn.nextEventId());
fire.setLocation(esr->location());
fire.setRange(3000);
fire.setQuantity(1);
exConn.sendStamped(fire);
}
if (simTime > init.damageTime())
{
}
launcher.tick();
if (pacMissile)
{
pacMissile->tick(simTime);
}
simTime += dt;
DtSleep(simTime - clock->elapsedRealTime());
}
return 0;
}

Launcher Initializer Header

Launcher Initializer Header

/*******************************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*******************************************************************************/
#ifndef launcherInit_H_
#define launcherInit_H_
{
public:
DtLauncherInitializer(int argc, char* argv[]);
private:
public:
virtual void parseCmdLine();
virtual void setLispFileName(const DtString& name);
virtual DtString lispFileName() const;
virtual double refLatitude() const;
virtual double refLongitude() const;
virtual double lifeTime() const;
virtual double erectorStartTime() const;
virtual double erectorStopTime() const;
virtual double missileSwapTime() const;
virtual double fireTime() const;
virtual double damageTime() const;
virtual double missileMoveTime() const;
virtual double missileStopTime() const;
protected:
virtual void initializeMtlParams();
protected:
double myRefLatitude;
};
#endif

Launcher Initializer Source

/*******************************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*******************************************************************************/
#include "launcherInit.h"
// Constructor -- Initialize the base class (will initialize protocol-specific
// parameters), command line arguments and mtl parameters
DtVrlApplicationInitializer(argc, argv, "VR-Link Launcher"),
myLispFileName(exerciseConnectionConfig()->settings(), "&lispFile", "launcher.mtl", "LISP File Name",
DtBaseConfigVariable::DtScopeCommandLine),
myLifeTime(exerciseConnectionConfig()->settings(), "lifeTime", 120.0, "Life Time",
DtBaseConfigVariable::DtScopeCommandLine),
myErectorStartTime(exerciseConnectionConfig()->settings(), "erectorStartTime", 10.0, "Time To Start Erector",
DtBaseConfigVariable::DtScopeCommandLine),
myErectorStopTime(exerciseConnectionConfig()->settings(), "erectorStopTime", 15.0, "Time To Stop Erector",
DtBaseConfigVariable::DtScopeCommandLine),
myFireTime(exerciseConnectionConfig()->settings(), "fireTime", 23.0, "Time To Fire",
DtBaseConfigVariable::DtScopeCommandLine),
myMissileSwapTime(exerciseConnectionConfig()->settings(), "missileSwapTime", 23.0, "Missile Swap Time",
DtBaseConfigVariable::DtScopeCommandLine),
myMissileMoveTime(exerciseConnectionConfig()->settings(), "missileMoveTime", 23.0, "Missile Move Time",
DtBaseConfigVariable::DtScopeCommandLine),
myMissileStopTime(exerciseConnectionConfig()->settings(), "missileStopTime", 45.0, "Missile Stop Time",
DtBaseConfigVariable::DtScopeCommandLine),
myDamageTime(exerciseConnectionConfig()->settings(), "damageTime", 45.0, "Damage Time",
DtBaseConfigVariable::DtScopeCommandLine),
myRefLatitude(0.0),
myRefLongitude(0.0)
{
}
{
}
// Registers the MTL parameters
{
myMtlEnv->registerVar("refLatitude", &myRefLatitude);
myMtlEnv->registerVar("refLongitude", &myRefLongitude);
}
// Parses the command line
{
// This call will parse the command line and
// set protocol-specific data
// If the "-l" flag was specified load the lisp file
{
myMtlEnv->loadLispFile(const_cast<char *>((myLispFileName.value()).string()), 0);
}
}
//--------------------------------------------------------------
// ACCESSORS/MODIFIERS
// Provide a way to inspect/modify the data
//--------------------------------------------------------------
{
}
{
}
{
return myRefLatitude;
}
{
}
{
return myLifeTime.value();
}
{
}
{
}
{
}
{
return myFireTime.value();
}
{
return myDamageTime.value();
}
{
}
{
}

Defining the Missile

Missile Header

/*********************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*********************************************************************/
#include "launcherInit.h"
#include <vl/topoView.h>
#include <matrix/vlDcm.h>
class Missile
{
public:
const DtLauncherInitializer &init);
virtual ~Missile();
virtual void setPos(DtConstVector vec);
virtual void setVel(DtConstVector32 vec);
virtual void tick(DtTime simTime);
protected:
};

Missile Source

/*********************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
*********************************************************************/
#include "missile.h"
#include <vlutil/vlUtil.h>
#include <mtl/mtl.h>
#include <vl/topoView.h>
const DtLauncherInitializer &init):
myMissileMoveTime(init.missileMoveTime()),
myMissileStopTime(init.missileStopTime()),
initPosition( 0.0, 0.0, 0.0 )
{
DtEntityType patriotMissile(2, 1, 225, 1, 16, 2, 0); //scudType(2,10,119,1,3,0,0);
myPub = new DtEntityPublisher(patriotMissile, conn, DtDrDrmRvw, DtForceOther);
DtArticulatedPart& erector =
initAngles = erector.orientation();
DtDcm erectNeutral2erect;
DtEuler_to_BodyToRef(initAngles, erectNeutral2erect);
DtEuler_to_BodyToRef(initAngles, erector2topo);
DtVector neutralErectorWRTlauncher(-6.64, -0.73, -1.65);
DtVector missileWRTerector(5.21, 0.70, -0.7688);
DtVector missileWRTneutralErector;
DtDcmVecMul(erectNeutral2erect, missileWRTerector,
missileWRTneutralErector);
DtVecAdd(missileWRTneutralErector, neutralErectorWRTlauncher,
initPosition);
initPosition = (missileWRTneutralErector + neutralErectorWRTlauncher);
myTopoView = new DtTopoView(myPub->esr(), DtDeg2Rad(init.refLatitude()), DtDeg2Rad(init.refLongitude()));
myTopoView->setLocation(initPosition);
myTopoView->setOrientation(initAngles);
myPub->tick();
}
{
delete myTopoView;
delete myPub;
}
{
return myPub;
}
{
DtDcmVecMul(erector2topo, vec, velocity);
}
void Missile::tick(DtTime simTime)
{
if (simTime > myMissileMoveTime && simTime < myMissileStopTime)
{
localVel[0] = 10;
myTopoView->setVelocity(velocity);
}
else if (simTime > myMissileStopTime)
{
}
myPub->tick();
}
{
DtVector rotVec;
DtDcmVecMul(erector2topo, vec, rotVec);
}

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)