VR-Vantage
Loading...
Searching...
No Matches
exampleSendControl

Overview

This example demonstrates how to use the vrvControlToolkit to send view control messages to an instance of VR-Vantage. It can send a Wireframe Control message, the LightCommand Control Message, and a custom attach observer to sensor message that the exampleViewControl plugin enables in VR-Vantage.

See also
exampleViewControl

Expected Result

Send Control Result

Example details

When running this example, type 'w' (and press Enter) into the example's console window and it will send a view control message to VR-Vantage telling it to toggle wireframe mode on or off (the first message enables wireframe, further messages toggle). In order for VR-Vantage to listen and respond to the view control messages, make sure "Listen for View Controls" is checked in the connection's configuration page. Typing 'q' will shut down the example.

To test the custom view control packet, type 'l' (and press Enter). If VR-Vantage is running the plug-in created in exampleViewControl, this will toggle the ambient and diffuse settings between different values.

To test the custom attach observer to sensor message, type 'a' (and press Enter). If VR-Vantage is running the plug-in created in exampleViewControl, and there is an entity on the network with a gimbaled sensor, VRV will attach the observer to that sensor. Note that the global entity ID is set in the plugin code for exampleViewControl.

Building the Example

VR-Vantage includes prebuilt versions of the example application. To build it yourself, follow the instructions in Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a VR-Link application, and requires a VR-Link license to run. Start Vantage with the exampleViewControl plugin loaded first, then load a terrain and connect with the protocol you want to test. Then, from the bin/ directory, run one of the launcher scripts for the desired protocol: exampleSendControlDISLocal.bat / exampleSendControlDISLocal.sh (DIS on 127.0.0.1), exampleSendControlHLA1516e.bat / exampleSendControlHLA1516e.sh, or exampleSendControlHLA4.bat / exampleSendControlHLA4.sh, and press 'w' to send a 'toggle to wireframe' message to VR-Vantage or 'l' to toggle between different values for ambient and diffuse lighting. For more information about running examples, please see Running Applications and Examples.

When using HLA1516e, it's important to configure the default connection using the RTI Assistant. In Windows, the RTI Assistant can be found under "MAK Technologies" from the Windows start menu. In Linux, the RTI Assistant can be started using the "./rtiAssitstant -N" script located in the RTI installed location bin folder. Using the RTI Assistant connection preferences tab, set the default connection to be "[machine name]'s predefined rtiexec loopback connection" rather than the default "Predefined lightweight loopback connection".

Configuring the Exercise Connection

The launcher scripts in bin/ pass "--exConnConfigFile ../appData/settings/connections/MAK-ONE-2026-Config.xml" to the example on startup. This XML file is the shared VR-Link exercise-connection configuration used across the MAK ONE product family, so the example joins the same exercise, site, application, federation, and RTI as VR-Vantage, VR-Forces, and VR-Engage by default. To point the example at a different configuration (for example, your own federation), pass "&ndash;exConnConfigFile <path>" on the command line; the option may be repeated and later files override earlier ones in argument order. See 6.2.7 Exercise Connection Configuration for details.

Example Source Files


sendControl.cxx

/*********************************************************************
** Copyright (c) 2024 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
#include <vl/dataInteraction.h>
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <vlutil/vlKeyboard.h>
using namespace vrvControlToolkit;
DtTime dt = 0.05;
int keyTick()
{
char *keyPtr = DtPollBlockingInputLine();
if (keyPtr && (*keyPtr == 'q' || *keyPtr == 'Q'))
{
return -1;
}
if (keyPtr && (*keyPtr == 'w' || *keyPtr == 'W'))
{
return 1;
}
if (keyPtr && (*keyPtr == 'l' || *keyPtr == 'L'))
{
return 2;
}
if( keyPtr && (*keyPtr == 'a' || *keyPtr == 'A') )
{
return 3;
}
return 0;
}
int main(int argc, char** argv)
{
//Initial wireframe state
bool wireframeState = false;
bool lightState = false;
// Initialize the application and connect
DtVrlApplicationInitializer appInit(argc, argv, "sendControl");
appInit.parseCmdLine();
DtExerciseConn exConn(appInit);
exConn.setApplicationId(3, 5);
DtClock* clock = exConn.clock();
DtTime simTime = 0;
while (true)
{
int key = keyTick();
if (key == -1)
{
break;
}
else
{
DtDataInteraction data;
if (key == 1) // 'w' or 'W'
{
//send a wireframe control PDU
wireframeState = !wireframeState;
cmd.myState = wireframeState;
marshall.encode(&cmd, &data);
}
else if (key == 2) // 'l' or 'L'
{
// send a Light Command PDU. This will only be recognized if VR-Vantage is
// using the exampleViewControl plugin which adds support for this packet
lightState = !lightState;
if (lightState)
{
}
else
{
}
marshall.encode(&cmd, &data);
}
else if( key == 3 )
{
#ifdef DtDIS
std::string entity = "1:3001:7"; // Global entity ID
#else
std::string entity = "VRF65537:100";
#endif
strcpy( cmd.myEntity, entity.c_str() );
std::string sensor = "Gimbaled Sensor";
strcpy( cmd.mySensorName, sensor.c_str() );
std::string observer = "Observer 1";
strcpy( cmd.myObserverName, observer.c_str() );
cmd.myCreateOverlay = true;
marshall.encode( &cmd, &data );
}
#ifdef DtDIS
data.setExerciseId(1);
#endif
exConn.send(data);
}
// Tell VR-Link the current value of simulation time.
clock->setSimTime(simTime);
// Process any incoming messages.
exConn.drainInput();
DtTime sleeptime = ( simTime += dt ) - clock->elapsedRealTime();
DtSleep( sleeptime ); // returns immediately if negative
}
return 0;
}
Contains MyControlToolkit control structures and defines.
A 3D Area Stealth Draw Control Object.
Definition DtVrlinkDataInterMarshaller.h:18
Definition MyViewControlDataTypes.h:51
bool myCreateOverlay
Whether or not to create the overlay.
Definition MyViewControlDataTypes.h:65
vrvControlToolkit::DtInt8 mySensorName[vrvControlToolkit::DtVrvControlNameSize]
The name of the sensor gimbal to attach to.
Definition MyViewControlDataTypes.h:59
vrvControlToolkit::DtInt8 myEntity[vrvControlToolkit::DtVrvControlNameSize]
The Global ID of the entity that hosts the sensor.
Definition MyViewControlDataTypes.h:56
vrvControlToolkit::DtInt8 myObserverName[vrvControlToolkit::DtVrvControlNameSize]
The name of the observer.
Definition MyViewControlDataTypes.h:62
Definition MyViewControlDataTypes.h:29
@ AmbientLightScaleSet
Definition MyViewControlDataTypes.h:43
@ DiffuseLightScaleSet
Definition MyViewControlDataTypes.h:42
vrvControlToolkit::DtUInt32 myDiffuseLightScale
Definition MyViewControlDataTypes.h:35
vrvControlToolkit::DtUInt8 myValuesSetFlags
Definition MyViewControlDataTypes.h:47
vrvControlToolkit::DtUInt32 myAmbientLightScale
Definition MyViewControlDataTypes.h:36
Definition vrvControlToolkitDataTypes.h:1197
DtBool myState
Enable or disable wireframe mode.
Definition vrvControlToolkitDataTypes.h:1199
Contains vrvControlToolkit control structures and defines.