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

Overview

This example shows how to register a function with the Key Map Manager, and bind it to a key event in a key map. In this example we use the DtDeSharedState method setPerformanceOverlayOn(), and bind the key event "'" [Down] in the "Observer Frame" key map (the default).

Expected Result

Key Map Result

Example details

  1. Get a reference to the input driver, which we need to access the Key Map Manager:
DtInputDriver& inputDriver =
  1. Get a reference to the Key Map Manager:
  1. Register the togglePerfOverlay() (and the application's instance of DtDisplayEngine) with the Key Map Manager, telling it to use "Toggle Performance Overlay" as the name of this function:
  1. Since the default key map is Observer Frame, add a key binding to that map. Of course, these last two steps could be omitted and instead use the Key Map Editor to create the key binding. Look up the key map:
  1. If the key map was found, bind the "'" key to the function named Toggle Performance Overlay. Note that the DtKeyMap (DtKeyMap.h) class has an addKeyMap() method that we could use directly, but the wrapper provided by the input driver provides some useful default parameters, making it a little easier to use:

Building the Example

VR-Vantage includes pre-built versions of the example application. 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/exampleKeyMapPlugin_stealth.bat (on Windows) or ./bin64/exampleKeyMapPlugin_stealth.sh (on Linux). Hit the apostrophe key "'" to see the performance overlay display. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleKeyMapPlugin.cxx

/*****************************************************************************
* Copyright (c) 2024 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
// Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace.
using namespace makVrv;
static vrvSignalsLib::connection postInitializeConnection;
void togglePerfOverlay(DtDe* de)
{
unsigned int state = de->sharedState().performanceOverlayState();
{
}
else
{
state++;
}
}
void installKeyMapping(DtDe& de)
{
DtInputDriver& inputDriver =
keyMapManager.addKeyFunction("Toggle Performance Overlay", boost::bind(
&togglePerfOverlay, &de), DtKeyMapManager::Miscellaneous);
DtKeyMap* obsFrame = keyMapManager.findKeyMap("Observer Frame");
if (obsFrame)
{
"Toggle Performance Overlay");
}
}
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 add the key mapping if we are running in master mode.
if (de.isInMasterMode())
{
// The key mapping must be set after the DE's initialization is
// finished, to make sure all the objects it relies on exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
&installKeyMapping, std::ref(de)));
}
}
{
// Setup the plug-in. Normally, the init function and functionality
// should be in its own library.
init(*de);
return true;
}
Contains makVrv::DtDe class.
#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::DtDeSharedState class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtImGuiLoaderStatsData class.
Contains makVrv::DtInputDriver class.
Contains makVrv::DtKeyMapManager class.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
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
virtual DtDeSharedState & sharedState()
Returns the DtDeSharedState object.
virtual unsigned int performanceOverlayState() const
virtual void setPerformanceOverlayState(unsigned int state)
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
@ ProfilerOverlayStates_OFF
Definition DtImGuiLoaderStatsData.h:51
@ ProfilerOverlayStates_FULL
Definition DtImGuiLoaderStatsData.h:53
This class's main responsibility is to handle keyboard and mouse events from OSG (Qt events are route...
Definition DtInputDriver.h:46
void addKeyBinding(DtKeyMap *map, DtKeyState::KeyType key, const std::string &functionName, DtKeyState::KeyModifier modifiers=DtKeyState::NO_MODIFIER, bool replace=false, DtKeyEvent::KeyEventType eventType=DtKeyEvent::KEY_DOWN)
bind a key down or key up event (possibly modified) to a function name
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Miscellaneous
Definition DtKeyMapManager.h:45
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_APOSTROPHE
Definition DtKeyState.h:131
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16