VR-Vantage 1.4.1 API Class Documentation
exampleDisConnection

This example shows how to create a very simple application that automatically connects to a DIS exercise.

The code fragments are from exampleDisConnection.cxx.

   // Step 1: Create the application instance.

   // A DtVrvApplication wraps up all the components required to build a complete
   // VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
   // DtVrvApplicationConfiguration).
   DtVrvApplication application;

   // Step 2: Initialize the application instance.

   // This causes the plug-in manager to load plug-ins, cause a Display Configuration
   // to be realized, creates the default environment, etc.
   application.initialize(argc, argv);

   //Step 3: Create the DIS driver.
   DtDisDriver* driver = new DtDisDriver(application.de().agentManager(), std::string("MyDisDriver"));

   // Step 4: Create the DIS Connection and add it to the DIS driver.
   DtExerciseConnInitializer exConnInitializer;
   exConnInitializer.setExerciseId(1);
   exConnInitializer.setMulticastTtl(-1);
   exConnInitializer.setPort(3000);
   exConnInitializer.setReceiveBufferSize(1048576);
   exConnInitializer.setSendBufferSize(-1);
   exConnInitializer.setSiteId(2);
   exConnInitializer.setUseAsynchIO(true);
   
   driver->setExerciseSettings(exConnInitializer);

   // Step 5: Add the DIS driver to the display engine.
   // The driver is now owned by the display engine. Do not delete it.
   application.de().driverManager().addDriver(driver);

   // Step 6: Start the driver which listens to the DIS network and creates agents.
   application.de().driverManager().startDriver(driver);

   // Step 7: Creates an event loop and begin running it, causing the creation of frames.
   application.run();

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/exampleDisConnection.exe (on Windows) or ./bin/exampleDisConnection (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleDisConnection.cxx

// /****************************************************************************** 
// ** Copyright (c) 2008 MAK Technologies, Inc. 
// ** All rights reserved. 
// ******************************************************************************/ 
// /****************************************************************************** 
// ** $RCSfile: exampleDisConnection.cxx,v $ $Revision: 1.13 $ $State: Exp $ 
// ******************************************************************************/ 

#include <vrvCore/DtVrvApplication.h>
#include <vrvCore/DtDe.h>
#include <vrvCore/DtAgentManager.h>
#include <vrvCore/DtDriverManager.h>
#include <vrvDis/DtDisDriver.h>
#include <vl/exConnInit.h>

// Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace.
using namespace makVrv;

int main(int argc,char** argv)
{
   // Step 1: Create the application instance.

   // A DtVrvApplication wraps up all the components required to build a complete
   // VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
   // DtVrvApplicationConfiguration).
   DtVrvApplication application;

   // Step 2: Initialize the application instance.

   // This causes the plug-in manager to load plug-ins, cause a Display Configuration
   // to be realized, creates the default environment, etc.
   application.initialize(argc, argv);

   //Step 3: Create the DIS driver.
   DtDisDriver* driver = new DtDisDriver(application.de().agentManager(), std::string("MyDisDriver"));

   // Step 4: Create the DIS Connection and add it to the DIS driver.
   DtExerciseConnInitializer exConnInitializer;
   exConnInitializer.setExerciseId(1);
   exConnInitializer.setMulticastTtl(-1);
   exConnInitializer.setPort(3000);
   exConnInitializer.setReceiveBufferSize(1048576);
   exConnInitializer.setSendBufferSize(-1);
   exConnInitializer.setSiteId(2);
   exConnInitializer.setUseAsynchIO(true);
   
   driver->setExerciseSettings(exConnInitializer);

   // Step 5: Add the DIS driver to the display engine.
   // The driver is now owned by the display engine. Do not delete it.
   application.de().driverManager().addDriver(driver);

   // Step 6: Start the driver which listens to the DIS network and creates agents.
   application.de().driverManager().startDriver(driver);

   // Step 7: Creates an event loop and begin running it, causing the creation of frames.
   application.run();

}


Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)