Overview
Show how to add a shared display unit setting (Mils Orientation).
Expected Result
'Mil' Units Result
Example details
This example show how to add a custom "Orientation" unit converter. A new class DtMilsConverter that derived from DtOrientationUnitConverter class is created. That class implement the necessary functions to do the needed units conversion. Once created the new converter is added to the DtDisplayUnitsSettingsManager.
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 ./bin64/exampleMilUnits_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleMilUnits_stealth.sh (on Linux). Menu "Settings->Display...", select "Display Units Settings", the new "Mils" unit was added to "Orientation" drop down list. For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleMilUnitsPlugin.h
#ifndef exampleMilUnitsPlugin_H_
#define exampleMilUnitsPlugin_H_
#ifdef _WIN32
#ifdef EXAMPLEMILUNITSPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEMILUNITSPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEMILUNITSPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEMILUNITSPLUGIN
#endif
#endif
exampleMilUnitsPluginInit.cxx
#include <matrix/vlMath.h>
{
return true;
}
using namespace makArchives;
namespace makVrv
{
namespace vrvExampleMilUnitsPlugin
{
inline double DtRad2Mil(double rad)
{
return ((rad / M_PI) * 3200.);
}
inline double DtMil2Rad(double mil)
{
return ((mil * M_PI) / 3200.0);
}
class DtMilsConverter : public DtOrientationUnitConverter
{
public:
DtMilsConverter()
: DtOrientationUnitConverter( UnitsMils )
{
}
~DtMilsConverter()
{
}
double radiansToLocal( double radians ) const
{
return DtRad2Mil(radians);
}
double localToRadians( double local ) const
{
return DtMil2Rad(local);
}
DtUnitConverter* clone() const
{
return new DtMilsConverter();
}
};
void installUnitConverter(
DtDe& de)
{
DtDisplayUnitsSettingsManager::instance(de).setAutoSave(false);
new DtMilsConverter() );
{
writeSettings( DtSharedSettingsManager::instance( de ) );
DtSharedDisplayUnitsSettings::Units attr;
{
attr.push_back(DtSharedDisplayUnitsSettings::UnitEntry(
DtUnicode::tr("Mils"), DtUnicode::tr("Mils"), UnitsMils));
}
}
}
{
{
}
}
}
}
exampleMilUnitsPluginInit.h
#pragma once
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEMILUNITSPLUGIN
namespace makVrv
{
class DtDe;
namespace vrvExampleMilUnitsPlugin
{
}
}
[<< Examples] [Home] [Top of Page]