VR-Vantage
Loading...
Searching...
No Matches
exampleWindowObjectHud

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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#pragma once
#include <matrix/vlVector.h>
namespace makVrv
{
class DtWindowEllipseAgent;
class DtPitchLadder;
class DtHeadingTape;
class DtObserver;
class DtWindowObjectHudDriver : public DtDriver
{
public:
DtWindowObjectHudDriver( DtAgentManager& agentManager, const std::string& instanceName );
virtual const std::string& className() const;
protected:
virtual bool onStart();
virtual bool onStop();
virtual bool onTick();
DtWindowEllipseAgent* myCenterDot;
DtPitchLadder* myPitchLadder;
DtHeadingTape* myHeadingTape;
};
}
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

// /******************************************************************************
// ** Copyright (c) 2025 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include <vrvCore/DtDe.h>
#include "DtPitchLadder.h"
#include "DtHeadingTape.h"
#include "DtHudConstants.h"
#include <matrix/vlQuaternion.h>
#include <iostream>
namespace makVrv
{
DtAgentManager& agentManager, const std::string& instanceName )
: DtDriver( agentManager, instanceName )
, myPitchLadder(0)
, myHeadingTape(0)
, myCenterDot(0)
{
// Tell the driver to start automatically when added to the DE
setAutoStart( true );
// This driver can't be started or stopped from the GUI; myUserControllableFlag sets this property
myUserControllableFlag = false;
}
DtWindowObjectHudDriver::~DtWindowObjectHudDriver()
{
}
const std::string& DtWindowObjectHudDriver::className() const
{
// name must be static, since it's returned by reference
static std::string name( "DtWindowObjectHudDriver" );
return name;
}
bool DtWindowObjectHudDriver::onStart()
{
// Iterate through displays
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();
// Iterate through all the windows
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 );
}
}
}
}
}
// Create center dot
myCenterDot = DtWindowEllipseAgent::create( myAgentManager );
myCenterDot->setPosition( 0.5, 0.5 );
myCenterDot->setNumVertices( 20 );
myCenterDot->setDimensions( 0.005, 0.005 );
myCenterDot->setColor( HudColorR, HudColorG, HudColorB, HudColorA );
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.
Contains DtHudConstants.
#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::DtInputDriver class.
Contains makVrv::DtObserver class.
Contains the DtObserverModeManager class declaration.
Contains DtPitchLadder class.
Contains makVrv::DtWindowObject class.
Contains DtWindowObjectHudDriver class.

exampleWindowObjectHudPluginInit.h

/******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEWINDOWOBJECTHUD
// Declare & export the plugin initialization function (bool initDeModule(DtDe* de))
namespace makVrv { class DtDe; }
// Work function for the plugin initialization
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

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <boost/bind/bind.hpp>
#include <string>
using namespace makVrv;
static vrvSignalsLib::connection postInitializeConnection;
void init( DtDe& de )
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// We only want to create the accessory if we're running in master mode:
if ( de.isInMasterMode() )
{
// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect( boost::bind( &loadDriver, &de ) );
}
}
{
// Setup the plugin
init( *de );
return true;
}
{
postInitializeConnection.disconnect();
DtWindowObjectHudDriver* driver = new DtWindowObjectHudDriver( de->agentManager(), "winowObjectHudDriver" );
de->driverManager().addDriver( driver );
}
#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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#pragma once
#include <vector>
// Use the VR-Vantage namespace.
// All classes in VR-Vantage are in this namespace.
namespace makVrv
{
class DtDe;
class DtWindowObjectAgent;
class DtWindowSurfaceAgent;
class DtObserver;
class DtHeadingTape
{
public:
DtHeadingTape( DtDe& de, DtObserver& observer );
virtual ~DtHeadingTape();
virtual void init();
virtual void tick();
protected:
typedef std::vector<DtWindowObjectAgent*> DtWindowObjects;
protected:
DtDe& myDe;
DtObserver& myObserver;
DtWindowObjectAgent* myHeadingTapeLowObject;
DtWindowObjectAgent* myheadingTapeHighObject;
DtWindowSurfaceAgent* mySurface;
};
}
DtWindowObjectAgent * myHeadingTapeLowObject
Root object to control the 0-180 heading tape.
Definition DtHeadingTape.h:72
DtObserver & myObserver
Current Observer refernece.
Definition DtHeadingTape.h:68
virtual void init()
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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include "DtHeadingTape.h"
#include "DtHudConstants.h"
#include <vrvCore/DtDe.h>
#include <sstream>
namespace makVrv
{
: 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 )
{
DtWindowObjectAgent* toDelete = *iter;
delete toDelete;
toDelete = 0;
}
myWindowAgents.clear();
myHeadingTapeLowObject = 0;
myheadingTapeHighObject = 0;
mySurface = 0;
}
{
mySurface = DtWindowSurfaceAgent::create( myDe.agentManager() );
if ( mySurface )
{
// Screen is (0.0,0.0) bottom left corner to (1.0,1.0) top right corner
mySurface->setPosition( 0.5, 0.85 );
mySurface->setScale( 1.0, 0.25 );
// This clip box will automatically clip any object outside it, provided
// that the object is a child of this surface object
mySurface->setClipBox( 0.4, 0.805, 0.6, 0.95 );
myWindowAgents.push_back( mySurface );
}
else
{
return;
}
DtWindowPolygonAgent* headingArrow = DtWindowPolygonAgent::create( myDe.agentManager() );
headingArrow->setVertex( 0, 0.0, 0.075 );
headingArrow->setVertex( 1, 0.005, 0.045 );
headingArrow->setVertex( 2, 0.00, 0.095 );
headingArrow->setVertex( 3, -0.005, 0.045 );
headingArrow->setFill( true );
mySurface->addChild( headingArrow->uniqueId() );
myWindowAgents.push_back( headingArrow );
// These low and high heading objects are used to control the tapes
// in the tick method. All of other heading lines are attached to these
// as children. The heading lines are specified in the coordinate system
// of these objects
myHeadingTapeLowObject = DtWindowLineAgent::create( myDe.agentManager() );
myHeadingTapeLowObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myHeadingTapeLowObject );
mySurface->addChild( myHeadingTapeLowObject->uniqueId() );
myheadingTapeHighObject = DtWindowLineAgent::create( myDe.agentManager() );
myheadingTapeHighObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myheadingTapeHighObject );
mySurface->addChild( myheadingTapeHighObject->uniqueId() );
for ( int i = 0; i <= 36; ++i )
{
DtWindowLineAgent* lowHeadingLine = DtWindowLineAgent::create( myDe.agentManager() );
// Line every 5 degrees
double xOffset = (HeadingScreenUnitsPerDegree * 5) * i;
// 0 - 180 line
lowHeadingLine->setVertex( 0, 0.0, 0.1 );
lowHeadingLine->setVertex( 1, 0.0, 0.175 );
lowHeadingLine->setWidth( 3 );
lowHeadingLine->setPosition( xOffset, 0.0 );
myHeadingTapeLowObject->addChild( lowHeadingLine->uniqueId() );
myWindowAgents.push_back( lowHeadingLine );
// 180 - 0 line
DtWindowLineAgent* highHeadingLine = DtWindowLineAgent::create( myDe.agentManager() );
highHeadingLine->setVertex( 0, 0.0, 0.1 );
highHeadingLine->setVertex( 1, 0.0, 0.175 );
highHeadingLine->setWidth( 3 );
highHeadingLine->setPosition( -xOffset, 0.0 );
myheadingTapeHighObject->addChild( highHeadingLine->uniqueId() );
myWindowAgents.push_back( highHeadingLine );
if ( i % 2 == 0 ) // every second line
{
float textXOffset = (float)-0.005;
float textYOffset = (float)0.05;
DtWindowTextAgent* lowHeadingText = DtWindowTextAgent::create( myDe.agentManager() );
lowHeadingText->setTopLeftCorner( (float)textXOffset, (float)textYOffset );
std::ostringstream ss;
ss << i / 2;
std::string onScreenStr = ss.str();
if ( i < 20 )
{
// pad a 0 for text str < 10
onScreenStr = "0" + onScreenStr;
}
lowHeadingText->setText( onScreenStr );
lowHeadingText->setFont( "FreeMono.otf", HudFontSize );
lowHeadingText->setVisible( true );
lowHeadingText->setAlignment( 0 );
lowHeadingLine->addChild( lowHeadingText->uniqueId() );
myWindowAgents.push_back( lowHeadingText );
DtWindowTextAgent* highHeadingText = DtWindowTextAgent::create( myDe.agentManager() );
highHeadingText->setTopLeftCorner( (float)textXOffset, (float)textYOffset );
if ( i == 0 )
{
onScreenStr = "00";
}
else
{
ss.str( std::string() );
int headingOutput = (36 - (i / 2));
ss << headingOutput;
onScreenStr = ss.str();
}
highHeadingText->setText( onScreenStr );
highHeadingText->setFont( "FreeMono.otf", HudFontSize );
highHeadingText->setVisible( true );
highHeadingText->setAlignment( 0 );
highHeadingLine->addChild( highHeadingText->uniqueId() );
myWindowAgents.push_back( highHeadingText );
}
}
}
{
double curPhi, curTheta, curPsi;
myObserver.getTopographicOrientation( curPhi, curTheta, curPsi );//ypr
double xPos = 0.0;
double yPos = 0.0;
// The tapes are spilt in two so we do not need an endless tape. Imagine we are flying
// in a circle, or rotating in a hover, when the tape comes back around to 00 we slot
// the 0->180 tape onto the end of 180->360.
if ( myHeadingTapeLowObject )
{
DtWindowObject* lowHeadingTape = myHeadingTapeLowObject->findObject();
if ( lowHeadingTape )
{
lowHeadingTape->getPosition( xPos, yPos );
if ( DtDeg2Rad( -180.0 ) < curPhi && curPhi < DtDeg2Rad( -135.0 ) )
{
// 0.015 = screen units per degree of rotation
// the tape is 180 * 0.015 = 2.7
// Tapes are centered on 0.0
xPos = ((-180.0 - DtRad2Deg( curPhi )) * HeadingScreenUnitsPerDegree) - 2.7;
}
else
{
xPos = (DtRad2Deg( curPhi ) * (-HeadingScreenUnitsPerDegree));
}
myHeadingTapeLowObject->setPosition( xPos, yPos );
}
}
if ( myheadingTapeHighObject )
{
DtWindowObject* highHeadingTape = myheadingTapeHighObject->findObject();
if ( highHeadingTape )
{
highHeadingTape->getPosition( xPos, yPos );
if ( DtDeg2Rad( 135.0 ) < curPhi && curPhi < DtDeg2Rad( 180.0 ) )
{
// 0.015 = screen units per degree of rotation
// the tape is 180 * 0.015 = 2.7 long
// Tapes are centered on 0.0
xPos = ((180.0 - DtRad2Deg( curPhi )) * HeadingScreenUnitsPerDegree) + 2.7;
}
else
{
xPos = (DtRad2Deg( curPhi ) * (-HeadingScreenUnitsPerDegree));
}
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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#pragma once
#include <vector>
// Use the VR-Vantage namespace.
// All classes in VR-Vantage are in this namespace.
namespace makVrv
{
class DtDe;
class DtWindowObjectAgent;
class DtWindowSurfaceAgent;
class DtObserver;
class DtPitchLadder
{
public:
DtPitchLadder( DtDe& de, DtObserver& observer );
virtual ~DtPitchLadder();
virtual void init();
virtual void tick();
protected:
virtual void drawHorizon();
virtual void drawPitchLadder();
protected:
typedef std::vector<DtWindowObjectAgent*> DtWindowObjects;
protected:
DtDe& myDe;
DtWindowObjectAgent* myPitchLadderRootObject;
DtWindowSurfaceAgent* mySurface;
DtWindowObjectAgent* myHorizonRootObject;
DtObserver& myObserver;
double lastPhi;
double lastTheta;
double lastPsi;
};
}
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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include "DtPitchLadder.h"
#include "DtHudConstants.h"
#include <vrvCore/DtDe.h>
namespace makVrv
{
: 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 )
{
DtWindowObjectAgent* toDelete = *iter;
delete toDelete;
toDelete = 0;
}
myWindowAgents.clear();
myPitchLadderRootObject = 0;
mySurface = 0;
}
{
myObserver.getTopographicOrientation( lastPhi, lastTheta, lastPsi );
mySurface = DtWindowSurfaceAgent::create( myDe.agentManager() );
if ( mySurface )
{
// Screen is (0.0,0.0) bottom left corner to (1.0,1.0) top right corner
// This clip box will automatically clip any object outside it, provided
// that the object is a child of this surface object
mySurface->setClipBox( 0.25, 0.2, 0.75, 0.8 );
mySurface->setPosition( 0.5, 0.5 );
// non uni-form scales on surfaces will currently not work]
// if you wish to rotate all the children attached to the
// surface
mySurface->setScale( 1.0, 1.0 );
mySurface->setScaleToClipBox( false );
myWindowAgents.push_back( mySurface );
}
drawPitchLadder();
drawHorizon();
}
{
double curPhi, curTheta, curPsi;
myObserver.getTopographicOrientation( curPhi, curTheta, curPsi );//ypr
double x = 0.0;
double y = 0.0;
// Update Pitch Ladder
if ( myPitchLadderRootObject )
{
DtWindowObject* pitchLadderRoot = myPitchLadderRootObject->findObject();
if ( pitchLadderRoot )
{
// current pitch * units per degree between pitch lines
// pitch lines are separated by 0.25 units.
double pTranslatDist = DtRad2Deg( curTheta ) * (PitchScreenUnitsPerDegree * 0.6);
x = -std::sin( curPsi ) * pTranslatDist;
y = std::cos( curPsi ) * pTranslatDist;
myPitchLadderRootObject->setPosition( -x, -y );
myPitchLadderRootObject->setRotation( curPsi );
}
}
// Update Horizon
if ( myHorizonRootObject )
{
DtWindowObject* horizonRoot = myHorizonRootObject->findObject();
if ( horizonRoot )
{
// change in pitch * half height of screen (0.5) * top half fov degrees (22.5)
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 = DtWindowLineAgent::create( myDe.agentManager() );
myHorizonRootObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myHorizonRootObject );
mySurface->addChild( myHorizonRootObject->uniqueId() );
DtWindowLineAgent* leftHorizon = DtWindowLineAgent::create( myDe.agentManager() );
leftHorizon->setVertex( 0, -0.13, 0.0 );
leftHorizon->setVertex( 1, -0.20, 0.0 );
leftHorizon->setVertex( 2, -0.20, -0.025 );
leftHorizon->setWidth( 3 );
myHorizonRootObject->addChild( leftHorizon->uniqueId() );
myWindowAgents.push_back( leftHorizon );
DtWindowLineAgent* rightHorizon = DtWindowLineAgent::create( myDe.agentManager() );
rightHorizon->setVertex( 0, 0.13, 0.0 );
rightHorizon->setVertex( 1, 0.20, 0.0 );
rightHorizon->setVertex( 2, 0.20, -0.025 );
rightHorizon->setWidth( 3 );
myHorizonRootObject->addChild( rightHorizon->uniqueId() );
myWindowAgents.push_back( rightHorizon );
}
{
myPitchLadderRootObject = DtWindowLineAgent::create( myDe.agentManager() );
myPitchLadderRootObject->setPosition( 0.0, 0.0 );
myWindowAgents.push_back( myPitchLadderRootObject );
mySurface->addChild( myPitchLadderRootObject->uniqueId() );
for ( int i = -8; i <= 8; i = i + 1 )
{
DtWindowLineAgent* pitchLine = DtWindowLineAgent::create( myDe.agentManager() );
// 5 Degrees between each line
double totalOffset = PitchScreenUnitsPerDegree * 5 * i;
double invertLine = 0.0;
if ( i < 0 )
{
invertLine = 0.015;
pitchLine->setSegmentStipplePattern( 2, 1, 0x00FF );
}
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 );
pitchLine->setWidth( 3 );
myPitchLadderRootObject->addChild( pitchLine->uniqueId() );
myWindowAgents.push_back( pitchLine );
DtWindowTextAgent* pitchTextRight = DtWindowTextAgent::create( myDe.agentManager() );
pitchTextRight->setColor( 0.0, 1.0, 0.0, 1.0 );
pitchTextRight->setTopLeftCorner( (float)0.105, (float) -0.006 + totalOffset );
std::ostringstream ss;
ss << std::abs( 5 * i );
pitchTextRight->setText( ss.str() );
pitchTextRight->setFont( "FreeMono.otf", HudFontSize );
pitchTextRight->setVisible( true );
pitchTextRight->setAlignment( 0 );
myPitchLadderRootObject->addChild( pitchTextRight->uniqueId() );
myWindowAgents.push_back( pitchTextRight );
DtWindowTextAgent* pitchTextLeft = DtWindowTextAgent::create( myDe.agentManager() );
pitchTextLeft->setTopLeftCorner( (float) -0.135, (float) -0.006 + totalOffset );
pitchTextLeft->setText( ss.str() );
pitchTextLeft->setFont( "FreeMono.otf", HudFontSize );
pitchTextLeft->setVisible( true );
pitchTextLeft->setAlignment( 2 ); // right
pitchTextLeft->setTextBoxWidth( 28 );
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

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#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