This example demonstrates how to listen for and display informaiton about environmental process objects (the network representation of control objects and overlay objects in VR-Forces).
Observe the output displaying details about the various control/overlay objects being simulated by VR-Forces.
#include <vl/exerciseConn.h>
#include <matrix/LibMatrix.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlKeyboard.h>
#include <vlutil/vlPrint.h>
#include <iostream>
int keybrdTick(void);
int main()
{
#if DtHLA
double rprFomVersion = 1.0;
DtString fedName(
"VRF-env-process-listen");
DtExerciseConn exConn(execName, fedName, new DtRprFomMapper(rprFomVersion));
#else
int port = 3000;
int exerciseId = 1;
int siteId = 1;
int applicationNum = 25;
DtExerciseConn exConn(port, exerciseId, siteId, applicationNum,
0,
true);
#endif
rel.addControlObjectAdditionCallback(controlObjectAddedCallback, clock);
rel.addControlObjectRemovalCallback(controlObjectRemovedCallback, clock);
int forever = 1;
while (forever)
{
if (keybrdTick() == -1)
break;
clock->setSimTime(clock->elapsedRealTime());
exConn.drainInput();
DtSleep(0.1);
}
return 0;
}
{
if(controlObject && clock)
{
printControlObjectState(controlObject->
cosr(), clock->simTime());
}
}
{
if(controlObject && clock)
{
}
}
{
if(controlObject && clock)
{
printControlObjectState(controlObject->
cosr(), clock->simTime());
}
}
{
DtInfo("************************************************************\n");
DtInfo("*************** Update at %f secs ***************\n", simTime);
DtInfo("************************************************************\n");
DtInfo("environmentalProcessId: %s\n", cosr->environmentalProcessID().string());
DtInfo("globalId: %s\n", cosr->globalId().string());
DtInfo(
"parent: %s\n", cosr->
parent().string());
DtInfo(
"kind: %d\n", cosr->
kind());
DtInfo(
"category: %d\n", cosr->
category());
DtInfo(
"forceType: %d\n", cosr->
forceType());
DtInfo(
"color: %x\n", cosr->
color());
DtInfo("environmentType: %s\n", cosr->environmentType().string());
DtInfo(
"closed figure: %s\n", cosr->
closedFigure() ?
"True" :
"False");
DtInfo(
"projected: %s\n", cosr->
projected() ?
"True" :
"False");
DtInfo(
"bound 2D: %s\n", cosr->
bound2D() ?
"True" :
"False");
DtInfo("model type: %x\n", cosr->modelType());
DtInfo("environmental status: %s\n", cosr->environmentalStatus() ? "Active" : "Inactive");
DtInfo("sequence number: %d\n", cosr->sequenceNumber());
DtInfo("location: %s\n", cosr->location().string().string());
DtInfo("radius: %f\n", cosr->radius());
if(vertexList.size())
{
DtInfo("number of vertices: %d\n", vertexList.size());
DtControlObjectRepository::DtCOVertexList::const_iterator iter = vertexList.begin();
DtControlObjectRepository::DtCOVertexList::const_iterator end = vertexList.end();
int index = 0;
while (iter != end)
{
DtInfo("vertex %d: %s\n", index, (*iter).string().string());
++index;
++iter;
}
}
DtInfo("number of subordinates: %d\n", numSubordinates);
const DtGlobalObjectDesignatorList& subordinates =
int index;
for(index = 0; index < numSubordinates; ++index)
{
bool isValidIndex;
const DtGlobalObjectDesignator& globalId = subordinates.object(index, &isValidIndex);
if(isValidIndex)
{
DtInfo("subordinate %d: %s\n", index, globalId.string());
}
}
int max = cosr->numberOfEnvironmentalRecords();
for (int i = 0; i < max; i++)
{
DtNetEnvironmentalRecord* rec = cosr->recordPointer(i);
int recType = rec->myType;
switch (recType)
{
case DtRectangularVolRecord1Type: DtInfo("%d) DtRectangularVolRecord1Type\n", i); break;
case DtPointRecord1Type: DtInfo("%d) DtPointRecord1Type\n", i); break;
default: DtInfo("%d) UNKNOWN 0x%x\n", i, recType); break;
}
}
DtInfo("\n");
}
int keybrdTick()
{
char *keyPtr = DtPollInputLine();
if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q'))
return -1;
else
return 0;
}