VR-Vantage 1.4.1 API Class Documentation
exampleHudUpdater

This example shows how to create a plug-in that adds updaters for a GL Studio cockpit (HUD) display.

It adds two new updaters: one is VR-Link protocol-specific and is used in the network thread; one is used in the render thread and is considered to use the object protocol.

As seen in exampleHatchStateUpdater.h and exampleMetersPerSecondUpdater.h, all updaters return a string that is used by the GL Studio object to update the display.

            virtual void init(DtVrlinkEntityStateListener* listener);
            virtual std::string value();

Each of the updaters also has a creator that is registered with the updater factory.

      class DT_DLL_EXAMPLEHUDUPDATERPLUGIN DtGlStudioHatchStateUpdaterCreator : public DtGlStudioAttributeUpdaterCreator
      {
      public:
         DtGlStudioHatchStateUpdaterCreator();
         virtual ~DtGlStudioHatchStateUpdaterCreator();

         virtual DtGlStudioAttributeUpdater* create() const;

      protected:

      };

In exampleHudUpdaterPluginInit.cxx the Plugin loader needs to make sure that GL Studio plugin has been initialized and then register a post-initialize function with the display engine to add the new updaters to the updater factory.

         DT_DE_INIT_ONCE(de);

         try
         {
            //make sure GlStudio is initialized
            DtGlStudio::init(de);

            //connect to post-initialize signal to setup updaters
            de.signal_postInitialize.connect(boost::bind(&addUpdaters, &de));
         }
         DtCATCH_AND_PROPAGATE(DtCorruptedState)

In the post-initialize function the updater factory is populated with new updaters. The updater factory is owned by the DtSharedCockpitSettings object. Updater creators are registered with the factory. If an updater creator has the same protocol and name as an existing creator, it will replace the creator.

void addUpdaters(makVrv::DtDe* de)
{
   //create the settings manager and get access to it
   DtSharedCockpitSettingsManager::instance(*de);
   {
      //get the updater factory
      DtWriteSettingsLock<DtSharedCockpitSettings> settings(DtSharedSettingsManager::instance(*de));
      DtGlStudioAttributeUpdaterFactory& factory=settings->updaterFactory();

      //visualizer side updater using entity state repository data directly at network update rate
       factory.registerUpdater(new vrvDis::DtGlStudioHatchStateUpdaterCreator());

      //object side updater uses TSPI data stored in HUD renderable to generate smooth updates at frame rate
      factory.registerUpdater(new DtExampleMetersPerSecondUpdaterCreator());
   }

   de->signal_postInitialize.disconnect(boost::bind(&addUpdaters, de));

All updater creators have a name and a protocol that are set in their constructor. The factory uses these to do lookups when a HUD object is created.

      :DtGlStudioAttributeUpdaterCreator()
   {
      myName="MetersPerSecond";
      myProtocol="Object";
   }

TheDtExampleMetersPerSecondUpdater is derived from a DtGlStudioObjectAttributeUpdater since it is going to live on the object (GL Studio object) side, or in the render thread.

All updaters that are of the "object" protocol have access to a smoother object which is able to get the smoothed values for position, velocity and accelleration at the specific time called.

   std::string DtExampleMetersPerSecondUpdater::value(double time)
   {
      if(mySmoother!=NULL)
      {
         myVelocity=mySmoother->approxVelocity(time);

         std::stringstream ss;

         double magnitude= sqrt(myVelocity.magnitudeSquared());

         ss << magnitude;
         return ss.str();
      }
   
      return "0.0";

The DtGlStudioHatchStateUpdater is a VR-Link protocol updater that is derived from the DtGlStudioVrlAttributeUpdater. This class uses the shared source technique common in VR-Vantage. The protocol specific updaters also return a string value and have a creator exactly like the object protocol updaters. VR-Link protocol updaters are placed in a protocol-specific namespace to keep from conflicting with the same updater for other protocols.

The VR-Link protocol updater is initialized with a DtVrlinkEntityStateListener. This listener provides access to the VR-Link entity state repository and allows for signals to be sent when attributes change.

      void DtGlStudioHatchStateUpdater::init(DtVrlinkEntityStateListener* listener )
      {
         myEntityConnections += listener->signal_appearanceBitSet.connect(
            boost::bind(&DtGlStudioHatchStateUpdater::setAppearanceBit, this, _1, _2));

          //initialize with current data
          setAppearanceBit(0, listener->esr().appearance());
      }

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/exampleHudUpdater_stealth.bat (on Windows) or ./bin/exampleHudUpdater_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleHatchStateUpdater.h

/****************************************************************************** 
** Copyright (c) 2007 MAK Technologies, Inc. 
** All rights reserved. 
******************************************************************************/ 
/****************************************************************************** 
** $RCSfile: DtExampleHudUpdater.h,v $ $Revision: 1.1 $ $State: Exp $ 
******************************************************************************/ 


#ifndef DT_PROTOCOL_NAMESPACE
#error Namespace Protocol Macro DT_PROTOCOL_NAMESPACE not defined.
#endif

#ifndef DtExampleHudUpdater_H_ 
#define DtExampleHudUpdater_H_ 

#include "exampleHudUpdaterPlugin.h"

#include <vrvGlStudioShared/DtGlStudioVrlAttributeUpdater.h>

namespace makVrv 
{ 
   namespace DT_PROTOCOL_NAMESPACE
   {
      
      class DtGlStudioHatchStateUpdater : public DtGlStudioVrlAttributeUpdater
      {
         public: 
            DtGlStudioHatchStateUpdater();

            virtual ~DtGlStudioHatchStateUpdater();

            virtual void init(DtVrlinkEntityStateListener* listener);
            virtual std::string value();

         protected:
            virtual void setAppearanceBit(unsigned int oldVal, unsigned int newVal);
            unsigned int myHatchState;
      };

      class DT_DLL_EXAMPLEHUDUPDATERPLUGIN DtGlStudioHatchStateUpdaterCreator : public DtGlStudioAttributeUpdaterCreator
      {
      public:
         DtGlStudioHatchStateUpdaterCreator();
         virtual ~DtGlStudioHatchStateUpdaterCreator();

         virtual DtGlStudioAttributeUpdater* create() const;

      protected:

      };
   } //DT_PROTOCOL_NAMESPACE::
} //makVrv::

#endif

exampleHatchStateUpdater.inl

/*******************************************************************************
** Copyright (c) 2009 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: DtGlStudioHatchStateUpdater.inl,v $ $Revision: 1.2 $ $State: Exp $
*******************************************************************************/

#include "exampleHatchStateUpdater.h"

#include <vrvVrl/DtVrlinkEntityStateListener.h>

#include <vl/entitySR.h>

#include <boost/bind.hpp>

namespace makVrv
{
   namespace DT_PROTOCOL_NAMESPACE
   {

      DtGlStudioHatchStateUpdater::DtGlStudioHatchStateUpdater()
         :DtGlStudioVrlAttributeUpdater()
      {
      }

      DtGlStudioHatchStateUpdater::~DtGlStudioHatchStateUpdater()
      {

      }

      void DtGlStudioHatchStateUpdater::init(DtVrlinkEntityStateListener* listener )
      {
         myEntityConnections += listener->signal_appearanceBitSet.connect(
            boost::bind(&DtGlStudioHatchStateUpdater::setAppearanceBit, this, _1, _2));

          //initialize with current data
          setAppearanceBit(0, listener->esr().appearance());
      }

      std::string DtGlStudioHatchStateUpdater::value()
      {
         //reset dirty flag
         myIsDirty=false;

         if(myHatchState==DtHatchOpenBitVal)
         {
            return "true";
         }

         return "false";
      }

      void DtGlStudioHatchStateUpdater::setAppearanceBit(unsigned int oldBits, unsigned int newBits)
      {
         //change in the state we care about
         unsigned oldHatch = oldBits & DtAppHatch;
         unsigned newHatch = newBits & DtAppHatch;
         if(oldHatch != newHatch)
         {
            myIsDirty=true;
            myHatchState = newHatch;
         }
      }



      DtGlStudioHatchStateUpdaterCreator::DtGlStudioHatchStateUpdaterCreator()
         :DtGlStudioAttributeUpdaterCreator()
      {
         myName="HatchState";
#ifdef DtDIS
         myProtocol="DtDis";
#else
#ifdef DtHLA_1516
   #ifdef DtHLA_1516_EVOLVED
         myProtocol="DtHla1516e";
   #else
         myProtocol="DtHla1516";
   #endif
#else
         myProtocol="DtHla13";
#endif
#endif

      }

      DtGlStudioHatchStateUpdaterCreator::~DtGlStudioHatchStateUpdaterCreator()
      {

      }

      DtGlStudioAttributeUpdater* DtGlStudioHatchStateUpdaterCreator::create() const
      {
         return new DtGlStudioHatchStateUpdater();
      }

   }//DT_PROTOCOL_NAMESPACE::

} //makVrv::

exampleMetersPerSecondUpdater.cxx

/*******************************************************************************
** Copyright (c) 2009 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: DtExampleMetersPerSecondUpdater.cxx,v $ $Revision: 1.1 $ $State: Exp $
*******************************************************************************/

#include "exampleMetersPerSecondUpdater.h"

#include <vlpi/smoother.h>

namespace makVrv
{
   DtExampleMetersPerSecondUpdater::DtExampleMetersPerSecondUpdater()
      :DtGlStudioObjectAttributeUpdater()
   {
   }

   DtExampleMetersPerSecondUpdater::~DtExampleMetersPerSecondUpdater()
   {

   }

   std::string DtExampleMetersPerSecondUpdater::value(double time)
   {
      if(mySmoother!=NULL)
      {
         myVelocity=mySmoother->approxVelocity(time);

         std::stringstream ss;

         double magnitude= sqrt(myVelocity.magnitudeSquared());

         ss << magnitude;
         return ss.str();
      }
   
      return "0.0";
   }


   DtExampleMetersPerSecondUpdaterCreator::DtExampleMetersPerSecondUpdaterCreator()
      :DtGlStudioAttributeUpdaterCreator()
   {
      myName="MetersPerSecond";
      myProtocol="Object";
   }

   DtExampleMetersPerSecondUpdaterCreator::~DtExampleMetersPerSecondUpdaterCreator()
   {

   }

   DtGlStudioAttributeUpdater* DtExampleMetersPerSecondUpdaterCreator::create() const
   {
      return new DtExampleMetersPerSecondUpdater();
   }
} //makVrv::

exampleMetersPerSecondUpdater.h

/*******************************************************************************
** Copyright (c) 2009 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: DtExampleMetersPerSecondUpdater.h,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/


#ifndef DtExampleMetersPerSecondUpdater_h
#define DtExampleMetersPerSecondUpdater_h

#include "exampleHudUpdaterPlugin.h"

#include <vrvGlStudioShared/DtGlStudioObjectAttributeUpdater.h>

#include <matrix/vlVector.h>

namespace makVrv
{
   class DtExampleMetersPerSecondUpdater : public DtGlStudioObjectAttributeUpdater
   {
   public: 
      DtExampleMetersPerSecondUpdater();

      virtual ~DtExampleMetersPerSecondUpdater();

      virtual std::string value(double time);

   protected:
      DtVector myVelocity;
   };

   class DT_DLL_EXAMPLEHUDUPDATERPLUGIN DtExampleMetersPerSecondUpdaterCreator : public DtGlStudioAttributeUpdaterCreator
   {
   public:
      DtExampleMetersPerSecondUpdaterCreator();
      virtual ~DtExampleMetersPerSecondUpdaterCreator();

      virtual DtGlStudioAttributeUpdater* create() const;

   protected:
   };

} //makVrv::

#endif

exampleHudUpdaterPluginInit.cxx

/******************************************************************************
** Copyright (c) 2007 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
/******************************************************************************
** $RCSfile: exampleChannelPluginInit.cxx,v $ $Revision: 1.3 $ $State: Exp $
******************************************************************************/


#include "exampleHudUpdaterPlugin.h"
#include "exampleHudUpdaterPluginInit.h"

#include <vrvCore/DtDe.h>
#include <vrvGlStudio/DtGlStudio.h>
#include <vrvGlStudioShared/DtSharedCockpitSettings.h>
#include <vrvGlStudioShared/DtSharedCockpitSettingsManager.h>

#include <boost/bind.hpp>

//shared source implementation 
#define DT_PROTOCOL_NAMESPACE vrvDis
#include <vl/globalObjDes.h>
#include <vrvGlStudioDIS/DtGlStudioDIS.h>
#include <vrvDis/vrvDis.h>
#include <vrvVrl/vrvVrl.h>
#include <vl/entitySR.h>
#include <vlpi/entityIdentifier.h>
#include <vrvVrl/DtVrlinkConnection.h>
#include "exampleHatchStateUpdater.h"
#include "exampleHatchStateUpdater.inl"
#undef DT_PROTOCOL_NAMESPACE

#include "exampleMetersPerSecondUpdater.h"

using namespace makVrv;

bool initDeModule(makVrv::DtDe* de)
{
   if (de->deInitializer().featureSupported( makVrv::DtDeInitializer::Features_3D ) )
   {
      vrvExampleHudUpdaterPlugin::init(*de);
      return true;
   }
   return false;
}

void addUpdaters(makVrv::DtDe* de)
{
   //create the settings manager and get access to it
   DtSharedCockpitSettingsManager::instance(*de);
   {
      //get the updater factory
      DtWriteSettingsLock<DtSharedCockpitSettings> settings(DtSharedSettingsManager::instance(*de));
      DtGlStudioAttributeUpdaterFactory& factory=settings->updaterFactory();

      //visualizer side updater using entity state repository data directly at network update rate
       factory.registerUpdater(new vrvDis::DtGlStudioHatchStateUpdaterCreator());

      //object side updater uses TSPI data stored in HUD renderable to generate smooth updates at frame rate
      factory.registerUpdater(new DtExampleMetersPerSecondUpdaterCreator());
   }

   de->signal_postInitialize.disconnect(boost::bind(&addUpdaters, de));
}

namespace makVrv
{
   namespace vrvExampleHudUpdaterPlugin
   {
      void init(DtDe& de)
      {
         DT_DE_INIT_ONCE(de);

         try
         {
            //make sure GlStudio is initialized
            DtGlStudio::init(de);

            //connect to post-initialize signal to setup updaters
            de.signal_postInitialize.connect(boost::bind(&addUpdaters, &de));
         }
         DtCATCH_AND_PROPAGATE(DtCorruptedState)
      }
   }
}


Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)