VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exampleKeyMap

Table of Contents

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

exampleKeyMap.png
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:

DtKeyMapManager& keyMapManager = DtKeyMapManager::instance(igApp.de());

  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:

keyMapManager.addKeyFunction( "Toggle Performance Overlay", boost::bind(
&togglePerfOverlay, &igApp.de()), DtKeyMapManager::Miscellaneous);

  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:

DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" );

  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:

if ( obsFrame )
{
inputDriver.addKeyBinding(obsFrame, DtKeyState::KEY_APOSTROPHE,
"Toggle Performance Overlay" );
}

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 an application. You can run it by running ./bin64/exampleKeyMap.exe (on Windows) or ./bin64/exampleKeyMap (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


exampleKeyMap.cxx

// /******************************************************************************
// ** Copyright (c) 2019 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include <boost/bind.hpp>
#include <vrvCore/DtDe.h>
// Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace.
using namespace makVrv;
void togglePerfOverlay(DtDe* de)
{
}
int main(int argc,char** argv)
{
// A DtVrvApplication wraps up all the components required to build a complete
// VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a
// DtVrvApplicationConfiguration).
// This causes the plugin manager to load plugins, cause a Display Configuration
// to be realized, creates the default environment, etc.
igApp.initialize(argc, argv);
DtInputDriver& inputDriver =
DtKeyMapManager& keyMapManager = DtKeyMapManager::instance(igApp.de());
keyMapManager.addKeyFunction( "Toggle Performance Overlay", boost::bind(
&togglePerfOverlay, &igApp.de()), DtKeyMapManager::Miscellaneous);
DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" );
if ( obsFrame )
{
"Toggle Performance Overlay" );
}
// Creates an event loop and begins running it, causing the creation of frames.
igApp.run();
return 0;
}

[<< Examples] [Home] [Top of Page]


Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)