Overview
Shows how to create and manipulate DtWindowObjects in VR-Vantage.
Example details
The VR-Vantage Control Toolkit lets you create 2D window objects such as lines, polygons and textboxes.
This example demonstrates an aircraft Head-Up Display (HUD), built using these window objects.
It gets the view orientation information from the observer to update a heading tape, pitch ladder, and horizon line.
The heading tape indicates the observer's heading from 0 to 360 degrees, and loops around when constantly moving in a circle.
The pitch ladder displays the observer pitch from -40 to + 40 degrees.
You can see the HUD moving by holding down the right mouse button and moving the observer view around. To roll the observer view, press 9 on the NUMPAD of the keyboard. To reset the view, press 5 on the NUMPAD of the keyboard.
Note: This example fixes the size of the main window to be 1000 by 1000 pixels to ensure the window objects are rendered on a square surface. Rendering window objects on a non-square window can result in shearing of the rendered graphics due to limitations in the scaling of window objects. Currently, non-uniform scaling (scaling of window objects on a non-square window) can result in sheared visuals. This limitation is documented under VRV-6174.
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin/exampleWindowObjectHud_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleWindowObjectHud_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
DtWindowObjectHudDriver.h
#pragma once
#include <matrix/vlVector.h>
{
class DtWindowEllipseAgent;
class DtPitchLadder;
class DtHeadingTape;
class DtObserver;
class DtWindowObjectHudDriver : public DtDriver
{
public:
virtual const std::string&
className()
const;
protected:
};
}
Contains makVrv:DtAgentManager class.
Contains makVrv:DtDriver class.
virtual const std::string & instanceName() const
Get this driver's instance name.
DtAgentManager & agentManager()
Get the master scene for this host. Do not create drivers using this agentManager,...
DtPitchLadder * myPitchLadder
Definition DtWindowObjectHudDriver.h:66
DtWindowEllipseAgent * myCenterDot
Center dot or cross hair located at (0.5,0.5) screen space.
Definition DtWindowObjectHudDriver.h:64
virtual ~DtWindowObjectHudDriver()
Virtual DTOR.
virtual const std::string & className() const
Get the class name as a string.
DtHeadingTape * myHeadingTape
Definition DtWindowObjectHudDriver.h:67
virtual bool onStop()
Called when the driver is stopped by the display engine.
DtWindowObjectHudDriver(DtAgentManager &agentManager, const std::string &instanceName)
CTOR.
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtWindowObjectHudDriver.cxx
#include <matrix/vlQuaternion.h>
#include <iostream>
{
DtAgentManager& agentManager, const std::string& instanceName )
: DtDriver( agentManager, instanceName )
, myPitchLadder(0)
, myHeadingTape(0)
, myCenterDot(0)
{
setAutoStart( true );
myUserControllableFlag = false;
}
DtWindowObjectHudDriver::~DtWindowObjectHudDriver()
{
}
const std::string& DtWindowObjectHudDriver::className() const
{
static std::string name( "DtWindowObjectHudDriver" );
return name;
}
bool DtWindowObjectHudDriver::onStart()
{
DtDisplayConfigurations::const_iterator displayCurIter = myAgentManager.de().deConfiguration().displayConfigurations().begin();
DtDisplayConfigurations::const_iterator displayEndIter = myAgentManager.de().deConfiguration().displayConfigurations().end();
std::string dName;
for ( ; displayCurIter != displayEndIter; ++displayCurIter )
{
DtDisplayConfiguration* dec = *displayCurIter;
dName = dec->name();
DtWindowConfigurations::const_iterator viewCurIter = dec->windowConfigurations().begin();
DtWindowConfigurations::const_iterator viewEndIter = dec->windowConfigurations().end();
for ( ; viewCurIter != viewEndIter; ++viewCurIter )
{
DtWindowConfiguration* wc = *viewCurIter;
std::string wName = wc->name();
if ( wName == "Window 1" )
{
wc->setFixedSize( true );
wc->setSize( 1000, 1000 );
DtDisplayProxySP display = myAgentManager.de().findDisplay( dName );
if ( display )
{
DtWindowProxySP window = display->findWindow( wName );
if ( window )
{
display->modifyWindow( window, *wc );
}
}
}
}
}
myCenterDot = DtWindowEllipseAgent::create( myAgentManager );
myCenterDot->setPosition( 0.5, 0.5 );
myCenterDot->setNumVertices( 20 );
myCenterDot->setDimensions( 0.005, 0.005 );
DtObserver* observer = myAgentManager.de().driverManager().inputDriver().findObserverByName(
"Observer 1" );
if ( observer )
{
observer->agent().resetAttachment();
observer->agent().level();
myPitchLadder = new DtPitchLadder( myAgentManager.de(), *observer );
myHeadingTape = new DtHeadingTape( myAgentManager.de(), *observer );
myPitchLadder->init();
myHeadingTape->init();
}
return true ;
}
bool DtWindowObjectHudDriver::onStop()
{
if( myCenterDot )
{
delete myCenterDot;
myCenterDot = 0;
}
if( myPitchLadder )
{
delete myPitchLadder;
myPitchLadder = 0;
}
if( myHeadingTape )
{
delete myHeadingTape;
myHeadingTape = 0;
}
return true;
}
bool DtWindowObjectHudDriver::onTick()
{
if( myPitchLadder )
{
myPitchLadder->tick();
}
if( myHeadingTape )
{
myHeadingTape->tick();
}
return true;
}
}
Contains makVrv:DtAttachManager class.
Contains makVrv::DtDe class.
Contains makVrv::DtDisplayConfigurationGenerator class.
Contains makVrv:DtMasterScene class.
Contains DtHeadingTape class.
#define HudColorA
Definition DtHudConstants.h:15
#define HudColorG
Definition DtHudConstants.h:12
#define HudColorB
Definition DtHudConstants.h:13
#define HudColorR
Definition DtHudConstants.h:14
Contains makVrv::DtObserver class.
Contains the DtObserverModeManager class declaration.
Contains DtPitchLadder class.
Contains makVrv::DtWindowObject class.
Contains DtWindowObjectHudDriver class.
exampleWindowObjectHudPluginInit.h
#pragma once
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEWINDOWOBJECTHUD
namespace makVrv {
class DtDe; }
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
void loadDriver(DtDe *de)
Contains DLL export macros.
#define DT_DLL_EXAMPLEWINDOWOBJECTHUD
Definition exampleWindowObjectHudPlugin.h:18
exampleWindowObjectHudPluginInit.cxx
#include <boost/bind/bind.hpp>
#include <string>
static vrvSignalsLib::connection postInitializeConnection;
{
{
}
}
{
return true;
}
{
postInitializeConnection.disconnect();
}
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtOsgEmptySceneLogo class.
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
static void setEnabled(bool enabled)
This global method will enable or disable the use of an empty scene overlay for all uses of this clas...
Definition DtWindowObjectHudDriver.h:39
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
DtHeadingTape.h
#pragma once
#include <vector>
{
class DtDe;
class DtWindowObjectAgent;
class DtWindowSurfaceAgent;
class DtObserver;
class DtHeadingTape
{
public:
protected:
protected:
};
}
DtWindowObjectAgent * myHeadingTapeLowObject
Root object to control the 0-180 heading tape.
Definition DtHeadingTape.h:72
DtObserver & myObserver
Current Observer refernece.
Definition DtHeadingTape.h:68
DtWindowSurfaceAgent * mySurface
Surface that clips the heading tape.
Definition DtHeadingTape.h:76
DtDe & myDe
DtDe reference.
Definition DtHeadingTape.h:66
std::vector< DtWindowObjectAgent * > DtWindowObjects
typedef vector for holding DtWindowObjectAgents
Definition DtHeadingTape.h:63
DtWindowObjectAgent * myheadingTapeHighObject
Root object to control the 180-360(0) heading tape.
Definition DtHeadingTape.h:74
DtWindowObjects myWindowAgents
Vector of the window agents.
Definition DtHeadingTape.h:70
DtHeadingTape(DtDe &de, DtObserver &observer)
CTOR.
virtual ~DtHeadingTape()
Virtual DTOR.
virtual void tick()
Update the heading tape.
DtHeadingTape.cxx
#include <sstream>
{
: myDe(de)
, myWindowAgents()
, mySurface(0)
, myHeadingTapeLowObject( 0 )
, myheadingTapeHighObject( 0 )
, myObserver(observer)
{
}
{
DtWindowObjects::iterator iter = myWindowAgents.begin();
DtWindowObjects::iterator endIter = myWindowAgents.end();
for ( ; iter != endIter; ++iter )
{
delete toDelete;
toDelete = 0;
}
myWindowAgents.clear();
myHeadingTapeLowObject = 0;
myheadingTapeHighObject = 0;
mySurface = 0;
}
{
if ( mySurface )
{
mySurface->setPosition( 0.5, 0.85 );
mySurface->setScale( 1.0, 0.25 );
mySurface->setClipBox( 0.4, 0.805, 0.6, 0.95 );
myWindowAgents.push_back( mySurface );
}
else
{
return;
}
mySurface->addChild( headingArrow->
uniqueId() );
myWindowAgents.push_back( headingArrow );
myHeadingTapeLowObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myHeadingTapeLowObject );
mySurface->addChild( myHeadingTapeLowObject->uniqueId() );
myheadingTapeHighObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myheadingTapeHighObject );
mySurface->addChild( myheadingTapeHighObject->uniqueId() );
for ( int i = 0; i <= 36; ++i )
{
myHeadingTapeLowObject->addChild( lowHeadingLine->
uniqueId() );
myWindowAgents.push_back( lowHeadingLine );
myheadingTapeHighObject->addChild( highHeadingLine->
uniqueId() );
myWindowAgents.push_back( highHeadingLine );
if ( i % 2 == 0 )
{
float textXOffset = (float)-0.005;
float textYOffset = (float)0.05;
std::ostringstream ss;
ss << i / 2;
std::string onScreenStr = ss.str();
if ( i < 20 )
{
onScreenStr = "0" + onScreenStr;
}
lowHeadingText->
setText( onScreenStr );
myWindowAgents.push_back( lowHeadingText );
if ( i == 0 )
{
onScreenStr = "00";
}
else
{
ss.str( std::string() );
int headingOutput = (36 - (i / 2));
ss << headingOutput;
onScreenStr = ss.str();
}
highHeadingText->
setText( onScreenStr );
myWindowAgents.push_back( highHeadingText );
}
}
}
{
double curPhi, curTheta, curPsi;
myObserver.getTopographicOrientation( curPhi, curTheta, curPsi );
double xPos = 0.0;
double yPos = 0.0;
if ( myHeadingTapeLowObject )
{
DtWindowObject* lowHeadingTape = myHeadingTapeLowObject->findObject();
if ( lowHeadingTape )
{
if ( DtDeg2Rad( -180.0 ) < curPhi && curPhi < DtDeg2Rad( -135.0 ) )
{
}
else
{
}
myHeadingTapeLowObject->setPosition( xPos, yPos );
}
}
if ( myheadingTapeHighObject )
{
DtWindowObject* highHeadingTape = myheadingTapeHighObject->findObject();
if ( highHeadingTape )
{
if ( DtDeg2Rad( 135.0 ) < curPhi && curPhi < DtDeg2Rad( 180.0 ) )
{
}
else
{
}
myheadingTapeHighObject->setPosition( xPos, yPos );
}
}
}
}
#define HudFontSize
Definition DtHudConstants.h:11
#define HeadingScreenUnitsPerDegree
Definition DtHudConstants.h:26
DtUniqueID uniqueId() const
inline accessor
Definition DtAgent.inl:55
A facade for a DtObserverObject.
Definition DtObserver.h:39
Agent class for the scene object class: DtWindowLine.
Definition DtWindowLineAgent.hpp:25
virtual void setVertex(unsigned int vtx, double x, double y)=0
static DtWindowLineAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
virtual void setWidth(unsigned int width)=0
virtual void setColor(float r, float g, float b, float a)=0
Set the color of this object.
Agent class for the scene object class: DtWindowObject.
Definition DtWindowObjectAgent.hpp:27
virtual void addChild(DtUniqueID id)=0
Add a child to this objects child list.
virtual void setPosition(double x, double y)=0
Set the window position of this object.
virtual void setColor(float r, float g, float b, float a)=0
Set the color of this object.
Base class for a graphical object that exists in a window Implements a parenting system for DtWindowO...
Definition DtWindowObject.h:25
virtual void getPosition(double &x, double &y)
Agent class for the scene object class: DtWindowPolygon.
Definition DtWindowPolygonAgent.hpp:25
virtual void setVertex(int index, double x, double y)=0
static DtWindowPolygonAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
virtual void setFill(bool fill)=0
static DtWindowSurfaceAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
Agent class for the scene object class: DtWindowText.
Definition DtWindowTextAgent.hpp:25
virtual void setVisible(bool isVisible)=0
Set whether the polygon is visible.
virtual void setAlignment(unsigned int alignment)=0
virtual void setFont(const std::string &fontFile, float sizeInPoints)=0
virtual void setText(const std::string &text)=0
virtual void setColor(float r, float g, float b, float a)=0
Set the color of this object.
static DtWindowTextAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
virtual void setTopLeftCorner(float x, float y)=0
DtPitchLadder.h
#pragma once
#include <vector>
{
class DtDe;
class DtWindowObjectAgent;
class DtWindowSurfaceAgent;
class DtObserver;
class DtPitchLadder
{
public:
protected:
protected:
protected:
};
}
double lastPhi
Orientation values of the observer from the last frame.
Definition DtPitchLadder.h:76
double lastPsi
Definition DtPitchLadder.h:78
virtual void init()
Initialise the pitch ladder & horizon line.
virtual void tick()
Update the pitch ladder & horizon line.
DtDe & myDe
DtDe reference.
Definition DtPitchLadder.h:62
std::vector< DtWindowObjectAgent * > DtWindowObjects
typedef vector for holding DtWindowObjectAgents
Definition DtPitchLadder.h:59
DtWindowObjectAgent * myPitchLadderRootObject
Root object to control the pitch ladder.
Definition DtPitchLadder.h:66
virtual void drawHorizon()
Draw the horizon.
DtObserver & myObserver
Observer 1 Reference.
Definition DtPitchLadder.h:73
double lastTheta
Definition DtPitchLadder.h:77
DtWindowObjects myWindowAgents
Vector of the window agents.
Definition DtPitchLadder.h:64
DtPitchLadder(DtDe &de, DtObserver &observer)
CTOR.
virtual ~DtPitchLadder()
Virtual DTOR.
DtWindowSurfaceAgent * mySurface
Surface that clips the pitch ladder.
Definition DtPitchLadder.h:69
virtual void drawPitchLadder()
Draw Pitch Ladder.
DtWindowObjectAgent * myHorizonRootObject
Root Object to control the horizon lines.
Definition DtPitchLadder.h:71
DtPitchLadder.cxx
{
: myDe(de)
, myWindowAgents()
, myPitchLadderRootObject(0)
, mySurface(0)
, lastPhi(0.0)
, lastTheta(0.0)
, lastPsi(0.0)
, myObserver( observer )
, myHorizonRootObject(0)
{
}
{
DtWindowObjects::iterator iter = myWindowAgents.begin();
DtWindowObjects::iterator endIter = myWindowAgents.end();
for ( ; iter != endIter; ++iter )
{
delete toDelete;
toDelete = 0;
}
myWindowAgents.clear();
myPitchLadderRootObject = 0;
mySurface = 0;
}
{
myObserver.getTopographicOrientation( lastPhi, lastTheta, lastPsi );
if ( mySurface )
{
mySurface->setClipBox( 0.25, 0.2, 0.75, 0.8 );
mySurface->setPosition( 0.5, 0.5 );
mySurface->setScale( 1.0, 1.0 );
mySurface->setScaleToClipBox( false );
myWindowAgents.push_back( mySurface );
}
drawPitchLadder();
drawHorizon();
}
{
double curPhi, curTheta, curPsi;
myObserver.getTopographicOrientation( curPhi, curTheta, curPsi );
double y = 0.0;
if ( myPitchLadderRootObject )
{
DtWindowObject* pitchLadderRoot = myPitchLadderRootObject->findObject();
if ( pitchLadderRoot )
{
x = -std::sin( curPsi ) * pTranslatDist;
y = std::cos( curPsi ) * pTranslatDist;
myPitchLadderRootObject->setPosition( -x, -y );
myPitchLadderRootObject->setRotation( curPsi );
}
}
if ( myHorizonRootObject )
{
if ( horizonRoot )
{
double pTranslatDist = -DtRad2Deg( curTheta ) * ((0.5) / 22.5);
x = -std::sin( curPsi ) * pTranslatDist;
y = std::cos( curPsi ) * pTranslatDist;
myHorizonRootObject->setPosition( x, y );
}
if (curPsi != lastPsi)
{
myHorizonRootObject->setRotation(curPsi);
}
}
lastPsi = curPsi;
lastTheta = curTheta;
lastPhi = curPhi;
}
{
myHorizonRootObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myHorizonRootObject );
mySurface->addChild( myHorizonRootObject->uniqueId() );
myHorizonRootObject->addChild( leftHorizon->
uniqueId() );
myWindowAgents.push_back( leftHorizon );
myHorizonRootObject->addChild( rightHorizon->
uniqueId() );
myWindowAgents.push_back( rightHorizon );
}
{
myPitchLadderRootObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myPitchLadderRootObject );
mySurface->addChild( myPitchLadderRootObject->uniqueId() );
for ( int i = -8; i <= 8; i = i + 1 )
{
double invertLine = 0.0;
if ( i < 0 )
{
invertLine = 0.015;
}
else if ( i == 0 )
{
invertLine = 0.0075;
}
pitchLine->
setVertex( 0, -0.1, (invertLine - 0.0075) + totalOffset );
pitchLine->
setVertex( 1, -0.1, 0.0 + totalOffset );
pitchLine->
setVertex( 2, -0.1, 0.0 + totalOffset );
pitchLine->
setVertex( 3, 0.1, 0.0 + totalOffset );
pitchLine->
setVertex( 4, 0.1, (invertLine - 0.0075) + totalOffset );
pitchLine->
setVertex( 5, 0.1, 0.0 + totalOffset );
myPitchLadderRootObject->addChild( pitchLine->
uniqueId() );
myWindowAgents.push_back( pitchLine );
pitchTextRight->
setColor( 0.0, 1.0, 0.0, 1.0 );
std::ostringstream ss;
ss << std::abs( 5 * i );
pitchTextRight->
setText( ss.str() );
myPitchLadderRootObject->addChild( pitchTextRight->
uniqueId() );
myWindowAgents.push_back( pitchTextRight );
pitchTextLeft->
setTopLeftCorner( (
float) -0.135, (
float) -0.006 + totalOffset );
pitchTextLeft->
setText( ss.str() );
myPitchLadderRootObject->addChild( pitchTextLeft->
uniqueId() );
myWindowAgents.push_back( pitchTextLeft );
}
}
}
#define PitchScreenUnitsPerDegree
Definition DtHudConstants.h:21
virtual void setSegmentStipplePattern(unsigned int segmentIndex, unsigned int stipplePattern)=0
virtual void setTextBoxWidth(float widthInPixels)=0
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
DtHudConstants.h
#pragma once
#define HudFontSize 16
#define HudColorG 1.0
#define HudColorB 0.0
#define HudColorR 0.0
#define HudColorA 1.0
#define PitchScreenUnitsPerDegree 0.05
#define HeadingScreenUnitsPerDegree 0.015