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 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
(Release) simpleCgf
(Debug) simpleCgfd
To run the application:
-
Open an command line and switch to the VR-Forces "bin" directory.
-
Start the VR-Forces GUI using the command "vrfLauncher –usePredefinedConnection DIS -F"
-
Open the userData/terrains/Ground-db.mtf terrain database.
-
Start simpleCgf from the command line as "simpleCGFDIS"
The simpleCgf application simulates a tank tasked to move toward a waypoint in the ground-db.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 <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
int main(int argc, char *argv[])
{
DtSimulationAddress simAddress(1, 3001);
#if DtHLA
double rprFomVersion = 1.0;
DtExerciseConn* exerciseConn = new DtExerciseConn(execName, federateName,
new DtRprFomMapper(rprFomVersion));
#else //DIS
int port = 3000;
int exerciseId = 1;
DtExerciseConn* exerciseConn = new DtExerciseConn(port, exerciseId,
simAddress.siteId(), simAddress.applicationId());
#endif
cgf->
newScenario(
"../userData/terrains/Ground-db.mtf");
DtEntityType tankType(1, 1, 225, 1, 1, 3, 0);
DtVector initialPosition(900.0, 900.0, 0.0);
DtReal initialHeading = 0.0;
tankType,
DtForceFriendly,
initialPosition,
initialHeading);
"Alpha");
bool entityCreatedAtRuntime = false;
while (1)
{
if (keyPtr && *keyPtr == 'q')
{
break;
}
DtSleep(0.01);
if (!entityCreatedAtRuntime)
{
initialPosition.setX(300);
cgf->
createEntity(tankType, DtForceFriendly, initialPosition,
initialHeading, DtString::nullString(), false);
entityCreatedAtRuntime = true;
}
}
delete cgf;
delete exerciseConn;
return 0;
}