![]() |
VR-Forces 4.0.4 Class Documentation
|
The exampleCreator example uses the creator pattern to cause a derived channel to get created when the display engine creates a channel. Here is the object class:
class MyExampleChannel : public DtOsgChannel { public: friend class MyExampleChannelCreator; virtual ~MyExampleChannel() { } protected: MyExampleChannel( DtDe& de, DtWindow* window, DtChannelConfiguration& channelConfig ) : DtOsgChannel( de, window, channelConfig ) { // Do nothing. This is an example of registering a class using the creator pattern. // osgViewer::View* view = view(); // osg::Camera* camera = camera(); } };
Notice the protected constructor. This is because we are going to use a creator to create our channel. Here is the creator for the object class:
class MyExampleChannelCreator : public DtChannelCreator { public: virtual DtChannel* create( DtDe& de, DtWindow* window, DtChannelConfiguration& config ) { return new MyExampleChannel( de, window, config ); } };
This creator is derived from the DtChannelCreator (DtChannel.h):
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/exampleCreator.exe (on Windows) or ./bin/exampleCreator (on Linux). For more information about running examples, please see Running Applications and Examples.
/***************************************************************************** * Copyright (c) 2012 MaK Technologies, Inc. * All rights reserved. *****************************************************************************/ #include <vrvCore/DtVrvApplication.h> #include <vrvOsg/DtOsgChannel.h> #include <boost/bind.hpp> // Use the VR-Vantage namespace. All classes in VR-Vantage are in this namespace. using namespace makVrv; // An example derived channel. // This shows how to create and register your own channel with the DtDisplayEngine. // This example demonstrates the Creator Pattern. class MyExampleChannel : public DtOsgChannel { public: friend class MyExampleChannelCreator; virtual ~MyExampleChannel() { } protected: MyExampleChannel( DtDe& de, DtWindow* window, DtChannelConfiguration& channelConfig ) : DtOsgChannel( de, window, channelConfig ) { // Do nothing. This is an example of registering a class using the creator pattern. // osgViewer::View* view = view(); // osg::Camera* camera = camera(); } }; class MyExampleChannelCreator : public DtChannelCreator { public: virtual DtChannel* create( DtDe& de, DtWindow* window, DtChannelConfiguration& config ) { return new MyExampleChannel( de, window, config ); } }; // A DtVrvApplication wraps up all the components required to build a complete // VR-Vantage application (DtDe, DtPluginManager, DtEventLoop, and a // DtVrvApplicationConfiguration). // // This derived application simply overrides the postLoadPluginModules() call // to register our example channel after the plugins are loaded. class MyExampleApplication : public DtVrvApplication { public: MyExampleApplication() : DtVrvApplication() { DtVrvApplication::ApplicationTransform functor = boost::bind( &MyExampleApplication::postLoadPluginModules, this, _1, _2, _3 ); installPostPluginTransform( functor, "postPluginTransform" ); } protected: virtual void postLoadPluginModules( DtDeInitializer& deInit, DtDe& de, DtVrvApplicationConfiguration& config ) { // Register the channel creator DtChannelCreator::registerInstance( *myDe, new MyExampleChannelCreator() ); } }; int main( int argc,char* argv[] ) { // Create the example application class. MyExampleApplication application; // This causes the plugin manager to load plugins, cause a Display Configuration // to be realized, creates the default environment, etc. application.initialize(argc, argv); // Creates an event loop and begins running it, causing the creation of frames. application.run(); }