![]() |
VR-Vantage API Documentation
|
The Distributed Simulation Tutorial takes you step-by-step through the process of creating a simple VR-Vantage plugin that implements a simulation driver.
We will look at using either threaded or non-threaded connections to listen for simulation data, and then according to the data received, adding agents to the scene graph. The first ten projects in this tutorial deal with small parts of this process, and the final project will tie these parts together by listening for data interactions and accordingly making changes to the scene.
Project 1 in the Distributed Simulation tutorial takes a look at how to create a VR-Vantage plugin which instantiates a driver class to interact with the application. The code is minimal, and simple to understand. All subsequent projects will be built using this project as a template.
Creating a VR-Vantage plugin
To create a plugin for VR-Vantage, we will need code that can be called by the Vantage application to initialize the plugin. The initDeModule() function is exported as the point of entry for plugin initialization, and when invoked, is passed a pointer to the display engine (DE). Note that the driver which is to be created by the plugin cannot be correctly instantiated until the display engine (DE) has been initialized. Therefore, the initDeModule() calls a local init() function which registers a callback with the post initialize signal of the display engine. When the display engine emits that signal, the callback disconnects itself from the signal and then instantiates an object of the desired driver class. This object is then added to the driver manager so that it will appear in the list of drivers in the application's Drivers Panel.
The files which define this functionality are as follows:
Creating a custom VR-Vantage driver class
A custom VR-Vantage driver class is derived from the DtDriver class, and is responsible for defining three pure virtual functions: onStart(), onTick(), and onStop(). onStart() is called each time the driver is started in the VR-Vantage application and onStop() is called each time the driver is stopped. onTick() is called after the driver has been started each time the simulation loop gives the driver a chance to do something.
For this project, we have made it so that both onStart() and onStop() print a message to the console window (monitor window) to indicate that they have been called. Whereas these messages are printed on their own separate lines, onTick() prints out only a dot with no newline added. Therefore, a running driver will continually print dots to the console window until the driver has been stopped.
The files which define this functionality are as follows:
The bin directory for the VR-Vantage installation contains both *.bat (for Windows) and *.sh (For Linux) script files which can be used to start the application with the given plugin. Each of these files contains a one-line command, which instantiates the application, and passes it a –plugin option, followed by the path to the plugin library file.
Running either the tutorialDistributedSimulation1d.bat or tutorialDistributedSimulation1.sh script file will start the VR-Vantage Stealth application, passing it the path to the correct plugin library file. For the former script, the file will be examples/plugins/debug/tutorialDistributedSimulation1d.dll, whereas for the latter, the file will be examples/plugins/release/tutorialDistributedSimulation1.so. Note that, for Windows, we are choosing to run the script file with the character 'd' at the end of the name. This will start a debug version which will ensure that the printouts to console will be seen, whereas, to run the release version on Windows will not show these printouts.
Invoke the script file to start the application. Stealth startup will be completed when you see the "Choose a Terrain" dialog window. Follow these instructions to test the plugin:
[Create a Non-Threaded Connection >>]