![]() |
VR-Vantage 1.4.1 API Class Documentation
|
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.
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.
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.
/********************************************************************* ** Copyright (c) 2010 MaK Technologies, Inc. ** All rights reserved. *********************************************************************/ #include <vl/dataInter.h> #include <vrvControl/DtVrlinkDataInterMarshaller.h> #include <vrvControl/vrvControlToolkitDataTypes.h> #include <vl/exerciseConn.h> #include <vl/exConnInit.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; DtWireframe_v1 cmd; cmd.myState=wireframeState; DtDataInteraction data; DtVrlinkDataInterMarshaller<DtDataInteraction> marshall; 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 } }