VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleSendControl

This example demonstrates how to use the vrvControlToolkit to send view control messages to an instance of VR-Vantage.

When running this example, type 'w' (and press enter) into the example's console window and it will send a view control message to Vantage telling it to toggle wireframe mode on or off (the first message enables wireframe, further messages toggle). In order for 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.

Building the Example

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

Running the Example

This example is an application. You can run it by running ./bin/exampleSendControl<protocol>.exe (on Windows) or ./bin/exampleSendControl<protocol> (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


sendControl.cxx

/*********************************************************************
** Copyright (c) 2014 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;
}
return 0;
}
int main(int argc, char** argv)
{
//Initial wireframe state
bool wireframeState=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 if (key == 1)
{
//send a wireframe control PDU
wireframeState=!wireframeState;
cmd.myState=wireframeState;
DtDataInteraction data;
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
}
}

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)