VR-Vantage
Loading...
Searching...
No Matches
9 - 2D Rendering

VR-Vantage draws 2D content – HUD elements, informational overlays, compass ribbons, map readouts – on top of the 3D scene through a single overlay pipeline.

This chapter documents the low-level primitives that make up an overlay, the higher-level Window Object API that most applications use, and the two composite overlays VR-Vantage ships on top of that foundation.

9.1 - Overlay Primitives

An overlay is a 2D scene that is drawn on top of a 3D scene. The 2D scene can contain any number of the 2D primitives, which include: makVrv::DtLineSegment, makVrv::DtQuad, makVrv::DtFilledPolygon, and makVrv::DtOutlinedPolygon. The class that implements the overlay concept is the makVrv::DtOverlayRenderer. The makVrv::DtOverlayRenderer does the actual drawing of the graphical primitives.

To draw an overlay you must add a makVrv::DtOverlayDrawable to the scene. The makVrv::DtOverlayDrawable is responsible for telling overlays (instances of makVrv::DtOverlayRenderer) to render themselves at the appropriate time.

The makVrv::DtOverlayDrawable is told which makVrv::DtOverlayRenderer it should draw. During the render phase, the makVrv::DtOverlayDrawable tells the makVrv::DtOverlayRenderer to render itself and the graphics primitives are then rendered.

The exampleLogo example shows how to create an overlay.

9.2 - 2D Window Object API

The window object API supports the drawing of multiple 2D graphical objects and text on screen.

The API implements a parenting system similar to a scene graph, and is maintained outside of OSG in vrvCore.

All of the window objects described have agent implementations. exampleWindowObjects and exampleWindowObjectHud show how to use them.

9.2.1 Objects

DtWindowObject - is the base class for all of the following window objects. It has no OSG implementation.

  • DtWindowPolygon
  • DtWindowEllipse
  • DtWindowLine
  • DtWindowText
  • DtWindowTriangleStrip
  • DtWindowTriangleFan
  • DtWindowEllipseGroup
  • DtWindowTriangleGroup
  • DtWindowLineGroup
  • DtWindowSurface - no OSG implementation.
  • DtWindowEntityAttachedSurface - no OSG implementation.

9.2.2 Parenting

A DtWindowObject holds a child list of DtUniqueIDs, all of the above window objects can be attached to each other using addChild. Although DtWindowObject has no OSG implementation, one can be created to hold a number of objects for control through a single object; this is also the concept behind surfaces.

DtWindowObject::needsUpdate processes its own child list, and calls needsUpdate on them. It also gets information from its own parent that it needs to update specific member variables, more on this below.

9.2.3 Surfaces

The concept of surfaces is that 2D objects can be drawn "on" them, when really they inherit from DtWindowObject and behave like any other window object with a few exceptions.

DtWindowSurface defines a section of the screen that window objects can render within. This is done by setting a clipBox that will clip window object vertices that extend past the edges of the box. Clip boxes are defined in normalised screen coordinates on a per channel basis using two coordinates, a bottom left 2D Vector and top right 2D vector (setClipBox method).

Surfaces should be top level objects. In DtWindowObject::needsUpdate an object will get the clipBox information from its parent and set it to its own myClipBox member variable; this way the information is passed down through the hierarchy.

virtual void setSurfaceCoordinateExtents( float minU, float minV, float maxU, float maxV );

The UV coordinates passed into setSurfaceCoordinateExtents allow for a sub coordinate system "on" the surface. For example: the screen is 0.0->1.0, the surface clipbox can be from 0.25->0.75 but you may wish to represent the 0.25->0.75 as 0.0->1.0. The scale and origin or position of the surface uses these values (from the setClipBox method):

scaleX = ( TopRight.x - BottomLeft.x ) / ( MaxU - MinU )
scaleY = ( TopRight.y - BottomLeft.y ) / ( MaxV - MinV )
originX = BottomLeft.x - ( MinU * scaleX)
originY = BottomLeft.x - ( MinV * scaleY)

A DtWindowEntityAttachedSurface allows for surfaces to move around the screen and track an entity's position. A user can set the entity ID on the surface, and the surface will update its own clipBox information in needsUpdate(). As the clip box is constantly updating, the clipbox is specified as a width and height in normalised screen coordinates (setSurfaceWidthHeight). A user can also set offsets from the entity position that are added to the entity position before the position is projected to the screen (setOffsets).

Note that for a DtWindowEntityAttachedSurface a user must set the channel that the surface is to be located by either using - setChannel( DtChannel* channel ) or setChannelOverlay( std::string displayName, std::string windowName, std::string channelName )

9.2.4 Channels

By default all channels are ceated with the "showRemoteGraphics" keyword, any window objects created will be shown on all channels with this keyword. When removing the keyword from channels, is it recommended to save the display settings as a .dcx file, and restart vrVantage.

In order to render specific objects on specific channels, a user must remove this keyword from the channel, and call setChannelOverlay. Note that this does not work for remote displays.

setChannelOverlay only needs to be called on the top level parent object, it will traverse the child list and update their channels too.

9.2.5 Transforms

Each window object has a position, rotation and scale, these are combined into a transform matrix (relative transform) in needsUpdate. If the object has no parent, this transform is set as myWindowTransform, the final transform for the object. If the object has a parent the relative transform matrix is multiplied by the parent objects myWindowTransform, to give its own final window transform.

Non-uniform scales are supported. However, if a user sets a surface as a base level window object, with non-uniform scales, then proceeds to attach children and rotate the child, they will get shear/skewing of the child object. This is a product of parent / child matrice hierarchies. This limitation is expected.

9.2.6 Object Instances

  • DtWindowPolygon - A simple polygon, the polygons OSG instances utilises a DtFilledPolygon or a DtOutlinedPolygon. The filled polygon does not support concave shapes as the methods used for DtWindowPolygon in DtFilledPolygon triangulate from the center of all vertices.

  • DtWindowEllipse - Can draw ellipses / circles in almost any manner. Filled, Outlined, with a start and end angle (in radians), inner and outer dimensions. OSG instance uses DtFilledPolygon and DtSegmentedLine.

  • DtWindowLine - OSG instance uses DtSegmentedLine to render lines, supports a number of stipple patterns.

  • DtWindowText - OSG instance uses a DtTextProxy to render text. Fonts from the "/data/fonts" folder can be set, and alignment of the text. Text objects are clipped as entire objects (top left corner), we do not support individual character clipping.

  • DtWindowTriangleStrip - Renders vertices as a triangle strip primitive, does not support outlining. OSG instance utilises a DtFilledPolygon

  • DtWindowTriangleFan - Renders vertices as a triangle fan primitive, the first vertex passed in is used as the frist vertex for each triangle.

  • DtWindowEllipseGroup, DtWindowTriangleGroup, and DtWindowLineGroup - These objects have thier own OSG instances which hold mutliple DtFilledPolygons and DtSegmentedLines. A user can call addEllipse, addLine, addTriangle or updateEllipse, updateLine, updateTriangle once they have been added. These objects allow the user to control multiple on screen items through one agent or window object, and remove the need for the user to maintain the parenting relationship for grouped objects.

9.3 - Sensor View Overlay

VR-Vantage draws a heads-up-display style overlay on top of any channel configured as a sensor view (a gimbaled sensor payload, an EO/IR camera, a targeting pod). The overlay is composed of independent sections such as a compass ribbon, a reticle, a pitch ladder, and text blocks for platform, target, and display information. Applications that add their own sensor payloads can replace individual sections, add new ones, or start from an empty section list and build the overlay from scratch.

Read this section if you are writing an application or plugin that drives a simulated sensor view and needs to customize what is drawn on top of the sensor image. The overlay is a pure 2D layer built with the primitives described above; nothing here alters the 3D scene.

9.3.1 Core Concepts

  • Sensor view. A channel whose observer is attached to a sensor payload rather than to a free-flying eyepoint. VR-Vantage treats sensor views as ordinary channels; the overlay is what makes them look like a sensor display.
  • Overlay. The composite 2D layer drawn on top of a sensor view. There is one makVrv::DtOsgSensorViewOverlay per sensor view.
  • Overlay section. One logical element of the overlay: compass, reticle, pitch ladder, platform info, and so on. Each section is a subclass of makVrv::DtOsgSensorViewOverlaySection and is responsible for creating its own primitives and updating them each frame.
  • Section creator. A factory object (makVrv::DtOsgSensorViewOverlaySectionCreator) that clones a section when the overlay is instantiated. The overlay creator holds a list of section creators; that list is the entire vocabulary of sections the overlay knows how to build.
  • Field-of-view data. A per-frame state block (makVrv::DtSensorFieldOfViewData) supplied by the application. It carries zoom level, sensor kind, and any other data the sections need to render correctly. The application owns this object and passes it into makVrv::DtOsgSensorViewOverlay::update on every frame.

9.3.2 Class Roles

9.3.3 Default Section Set

Calling makVrv::DtOsgSensorViewOverlayCreator::defaultOverlaySectionCreators returns creators for the seven sections VR-Vantage ships:

Every section is optional. Building the section-creator list yourself gives you an overlay with exactly the sections you want and no others.

9.3.4 Extending the Overlay

To replace or supplement a section, build your own section-creator list and register it with the overlay creator before any sensor view is created. The overlay creator holds the list by value; every new overlay clones its sections from this list.

// Build a list that keeps the default sections but swaps in a custom
// compass, then register it with the display engine.
sectionCreators.push_back(new MyGimbalCompassOverlaySectionCreator);
Responsible for creating new DtOsgSensorViewCrossHairOverlaySections.
Definition DtOsgSensorViewCrossHairOverlaySection.h:67
Responsible for creating new DtOsgSensorViewDisplayInfoOverlaySections.
Definition DtOsgSensorViewDisplayInfoOverlaySection.h:67
static void registerInstance(DtDe &de, DtOsgSensorViewOverlaySectionCreators *sectionCreators=0)
Registers this class to be used as the creator for any DtSensorViewOverlays. Optionally allows a list...
Responsible for creating new DtOsgSensorViewPitchOverlaySections.
Definition DtOsgSensorViewPitchOverlaySection.h:90
Responsible for creating new DtOsgSensorViewPlatformInfoOverlaySections.
Definition DtOsgSensorViewPlatformInfoOverlaySection.h:90
Responsible for creating new DtOsgSensorViewReticleOverlaySections.
Definition DtOsgSensorViewReticleOverlaySection.h:73
Responsible for creating new DtOsgSensorViewTargetInfoOverlaySections.
Definition DtOsgSensorViewTargetInfoOverlaySection.h:85
std::list< DtOsgSensorViewOverlaySectionCreator * > DtOsgSensorViewOverlaySectionCreators
Definition DtOsgSensorViewOverlaySection.h:97

To write a new section, derive from makVrv::DtOsgSensorViewOverlaySection, override update to redraw the section from the supplied makVrv::DtOsgObserverObject and makVrv::DtSensorFieldOfViewData, and publish a unique sectionName so the overlay can look you up later. Pair the section class with a matching subclass of makVrv::DtOsgSensorViewOverlaySectionCreator that returns your section from create.

Because the overlay creator matches sections by unique section name, a custom compass section can adopt makVrv::DtOsgSensorViewCompassOverlaySection::SectionName if it is a drop-in replacement, or a fresh name if it is meant to coexist with the default compass.

9.3.5 Complete Example

The exampleGimbalPlugin example demonstrates the full workflow: registering a custom section-creator list, deriving a DtGimbalCompassOverlaySection that replaces the stock compass, creating the overlay through makVrv::DtSensorViewOverlayCreator, and driving it every frame from a scenario driver. It is the recommended starting point for any custom sensor-view integration.

9.3.6 Related Reference

9.4 - Map Information Overlay

VR-Vantage draws a stacked block of informational text on top of a Plan View channel: map scale, mouse cursor world position, mouse cursor bearing and range from the current bullseye. The block is the map information overlay. Each row is an independent section; toolkit developers can add their own rows, remove built-in ones, or restyle the whole overlay from an authored model definition.

Read this section if you are writing an application or plugin that extends a Plan View with additional readouts, or that customizes the look of the overlay from a model definition.

9.4.1 Core Concepts

  • Channel keyword. A channel becomes eligible for the map information overlay by carrying the string keyword MapInformationOverlay in its channel configuration. VR-Vantage watches for channels tagged with that keyword and constructs a makVrv::DtChannelKeywordMapInformationOverlay to manage each one.
  • Plan View gating. The overlay only appears when the channel's observer is in Plan View (2D projection) mode. Switching an observer back to 3D tears the overlay down; switching back to Plan View rebuilds it.
  • Master vs slave display engine. Channel-keyword objects are created only on the master display engine, but the visualization runs on the display engine that owns the channel. Two objects cooperate: makVrv::DtMapInformationOverlay is a lightweight wrapper that exists on both engines, and makVrv::DtMapInformationOverlayInstance is the visual driver that only builds actual geometry on the local display engine.
  • Section. One row of the overlay. VR-Vantage ships three: map scale, mouse cursor world position, and mouse cursor bearing/range from the bullseye. Sections are keyed by an entry in the makVrv::DtObserverSettingsManager::ObserverSetting enumeration so their visibility can be toggled independently through observer settings.
  • Model definition. Font, colors, margins, and row spacing come from a model definition whose myName is MapInformationOverlay. Model definitions can be authored offline and applied at runtime; section composition remains a programmatic decision.

9.4.2 Class Roles

9.4.3 Wiring and Setup

Nothing special is required to enable the built-in overlay on a standard Plan View: tag the channel with the MapInformationOverlay keyword in the display configuration and put the observer in Plan View. VR-Vantage does the rest.

Section visibility is driven by observer settings. Each built-in section maps to one entry in makVrv::DtObserverSettingsManager::ObserverSetting:

  • ShowMapScale
  • ShowMapMouseCursorToScenePosition
  • ShowMapMouseCursorPositionFromBullseye
  • ShowMapMouseCursorPositionFromBullseyeOnMouseCursor (the last one drives an on-cursor readout rather than a stacked row.)

Toggling the corresponding observer setting shows or hides the row; the overlay instance destroys the section visuals when the setting is off and rebuilds them when it is turned back on.

9.4.4 Model Definition Authoring

Font, colors, background, and layout can be authored by declaring a model definition whose myName is MapInformationOverlay and whose parameters follow the schema shipped in factory/schema/Model Definitions.smtx. The overlay picks up the following parameters:

  • TextColor - text color (RGBA).
  • BackgroundColor - background color of the block (RGBA).
  • TextFontFile - font file relative to data/Fonts.
  • TextFontPointSize - point size for the text.
  • LeftMarginInPixels, RightMarginInPixels, TopMarginInPixels, BottomMarginInPixels - block padding.
  • RowSpacingInPixels - vertical space between rows.

Programmatic setters on makVrv::DtMapInformationOverlayInstance (setFontColor, setBackgroundColor, setFontFile, setFontPointSize) mirror these parameters. Prefer the model definition for anything a scenario or a deployment needs to change without a rebuild; reach for the programmatic API when a runtime event needs to alter the overlay in place.

9.4.5 Adding a Custom Section

Registering a custom section takes two steps. First, derive from makVrv::DtMapInformationSectionOverlay and makVrv::DtMapInformationSectionOverlayCreator. Second, register a modified section-creator map with makVrv::DtMapInformationOverlayInstanceCreator before the first Plan View channel is created.

A new section needs its own entry in makVrv::DtObserverSettingsManager::ObserverSetting so that operator visibility toggles route to it. Values at or above DtObserverSettingsManager::USER_START are reserved for that purpose.

// One-time registration during application startup.
"ShowMyReadout", ShowMyReadout);
// Start from the default section creators, add ours, and register.
creators[static_cast<makVrv::DtObserverSettingsManager::ObserverSetting>(ShowMyReadout)]
= new MyReadoutSectionCreator;
static void defaultOverlaySectionCreators(DtDe &de, DtMapInformationOverlayInstance::DtMapInformationOverlayInstanceSectionCreators &sectionCreators)
Returns the default list of overlay section creators.
static DtMapInformationOverlayInstanceCreator & instance(DtDe &de)
Get the creator instance that is registered with the passed in display engine. If one is not register...
virtual void setOverlaySectionCreators(const DtMapInformationOverlayInstance::DtMapInformationOverlayInstanceSectionCreators &)
Sets a new set of overlay section creators. The old creators will be deleted.
std::map< DtObserverSettingsManager::ObserverSetting, DtMapInformationSectionOverlayCreator * > DtMapInformationOverlayInstanceSectionCreators
Definition DtMapInformationOverlayInstance.h:51
int registerGlobalObserverSetting(const std::string &stringKey, const DtQIconConfigurations &iconConfigurations)
Register a setting as global, and generate an integer key.
ObserverSetting
Definition DtObserverSettingsManager.h:42
@ USER_START
Definition DtObserverSettingsManager.h:86
static DtObserverSettingsManager & instance(DtDe &de)
Get an instance used to emit, or to connect.

Each section is responsible for reporting its own size through getSize; the parent overlay stacks sections and assigns each one a geometry rectangle through setGeometry. makVrv::DtMapScaleSectionOverlay is a small, self-contained reference implementation to study when writing your own.

9.4.6 Ownership and Threading

  • The channel-keyword object owns the wrapper; the wrapper owns the instance. When a channel is destroyed or its keyword is removed, the wrapper is destroyed and the instance is torn down with it.
  • The wrapper exists on every display engine that carries the channel keyword's registration, but the instance only builds visuals on the display engine that actually owns the channel. Code that queries or drives the overlay must be prepared for the case where the instance is null on remote engines.
  • Section-creator registration is a global choice for the display engine. Register once during startup, before any Plan View channel is created; the creator retains the list by value and hands out cloned sections to every subsequent overlay instance.
  • All overlay updates run on the main frame thread; there is no need for external synchronization when calling into the overlay from a driver.

9.4.7 Related Reference