VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Simple CGF (simpleCGF)

Table of Contents

The Simple CGF example demonstrates the following:

A CGF application differs from the released back-end in that there is not command line options applied to it and it is intended to be used as part of a larger back-end application that does not have a need to interface with the VR-Forces front-end.

How to Run the Example

This example demonstrates how to create a simple CGF application (outside of the context of the vrfSim application). It shows how to create an embedded CGF in an non-VR-Forces application.

Usage

To run the application:

  1. Open a command prompt window and navigate to the VR-Forces /bin64/ directory.
  2. Start just the VR-Forces vrfGUI (frontend) through the Launcher - using the command "vrfLauncher -F"
  3. From the Launcher - start VR Forces using the preconfigured DIS (7) connection (rather than "DIS (7) localhost")
  4. Do not load an existing or create a new scenario.
  5. Open the userData/terrains/Ground_DB II.mtf terrain database.
  6. Open a separate command prompt window, navigate to the VR-Forces /bin64/ directory and start simpleCgf from the command prompt with the --deviceAddress option as "simpleCGFDIS \--deviceAddress <deviceAddress>" - e.g.:

      simpleCGFDIS.exe --deviceAddress 127.0.0.1
    
      Note:
      The necessary front-end command line arguments can be copied from the Launcher UI.
    

  7. Join the session when propmpted by the vrfGui.
  8. The simpleCgf application creates a tank tasked to move toward a waypoint in the Ground_DB II.mtf terrain.
  9. A tank and waypoint will appear in the display, and the tank will immediately begin moving toward the waypoint.

Main Application File

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//This example demonstrates how to use the DtCgf class to create objects
//and task entities, as you would if you were to embed VR-Forces in your own
//application.
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#endif
//VR-Forces Headers
#include "vrfcgf/cgf.h"
//VR-Link headers
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
// Instead of an exercise connection, the cgf must now be initialized with a communication manager that
// contains the supported network protocols
using namespace makVrf;
int main(int argc, char *argv[])
{
//DIS/RPR simulation address
DtSimulationAddress simAddress(1, 3001);
//Create the CGF
DtCgf* cgf = new DtCgf(simAddress);
// The following is left so the user can see how to piece together a
// simple DIS or HLA exercise connection. Also so you know what execName to
// pass for HLA for the -x command. Use this and you don't need anything else, it will use
// a default fed file of VR-Link.fed(for HLA13) or VR-Link.xml( for HLA1516/1516e) However to make life easier we're also
// going to show you how to use an DtVrlApplicationInitializer so you can parse the command line as well
//Create the exercise connection
/*#if DtHLA
DtString execName = "VR-Link"; //HLA federation execution name
DtString federateName = "simpleCgf"; //HLA federate name
double rprFomVersion = 1.0; //RPR FOM version number
DtExerciseConn* exerciseConn = new DtExerciseConn(execName, federateName,
new DtRprFomMapper(rprFomVersion));
#else //DIS
int port = 3928; //UDP port number
int exerciseId = 1; //DIS exercise ID
DtExerciseConn* exerciseConn = new DtExerciseConn(port, DtInetAddr("127.255.255.255"),exerciseId,
simAddress.siteId(), simAddress.applicationId());
#endif*/
// Use this to parse the command line then pass the initializer to the exercise connection
DtVrlApplicationInitializer initializer(argc, argv, "simpleCgf");
#if DtDIS
initializer.setDisVersionToSend(7);
#endif
initializer.parseCmdLine();
#if DtDIS
initializer.setSiteId(simAddress.siteId());
initializer.setApplicationNumber(simAddress.applicationId());
#endif
DtExerciseConn* exerciseConn = new DtExerciseConn(initializer);
// Turn off warnings for too many PDUs sent in a second as this is expected on terrain that is very hilly or has a lot
// of quick altitude changes
DtObjectPublisher::setDfltUpdateRateWarningThreshold(10000);
communicationManager->addManager(vrliface);
//Initialize the CGF
cgf->init(communicationManager);
//Create the dispatcher so this application can interface with
//front-end
DtCgfDispatcher* cgfDispatcher = new DtCgfDispatcher(cgf,
//Create a new scenario, using the Ground-db.gdb terrain database and the EntityLevel
//simulation model set to allow for entity creation. Also create a global environment and dynamic terrain object
cgf->newScenario(DtFilename("$(SHARED_DATA_DIR)/TerrainData/TerrainConfiguration/Ground_DB II.mtf"),
DtFilename("$(DATA_DIR)/simulationModelSets/EntityLevel.sms"), true, true);
//Tick the cgf to get the terrain loaded
cgf->tick();
//Create a tank
DtEntityType tankType(1, 1, 225, 1, 1, 3, 0);
DtVector initialPosition(133.1, 164.6, 21.3); //Database coordinates, meters
DtReal initialHeading = 0.0; //Heading in radians
//At this point the simulation has not yet been started, so when creating
//entities it's best to call createEntity without specifying the
//"allowBlocking" parameter to allow it default to true. This will insure
//that when using a paging terrain, the necessary pages will immediately
//get paged in.
tankType,
DtForceFriendly,
initialPosition,
initialHeading);
//Create a waypoint named "Alpha"
DtVector(200.0, 300.0, 18.0),
"Alpha");
//Put the simulation engine into run mode. This will tick the nav
// interface to make sure the task below can execute using the nav area
// if it exists in the terrain.
cgf->run();
//Tell the tank to move to waypoint "Alpha"
DtMoveToTask moveToTask;
moveToTask.setControlPoint(alpha->uuid());
cgf->assignTask(tank, moveToTask);
//Used below to insure only one example entity is created at runtime
bool entityCreatedAtRuntime = false;
//Main application loop
while (1)
{
//tick the CGF Dispatcher
cgfDispatcher->tick();
//tick the CGF
cgf->tick();
//Poll & process keyboard input
char *keyPtr = DtGetInputLine();
if (keyPtr && *keyPtr == 'q')
{
break;
}
//Give up the remainder of our time slice.
DtSleep(0.01);
//This is an example of creating an entity at runtime
if (!entityCreatedAtRuntime)
{
//Change the initial position so this entity isn't created on top of
//the first one
initialPosition.setX(75);
//In this case when calling createEntity, the allowBlocking flag must
//be set to false. If the entity being created requires a new tile to
//be swapped in, the simulation can't block while it gets loaded in
//without having a negative effect on the models.
cgf->createEntity(tankType, DtForceFriendly, initialPosition,
initialHeading, DtString::nullString(), false);
//reset the flag so only one entity gets created
entityCreatedAtRuntime = true;
}
}
delete cgf;
delete communicationManager;
delete exerciseConn;
return 0;
}

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)