![]() |
VR-Forces 4.0.4 Class Documentation
|
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 DtDisplayEngine method toggleWireframeMode(), and bind the key event F [Down] in the "Observer Frame" key map (the default).
DtInputDriver& inputDriver =
igApp.de().driverManager().inputDriver();
DtKeyMapManager& keyMapManager = DtKeyMapManager::instance(igApp.de());
keyMapManager.addKeyFunction( "Toggle Wireframe", boost::bind( &toggleWireframe, &igApp.de()), DtKeyMapManager::Rendering );
DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" );
if ( obsFrame ) { inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_F, "Toggle Wireframe" ); }
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.
This example is an application. You can run it by running ./bin/exampleKeyMappage.exe (on Windows) or ./bin/exampleKeyMappage (on Linux). For more information about running examples, please see Running Applications and Examples.
// /****************************************************************************** // ** Copyright (c) 2008 MAK Technologies, Inc. // ** All rights reserved. // ******************************************************************************/ // /****************************************************************************** // ** $RCSfile: exampleKeyMap.cxx,v $ $Revision: 1.13 $ $State: Exp $ // ******************************************************************************/ #include <vrvCore/DtVrvApplication.h> #include <boost/bind.hpp> #include <vrvCore/DtDe.h> #include <vrvCore/DtInputDriver.h> #include <vrvCore/DtKeyMap.h> #include <vrvCore/DtKeyMapManager.h> #include <vrvCore/DtDriverManager.h> #include <vrvCore/DtDeSharedState.h> // Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace. using namespace makVrv; void toggleWireframe(DtDe* de) { de->sharedState().setWireframeMode(!de->sharedState().wireframeMode()); } 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). DtVrvApplication igApp; // 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 = igApp.de().driverManager().inputDriver(); DtKeyMapManager& keyMapManager = DtKeyMapManager::instance(igApp.de()); keyMapManager.addKeyFunction( "Toggle Wireframe", boost::bind( &toggleWireframe, &igApp.de()), DtKeyMapManager::Rendering ); DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" ); if ( obsFrame ) { inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_F, "Toggle Wireframe" ); } // Creates an event loop and begins running it, causing the creation of frames. igApp.run(); }