Changeset 231 for osgVisual/trunk/src/core
- Timestamp:
- Feb 13, 2011, 6:08:42 PM (14 years ago)
- Location:
- osgVisual/trunk/src/core
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/trunk/src/core/visual_core.cpp
r228 r231 23 23 { 24 24 OSG_NOTIFY( osg::ALWAYS ) << "visual_core instantiated." << std::endl; 25 26 currentTrackingID = -1;27 25 } 28 26 … … 60 58 // Test memory leak (todo) 61 59 double* test = new double[1000]; 62 63 #ifdef USE_SPACENAVIGATOR64 mouse = NULL;65 #endif66 60 67 61 //osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( 8 ); … … 91 85 92 86 // 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); 94 89 95 90 // create the windows and run the threads. … … 164 159 visual_dataIO::getInstance()->shutdown(); 165 160 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(); 175 164 176 165 // Destroy osgViewer … … 197 186 void visual_core::addManipulators() 198 187 { 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 267 189 } 268 190 … … 297 219 std::string attr_name=reinterpret_cast<const char*>(attr->name); 298 220 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) ); 300 222 301 223 … … 510 432 511 433 } 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_object520 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 else530 node = node_;531 532 // Spacemouse Node Tracker533 #ifdef USE_SPACENAVIGATOR534 if (mouseTrackerManip.valid())535 {536 mouseTrackerManip->setTrackNode( node );537 mouseTrackerManip->setMinimumDistance( 100 );538 }539 #endif540 541 // Classical OSG Nodetracker542 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 }
Note: See TracChangeset
for help on using the changeset viewer.