![]() |
VR-Forces Developer's Guide
|
This section introduces the layers of the VR-Vantage architecture.
They describe the purpose of each one and how to use the various APIs at each layer to accomplish your visualization goals. We start at the bottom layer (OpenGL) and work our way up to the application layer, illustrating and explaining each through code examples.
The VR-Vantage Toolkit is a multilayered toolkit. VR-Vantage has the following layers:
We will now explore each layer in depth.
At the lowest level, VR-Vantage relies on OpenGL to draw pixels on the screen. It will be rare for a VR-Vantage Toolkit user to have to program at this level however in explaining the various layers in VR-Vantage it helps to start at the bottom.
OpenGL is an industry standard environment for developing 2D and 3D graphics applications. OpenGL is available on many different platforms and is actively supported by the leading graphics vendors. In most cases OpenGL is an API for controlling the functions of a graphics rendering architecture. While this architecture can be implemented using software executed by the CPU, it is more common that dedicated graphics hardware is used to accelerate these functions. VR-Vantage takes advantage of the latest capabilities of modern graphics hardware and they are required by most rendering features. OpenGL is a functional API specification typically used by the C language and languages which can interoperate with C.
We provide some basic OpenGL examples to explore if you wish. Feel free to skip them and go to 2.3 - The OpenSceneGraph Layer.
OpenSceneGraph is a C++ scene graph API built on top of OpenGL. A scene graph is a data structure that represents a scene through connected nodes. OSG follows a number of common patterns for interoperating with the scene. One example is the visitor pattern in which an object is written in a way that allows it to visit each node in a graph and perform an operation such as culling. OSG provides many features that VRVantage can support, including a wide range of file format loaders, particle effects, weather, data management, paging data, and LOD management. If VR-Vantage does not support a particular OSG feature, it can be integrated with minimal effort. OSG provides plug-ins for additional capabilities and file loading. VR-Vantage provides plug-ins for loading MAK GDB files, MAK propriety geometry (MEDF), and imagery (MEIF) files.
The scene graph starts with a top level root node. Beneath the root node, group nodes organize geometry, transforms, and state. The figure below represents an abstract scene graph.
We've provided some simple OSG only examples that will help you learn the OSG Layer API if you need work with the scene graph directly.
| exampleOsgSimple - Shows how to create a simple OpenSceneGraph application that mimics exampleOpenGLSimple by displaying a cube. | |
| exampleOsgTransforms - Shows how to create a simple OpenSceneGraph application that mimics exampleOpenGLTransforms by creating and transforming several geometry objects. | |
| exampleOsgArticulation - Shows how to create a simple OpenSceneGraph application that loads a geometry file from disk, locates degree-of-freedom nodes in the geometry and articulate the geometry with those nodes. |
The classes at Rendering System Layer associate some semantics with the geometry. Instead of just thinking of 3D geometry as generic "nodes", the Toolkit supports application-level concepts like terrain, props, the environment, models, and scene objects. Additionally, the Rendering System Layer contains a DtRenderer that does the actual rendering of pixels to the screen.
The component responsible for drawing 3D images in VR-Vantage is called the DtOsgRenderer and each display engine owns one. The DtOsgRenderer is derived from a DtRenderer which is an abstract base class that provides an interface for updating the scene graph and rendering the scene. Its update() and render() functions are called each display engine tick. The renderer also starts the OSG update traversal for updating all nodes in the scene. After the update traversal is complete, the renderer starts the render traversal, which causes the scene to be rendered on all the available channels.
VR-Vantage organizes the scene graph is a specific way so that things like lighting work properly. The DtOsgRenderer provides access to the various OSG nodes, such as the prop root node, and other nodes where various models are added. There are several "roots" under which to add nodes. These are defined in DtOsgRenderer::RootDomain and examples include Environment, Terrain and Props.
The simplest way to add a model to the scene is to just add nodes as children to one of these roots. In exampleSceneRootPlugin, we load an OpenFlight model and add it to the props root. A prop is a non-moving object in the scene that lives under the environment. Nodes that live under the environment get lit and shadowed.
Many aspects of VR-Vantage are configurable via the GUI, such as the 3D model representation an entity uses. Under the hood the GUI writes out a DtModelDefinition for each piece of content that was specified. The DtModelDefinition contains the details required to draw a model, such as geometry, filename, scale, and texture. During runtime a DtModelInstance is created in a display engine and the DtModelDefinition is realized, causing the content to be added to the scene. See exampleModelInstance to learn how to create a DtOsgSimpleModelInstance and realize a DtModelDefinition to add content to the scene. The DtOsgSimpleModelInstance class will load and display any file format supported by OSG and will automatically cache, accelerate, compress, and instance the rendering resources.
A DtModel is a managing container for a single DtModelInstance, providing more attributes about how the DtModelInstance should be rendered. Initialization of a DtModel starts with giving it a model definition. Unlike the DtModelInstance, which can be handed a model definition identifying the model to load, the DtModel retrieves a model definition which has been pre-loaded into a definition manager. Usually DtModelDefinition objects are automatically loaded from disk to populate the definition manager.
Initializing a DtModel only loads the geometry and prepares it for rendering. The DtModel has to be place in the scene to be rendered. To add the model to the scene, a DtSceneObject is used to manage the model. The DtSceneObject is a container class that 'groups' multiple models into a single scene-object. A scene-object is an association of models that can be manipulated as a single unit. Among other features, the DtSceneObject identifies a single position and attitude within the scene for all models associated with it. As such, models are added to (and removed from) the scene object to be inserted to (and removed from) the scene itself. Once constructed the DtSceneObject can be positioned and oriented within the scene so that any models added to the object will also be positioned and oriented.
To see how a DtModel and DtSceneObject are created and used see exampleSequenceControl. This example also illustrates the use of a DtOsgArticulatedModel and shows how to move the various pieces of an articulated 3D object.
In most cases it is not necessary to add new model classes. The DtOsgSimpleModelInstance class can load and display any file format supported by OSG and will automatically cache, accelerate, compress, and instance the rendering resources. However, if you need custom visualization, it is easy to add new model classes, and add instances that use the model classes to objects in the scene. If you create custom model classes, you use them by creating a schema and model definition for the new model. Then you map it to an entity type for display.
| exampleSceneRootPlugin - Shows how to create a very simple VR-Vantage plugin that adds an OpenSceneGraph model directly to the scene. |
| exampleModelInstance - Shows how to load a Model Instance with a geometry file from disk and add it to a scene root in a DtOsgRenderer. |
| exampleSequenceControl - Shows how to load an articulated Model Instance, add it to a scene-root in a DtOsgRenderer and animate its articulated parts. |
The Control Interface layer provides agents, proxies, and higher-level classes (facades) that allow you to control objects in the Rendering System independently of whether they exist in your application or in a remote display engine. (This allows VR-Vantage applications to support multi-channel distributed rendering). The Rendering System objects act on the commands that they receive from the Control Interface by making changes to the OSG Scene Graph, or by changing other OSG rendering parameters. OSG makes calls to OpenGL, which ensures that the correct scene is rendered by the graphics card.
DtDe, the top-level class, provides access to objects in all of these layers (as well as direct access to OpenSceneGraph!) You can write your application code so that it makes direct calls to the Rendering System (or to OSG). But if you just want to use the built-in capabilities of the VR-Vantage Toolkit (rather than trying to extend the capabilities of the toolkit), we recommend that you stay at the level of the Control Interface rather than going directly to the Rendering System. There are two reasons for this:
The VR-Vantage Toolkit does not group all of the Rendering System classes under a single "Rendering System" object, and all of the Control Interface objects under a "Control Interface" object. Instead, both sets of classes are accessible from DtDe. So it can sometimes be difficult to tell which classes are parts of which layer. For the most part, classes that end in the word "Object" represent scene objects that are part of the Rendering System. Classes that end in the word "Agent" are the agents that are used in the Control Interface to pass commands to their corresponding scene objects. There is usually a one-to-one relationship between scene objects and the agents that command them. For example, a DtObserverObjectAgent is used to control DtObserverObjects in the Rendering System.
Note: Generated agent classes are declared in .hpp files (and defined in .cpp files) to distinguish them from hand-written C++ headers.
However, in many cases, a higher-level class in the Control Interface layer groups together several agents, and provides an interface that allows you to control several different Rendering System objects from a single object (through multiple agents). Two important examples of this are DtScene and DtEntityFacade. They use a variety of agents to control several objects related to terrain, the environment, and moving entity models.
The exampleDriver and exampleDriverPlugin examples use DtScene DtEntity3dFacade and DtEntityFacade to load a terrain database and place a 3D model of an F16 into the world. In general, when you create a particular Control Interface object (for example, DtEntity3dFacade or one of the agents), the corresponding Rendering System objects will be automatically created in all display engines to which you are currently connected (including the one that is local to your application). The only thing that the Control Interface objects need to communicate with the Rendering System is a pointer to an interface object called an Agent Manager. The Agent Manager is created automatically by a DtDe, and is accessible by calling displayEngine->agentManager().
exampleSimpleAgent - Shows how to create an agent for a custom object. | |
| exampleModelArticulationDistributed - Shows how to load a distributed articulation model and move the different parts using an agent. |
| exampleMultipleChannels - A VR-Vantage Renderer example showing how to multiple windows, each with multiple channels rendering a different model-set. |
The Driver layer drives the control interfaces. Drivers take input from the simulation network and/or users and sends instructions to the VR-Vantage Control Interface. The job of a driver is to compose the scene. For example the DIS driver will take data from a distributed simulation and create and maintain agents (part of the control interface layer) to add entities to the scene. The scene driver will create the environment and terrain. And the input driver will take keyboard and mouse input control the observer.
Each driver is designed to be modular and may be user-controllable. Drivers can be added and removed from the display engine once it is initialized. Multiple drivers can be (and typically are) active at the same time.
A driver can be in a stopped state or a running state. Initially a driver is in the stopped state. A stopped driver is functionally inactive. Drivers can be started and stopped any number of times. When a driver is started it creates the resources it will update. While a driver is running, it creates, destroys, and updates these resources. When a driver stops, it must deallocate all allocated resources. It must restore the scene to the state that existed before the driver was started. This capability is used to reload the scene when connecting to display engines.
You can set drivers to automatically start and stop based upon the existence of windows. When a driver is running it is constantly ticked at the rate of the display engine. To ensure good performance, a driver should try to do as little work as possible in its tick() function.
The display engine supports many simultaneous running drivers. The use, configuration, and runtime behavior of drivers is application-specific. Some drivers are built into the display engine, while others are available from other VR-Vantage modules. Two important built-in drivers are the scene driver and the input driver.
The scene driver, DtSceneDriver, is the default logic for the built-in scene logic for the display engine. The scene driver owns a scene (DtScene). It can load and save the scene using the VR-Vantage scene file format. The scene driver is automatically started when the display engine is initialized. It does not perform any actions during tick(). You can extend the scene driver class by replacing the corresponding creator instance. The VR-Vantage Toolkit assumes there is a valid scene driver at all times.
Typically, VR-Vantage applications get their data from networked simulations or hosts. VR-Vantage is designed for this and most of the time the correct place for an agent to get created is in a driver. VR-Vantage includes drivers for HLA 1.3, HLA 1516, HLA Evolved, CIGI, and DIS.
Like the scene driver, the input driver is started automatically when the display engine is initialized. The input driver creates observers as requested, processes mouse events, processes key events using the Key Map Manager, and controls the observer based on the mouse and key events. It also interacts with the Selection Manager (DtSelectionManager) when processing certain mouse events. When the input driver is created, it creates the Key Map Manager. It creates the observer controller and the key and mouse event listener when it starts, and destroys them when it stops.
exampleDistributedDraw- Creates a driver that that controls a distributed draw object. | |
exampleDistributedObject - Creates a distributed object that loads a model and rotates it using an agent. | |
exampleDriver - Creates a driver and uses it to put an entity in the scene. | |
exampleDriverPlugin - Creates a driver and uses it to put an entity in the scene. | |
exampleAccessory - Shows how to create an accessory to extend a driver. | |
exampleCloudDriver - Creates a new driver that demonstrates how to create clouds based on an external data source and how to dynamically move those clouds based on wind. | |
| tutorialDistributedSimulation1 - Multi-part tutorial that creates a simple distributed simulation VR-Vantage plug-in. |
The presence of the GUI in applications based on the DtVrvApplication class is controlled by its configuration's assembleUserInterfaceComponents() member. If you want to run MAK's VR-Vantage applications without the GUI, you can use the –noGui command-line option to set this member in the DtVrvApplicationConfiguration.
The GUI is constructed by the DtQtMenuAssembler, the DtQtToolbarAssembler, and the DtQtPageAssembler. To add or remove GUI elements, register or unregister the appropriate builder with the appropriate assembler.
VR-Vantage's menu system is configured by each application, controlled by the vrvCore module, and implemented in various plug-ins. Menus are derived from DtMenu. The implementation for the menu system is part of the Qt plugin (vrvCoreQt.dll). This plugin defines concrete menus and menu items with Qt-based implementations, such as DtAddFeatureLayerItem.h, and registers their creators with the DtDe. (For details, please see DtMainMenus.h and the various classes implementing DtMenuItem. Each menu and menu item has a unique ID name provided by its constructor, such as DtExamplePage, that is used to identify it.
The menu interface used directly by the DtDe is defined in the vrvCore module by the classes DtMenuAssembler, DtMenuConfiguration, and DtMenuPath. The DtMenuPath class is used to specify the location of a single menu or menu item in terms of its location and the name of the creator that generates its implementation.
DtMenuConfiguration contains a collection of menu paths and provides several methods to conveniently add, access, and modify menu paths. The DtMenuAssembler acts as a sort of menu configuration interpreter. It takes a DtMenuConfiguration and executes the creators necessary to create the menus and menu items. The Qt plugin overrides the default menu assembler to assemble the menus in a Qt-specific fashion. If you want to replace Qt with another GUI toolkit, you will probably need to implement your own DtMenuAssembler as well.
The DtVrvApplication framework class has the functions masterModeMenuConfiguration() and slaveModeMenuConfig(). It uses them to generate the correct menu configuration. The source for MAK's VR-Vantage applications overrides these functions to produce their respective menus. For details, please see the exampleDialogPage example.
Toolbars are assembled similarly to menus. Registered menu item creators can also be used to populate toolbars, and can be specified in toolbar paths. Toolbars can also contain objects derived from DtWidget. Creators for the widgets are registered with the DtQtToolbarAssembler.
Most dialog boxes in VR-Vantage are implemented as pages in a tabbed parent dialog box, called a page collection. Each page derives from DtPage, which is a QWidget. A page is installed into the system by making a creator class for it and registering that creator with the page assembler (please see exampleDialogPage for an example). Once registered, pages can be added to the GUI using the VR-Vantage application's page configuration.
Tabbed dialog boxes that display pages are called page collections. The set of page collections that exists at runtime is determined by the VR-Vantage application's page configuration. (Please see the exampleDialogPage example for an example of adding a new page collection.) Page collections can be configured as either dockable or freefloating dialog boxes.
exampleDialogPage - Shows how to add a page to a dialog box. | |
exampleDisplayUnits - Shows how to use convert values and display them using the application's display units settings. | |
exampleEventProcessor - Create and registers an event processor. | |
exampleExtendDialogByAddition - Shows how to extend an existing dialog box by simply adding a new GUI element to it. Does not follow the humble-dialog pattern. | |
exampleExtendDialogByDerivation - Shows how to extend an existing dialog box (adding more features) through derivation. | |
exampleHumbleDialog - Shows how to create a custom Humble Dialog that is displayed with a custom menu. | |
exampleKeyMap - Registers a function with the Key Map Manager, and binds it to a key event in a given key map. | |
exampleSymbolDecoration - Shows how to add a symbol decoration to a 2D icon. | |
exampleToolbar - Shows how to create a toolbar and add items that are part of the menu bar and items that are not part of the menu bar. | |
| tutorialSymbolFacade1 - Multi-part tutorial that shows how to add symbols and handle symbol events. |
The VR-Vantage Toolkit provides an application framework that makes it easy to create new applications. The high level class DtVrvApplication creates and owns a number of useful subsystems for you. It creates the DtDe, then a DtPluginManager (and loads any available plug-ins), and then initializes the DtDe. It sets up an event loop, and once you call run(), it repeatedly calls DtDe::tick(). To get access to the application's DtDe, simply call DtVrvApplication::de().
| exampleSimple - Creates a simple VR-Vantage application. |
| exampleEmbedded - Builds a QT application with a Master Display Engine embedded in it. |
| exampleEmbeddedSlave - Builds a QT application with a Slave Display Engine embedded in it. |
| exampleMFC - Shows how to embed VR-Vantage in an MFC application. |
This section introduces the layers of the VR-Vantage architecture.
They describe the purpose of each one and how to use the various APIs at each layer to accomplish your visualization goals. We start at the bottom layer (OpenGL) and work our way up to the application layer, illustrating and explaining each through code examples.