Changeset 231 for osgVisual/trunk/src


Ignore:
Timestamp:
Feb 13, 2011, 6:08:42 PM (14 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/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • 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.