Changeset 231


Ignore:
Timestamp:
Feb 13, 2011, 6:08:42 PM (13 years ago)
Author:
Torben Dannhauer
Message:

Reloaced eventhandler and manipulator in a dedicated manipulator and tracking class (preparation for automatic tracking by extLink)

Location:
osgVisual/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/trunk/CMakeLists.txt

    r199 r231  
    291291        src/core/visual_core.cpp
    292292        src/core/osgVisual.cpp
     293        src/core/core_manipulator.h
     294        src/core/core_manipulator.cpp
    293295        # Memory Leak debugging
    294296        include/core/leakDetection.h
  • osgVisual/trunk/include/core/visual_core.h

    r228 r231  
    2424#include <osg/Referenced>
    2525#include <osg/Notify>
    26 
    2726#include <osgViewer/Viewer>
    28 
    2927#include <osgDB/ReadFile>
    3028
    31 // OSG eventhandler
    32 #include <osgViewer/ViewerEventHandlers>
     29// Manipulator and eventhandler
     30#include <core_manipulator.h>
    3331
    34 // OSG manipulator
    35 #include <osgGA/TrackballManipulator>
    36 #include <osgGA/FlightManipulator>
    37 #include <osgGA/DriveManipulator>
    38 #include <osgGA/KeySwitchMatrixManipulator>
    39 #include <osgGA/StateSetManipulator>
    40 #include <osgGA/AnimationPathManipulator>
    41 #include <osgGA/TerrainManipulator>
    42 #include <osgGA/NodeTrackerManipulator>
    43 
    44 // Spacenavigator manipulator
    45 #ifdef USE_SPACENAVIGATOR
    46 #include <manip_spaceMouse.h>
    47 #include <manip_nodeTrackerSpaceMouse.h>
    48 #include <manip_freeSpaceMouse.h>
    49 #endif
    50 
    51 // Object mounted manipulator
    52 #include <manip_objectMounted.h>
    5332
    5433#ifdef USE_DISTORTION
     
    8564#endif
    8665
     66
     67
    8768// Test
    8869#include <dataIO_transportContainer.h>
     
    10586        void shutdown();
    10687
    107         void addManipulators();
    10888        void parseScenery(xmlNode * a_node);
    10989        bool loadTerrain(osg::ArgumentParser& arguments_);
     
    11191
    11292        void setupScenery();
    113         void trackNode( osg::Node* node_ );
    114         void trackNode( int trackingID );
    115         int getCurrentTrackingID(){return currentTrackingID;};
    11693
    11794protected:
     95        /**
     96         * \brief Destrcutor
     97         *
     98         */
    11899        virtual ~visual_core(void);
    119100
    120 
    121101private:
     102        /**
     103         * \brief This function starts the main rendering loop
     104         *
     105         */
    122106        void mainLoop();
    123107
     
    143127
    144128
    145 #ifdef USE_SPACENAVIGATOR
    146         /**
    147          * Spacemouse node tracker manipulator
    148          */
    149         osg::ref_ptr<NodeTrackerSpaceMouse> mouseTrackerManip;
    150 
    151         /**
    152          * Space mouse hardware driver instance
    153          */
    154         SpaceMouse* mouse;
    155 #endif
    156 
    157         /**
    158          * This Matrix manipulator is used for controlling Camera by Nodes.
    159          */
    160         osg::ref_ptr<objectMountedManipulator> objectMountedCameraManip;
    161 
    162129
    163130#ifdef USE_SKY_SILVERLINING
     
    181148        osg::ref_ptr<visual_object> testObj;
    182149
    183         osg::ref_ptr<osgGA::NodeTrackerManipulator> nt;
    184 
    185150        osg::ref_ptr<visual_debug_hud> hud;
    186151
    187         int currentTrackingID;
     152        osg::ref_ptr<core_manipulator> manipulators;
    188153};
    189154
  • osgVisual/trunk/src/core/visual_core.cpp

    r228 r231  
    2323{
    2424        OSG_NOTIFY( osg::ALWAYS ) << "visual_core instantiated." << std::endl;
    25 
    26         currentTrackingID = -1;
    2725}
    2826
     
    6058        // Test memory leak (todo)
    6159        double* test = new double[1000];
    62 
    63         #ifdef USE_SPACENAVIGATOR
    64                 mouse = NULL;
    65         #endif
    6660
    6761        //osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( 8 );
     
    9185
    9286        // Add manipulators for user interaction - after dataIO to be able to skip it in slaves rendering machines.
    93         addManipulators();
     87        manipulators = new core_manipulator();
     88        manipulators->init( viewer, arguments, configFilename, rootNode);
    9489
    9590        // create the windows and run the threads.
     
    164159        visual_dataIO::getInstance()->shutdown();
    165160
    166        
    167 #ifdef USE_SPACENAVIGATOR
    168         //Delete SpaceMouse driver
    169         if(mouse)
    170         {
    171                 mouse->shutdown();
    172                 delete mouse;
    173         }
    174 #endif
     161        // Shutdown manipulators
     162        if(manipulators.valid())
     163                manipulators->shutdown();
    175164
    176165        // Destroy osgViewer
     
    197186void visual_core::addManipulators()
    198187{
    199         if(!visual_dataIO::getInstance()->isSlave()) // set up the camera manipulators if not slave.
    200     {
    201         osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
    202 
    203         keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
    204         keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
    205         keyswitchManipulator->addMatrixManipulator( '3', "Terrain", new osgGA::TerrainManipulator() );
    206                 nt = new osgGA::NodeTrackerManipulator();
    207                 nt->setTrackNode(NULL);
    208                 keyswitchManipulator->addMatrixManipulator( '4', "NodeTrackerManipulator", nt );
    209                
    210 #ifdef USE_SPACENAVIGATOR
    211                 // SpaceNavigator manipulator
    212                 mouse = new SpaceMouse();
    213                 mouse->initialize();
    214                 mouseTrackerManip = new NodeTrackerSpaceMouse(mouse);
    215                 mouseTrackerManip->setTrackerMode(NodeTrackerSpaceMouse::NODE_CENTER);
    216                 mouseTrackerManip->setRotationMode(NodeTrackerSpaceMouse::ELEVATION_AZIM);
    217                 mouseTrackerManip->setAutoComputeHomePosition( true );
    218                 keyswitchManipulator->addMatrixManipulator( '5', "Spacemouse Node Tracker", mouseTrackerManip );
    219                 keyswitchManipulator->addMatrixManipulator( '6', "Spacemouse Free (Airplane)", new FreeManipulator(mouse) );
    220 #endif
    221 
    222                 // objectMounted Manipulator for Camera control by Nodes
    223                 objectMountedCameraManip = new objectMountedManipulator();
    224                 keyswitchManipulator->addMatrixManipulator( '7', "Object mounted Camera", objectMountedCameraManip );
    225 
    226                 // Animation path manipulator
    227                 std::string pathfile = util::getAnimationPathFromXMLConfig(configFilename);
    228         char keyForAnimationPath = '8';
    229                 if( pathfile != "" )
    230         {
    231             osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
    232             if (apm || !apm->valid())
    233             {
    234                 unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
    235                 keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
    236                 keyswitchManipulator->selectMatrixManipulator(num);
    237                 ++keyForAnimationPath;
    238             }
    239         }
    240 
    241         viewer->setCameraManipulator( keyswitchManipulator.get() );
    242     }   // If not Slave END
    243 
    244     // add the state manipulator
    245     viewer->addEventHandler( new osgGA::StateSetManipulator(rootNode->getOrCreateStateSet()) );
    246    
    247     // add the thread model handler
    248     viewer->addEventHandler(new osgViewer::ThreadingHandler);
    249 
    250     // add the window size toggle handler
    251     viewer->addEventHandler(new osgViewer::WindowSizeHandler);
    252        
    253     // add the stats handler
    254     viewer->addEventHandler(new osgViewer::StatsHandler);
    255 
    256     // add the help handler
    257     viewer->addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
    258 
    259     // add the record camera path handler
    260     viewer->addEventHandler(new osgViewer::RecordCameraPathHandler);
    261 
    262     // add the LOD Scale handler
    263     viewer->addEventHandler(new osgViewer::LODScaleHandler);
    264 
    265     // add the screen capture handler
    266     viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);
     188
    267189}
    268190
     
    297219                                                std::string attr_name=reinterpret_cast<const char*>(attr->name);
    298220                                                std::string attr_value=reinterpret_cast<const char*>(attr->children->content);
    299                                                 if( attr_name == "id" ) trackNode( util::strToInt(attr_value) );
     221                                                if( attr_name == "id" ) manipulators->trackNode( util::strToInt(attr_value) );
    300222
    301223
     
    510432
    511433}
    512 
    513 void visual_core::trackNode( osg::Node* node_ )
    514 {
    515         if(!node_)
    516                 return;
    517 
    518         osg::Node* node = NULL;
    519         // Check if tracked node is a visual_object
    520         osgVisual::visual_object* trackedObject = dynamic_cast<osgVisual::visual_object*>(node_);
    521         if(trackedObject)
    522         {
    523                 node = trackedObject->getGeometry();
    524 
    525                 // Object mounted manipulator ( Only working with visual_object, not with osg::Node )
    526                 if (objectMountedCameraManip.valid())
    527                         objectMountedCameraManip->setAttachedObject( trackedObject );
    528         }
    529         else
    530                 node = node_;
    531 
    532         // Spacemouse Node Tracker
    533 #ifdef USE_SPACENAVIGATOR
    534         if (mouseTrackerManip.valid())
    535         {
    536                 mouseTrackerManip->setTrackNode( node );
    537                 mouseTrackerManip->setMinimumDistance( 100 );
    538         }
    539 #endif
    540 
    541         // Classical OSG Nodetracker
    542         if(nt.valid())
    543         {
    544                 osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER;
    545                 osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::ELEVATION_AZIM;
    546                 nt->setTrackerMode(trackerMode);
    547                 nt->setRotationMode(rotationMode);
    548                 nt->setMinimumDistance( 100 );
    549                 nt->setTrackNode( node );
    550                 nt->setAutoComputeHomePosition( true );
    551                 nt->setDistance( 250 );
    552         }
    553 }
    554 
    555 void visual_core::trackNode( int trackingID )
    556 {
    557         osg::ref_ptr<osg::Node> tmp = visual_object::findNodeByTrackingID(trackingID, rootNode);
    558         if(tmp.valid())
    559         {
    560                 currentTrackingID = trackingID;
    561                 trackNode(tmp);
    562         }
    563 }
  • osgVisual/trunk/src/dataIO/visual_dataIO.cpp

    r221 r231  
    6262        //// EventCallback at the absolute beginning of the frame
    6363        eventCallback = new dataIO_eventCallback(this);
    64         viewer->getCamera()->setEventCallback( eventCallback );
     64        viewer->getCamera()->addEventCallback( eventCallback );
    6565        //// FinalDrawCallback at the end of event and update handling, but BEFORE rendering the frame
    6666        finalDrawCallback = new dataIO_finalDrawCallback(this);
Note: See TracChangeset for help on using the changeset viewer.