The Simple CGF example demonstrates the following:
- How to create a CGF
- How to create objects within this CGF
A CGF application differs from the released sim engine in that there is not command line options applied to it and it is intended to be used as part of a larger sim engine application that does not have a need to interface with the VR-Forces GUI.
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:
-
Open a command prompt window and navigate to the VR-Forces /bin64/ directory.
-
Start just the VR-Forces GUI through the Launcher - using the command "vrfLauncher -F"
-
From the Launcher - start VR Forces using the preconfigured DIS (7) connection (rather than "DIS (7) localhost")
-
Do not load an existing or create a new scenario.
-
Open the ($SharedDataDir)/TerrainData/TerrainConfiguration/Ground_DB II.mtf terrain database.
-
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 GUI command line arguments can be copied from the Launcher UI.
-
Join the session if propmpted by the vrfGui depending on application settings for sessions.
-
The simpleCgf application creates a tank tasked to move toward a waypoint in the Ground_DB II.mtf terrain.
-
A tank and waypoint will appear in the display, and the tank will immediately begin moving toward the waypoint.
Main Application File
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#endif
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
using namespace makVrf;
int main(int argc, char *argv[])
{
DtSimulationAddress simAddress(1, 3001);
#if DtDIS
initializer.setDisVersionToSend(7);
#endif
initializer.parseCmdLine();
#if DtDIS
initializer.setSiteId(simAddress.siteId());
initializer.setApplicationNumber(simAddress.applicationId());
initializer.setSuppressSelfReflect(true);
#endif
DtExerciseConn* exerciseConn = new DtExerciseConn(initializer);
DtObjectPublisher::setDfltUpdateRateWarningThreshold(10000);
cgf->
init(communicationManager);
cgf->
newScenario(DtFilename(
"$(SHARED_DATA_DIR)/TerrainData/TerrainConfiguration/Ground_DB II.mtf"),
DtFilename("$(DATA_DIR)/simulationModelSets/EntityLevel.sms"), true, true);
DtEntityType tankType(1, 1, 225, 1, 1, 3, 0);
DtVector initialPosition(133.1, 164.6, 21.3);
DtReal initialHeading = 0.0;
tankType,
DtForceFriendly,
initialPosition,
initialHeading);
DtVector(200.0, 300.0, 18.0),
"Alpha");
bool entityCreatedAtRuntime = false;
while (1)
{
if (keyPtr && *keyPtr == 'q')
{
break;
}
DtSleep(0.01);
if (!entityCreatedAtRuntime)
{
initialPosition.setX(75);
cgf->
createEntity(tankType, DtForceFriendly, initialPosition,
initialHeading, DtString::nullString(), false);
entityCreatedAtRuntime = true;
}
}
delete cgf;
delete communicationManager;
delete exerciseConn;
return 0;
}