![]() |
VR-Forces 4.0.4 Class Documentation
|
This example shows how to create and register an event processor.
This event processor bypasses the key mapping system. It toggles wireframe mode on or off whenever the F key is pressed, regardless of any key mapping to the contrary.
Note: Any functions mapped to the F key in a key map will not be executed, because the event processor returns true, indicating that the event has been handled.
class MyEventProcessor : public DtEventProcessorInterface { public: MyEventProcessor( DtDe& de ) : myDe( de ) , myClassName( "MyEventProcessor" ) { }
virtual ~MyEventProcessor() { } virtual bool processMouseEvent( const DtMouseEvent& ev, DtChannel& channel) { return false; }
virtual bool processKeyboardEvent( const DtKeyEvent& ev, DtChannel& channel) { if ( ev.eventType() == DtKeyEvent::KEY_DOWN && ev.keyState().keyType() == DtKeyState::KEY_F && ev.keyState().modifiers() == DtKeyState::NO_MODIFIER ) { myDe.sharedState().setWireframeMode(!myDe.sharedState().wireframeMode()); // handled return true; } return false; }
DtDe& myDe; std::string myClassName;
MyEventProcessor* captureF = new MyEventProcessor( igApp.de() ); DtInputDriver& inputDriver = igApp.de().driverManager().inputDriver(); inputDriver.addEventProcessorToFront( captureF );
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/exampleEventProcessor.exe (on Windows) or ./bin/exampleEventProcessor (on Linux). For more information about running examples, please see Running Applications and Examples.
// /****************************************************************************** // ** Copyright (c) 2008 MAK Technologies, Inc. // ** All rights reserved. // ******************************************************************************/ // /****************************************************************************** // ** $RCSfile: exampleEventProcessor.cxx,v $ $Revision: 1.14 $ $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> #include <vrvCore/DtEventProcessorInterface.h> // Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace. using namespace makVrv; class MyEventProcessor : public DtEventProcessorInterface { public: MyEventProcessor( DtDe& de ) : myDe( de ) , myClassName( "MyEventProcessor" ) { } virtual ~MyEventProcessor() { } virtual bool processMouseEvent( const DtMouseEvent& ev, DtChannel& channel) { return false; } virtual bool processKeyboardEvent( const DtKeyEvent& ev, DtChannel& channel) { if ( ev.eventType() == DtKeyEvent::KEY_DOWN && ev.keyState().keyType() == DtKeyState::KEY_F && ev.keyState().modifiers() == DtKeyState::NO_MODIFIER ) { myDe.sharedState().setWireframeMode(!myDe.sharedState().wireframeMode()); // handled return true; } return false; } virtual const std::string& className() { return myClassName; } protected: DtDe& myDe; std::string myClassName; }; 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); MyEventProcessor* captureF = new MyEventProcessor( igApp.de() ); DtInputDriver& inputDriver = igApp.de().driverManager().inputDriver(); inputDriver.addEventProcessorToFront( captureF ); // Creates an event loop and begins running it, causing the creation of frames. igApp.run(); }