- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPresentation/SlideEventHandler.cpp
r12908 r13041 1 /* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield 1 /* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield 2 2 * 3 * This software is open source and may be redistributed and/or modified under 3 * This software is open source and may be redistributed and/or modified under 4 4 * the terms of the GNU General Public License (GPL) version 2.0. 5 5 * The full license is in LICENSE.txt file included with this distribution,. 6 * 6 * 7 7 * This software is distributed in the hope that it will be useful, 8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 10 * include LICENSE.txt for more details. 11 11 */ … … 72 72 reset(); 73 73 } 74 74 75 75 virtual void maintain() 76 76 { 77 77 } 78 78 79 79 virtual void leave() 80 80 { … … 91 91 else _imageStream->play(); 92 92 } 93 93 94 94 virtual void reset() 95 95 { … … 100 100 101 101 //_imageStream->setVolume(previousVolume); 102 102 103 103 if(previousStatus==osg::ImageStream::PLAYING) 104 104 { … … 106 106 } 107 107 108 // add a delay so that movie thread has a chance to do the rewind 108 // add a delay so that movie thread has a chance to do the rewind 109 109 float microSecondsToDelay = SlideEventHandler::instance()->getTimeDelayOnNewSlideWithMovies() * 1000000.0f; 110 110 OpenThreads::Thread::microSleep(static_cast<unsigned int>(microSecondsToDelay)); … … 126 126 reset(); 127 127 } 128 128 129 129 virtual void maintain() 130 130 { 131 131 } 132 132 133 133 virtual void leave() 134 134 { … … 208 208 209 209 OSG_INFO<<"}"<<std::endl; 210 } 210 } 211 211 if (!_layerAttribute->_runStrings.empty()) 212 212 { … … 235 235 236 236 } 237 237 238 238 virtual void maintain() 239 239 { 240 240 } 241 241 242 242 virtual void leave() 243 243 { … … 286 286 } 287 287 288 void apply(osg::Geode& node) 288 void apply(osg::Geode& node) 289 289 { 290 290 apply((osg::Node&)node); … … 326 326 { 327 327 _previous.swap(_current); 328 328 329 329 _current.clear(); 330 330 331 331 FindOperatorsVisitor fov(_current, tm); 332 332 incommingNode->accept(fov); 333 333 334 334 OSG_INFO<<"ActiveOperators::collect("<<incommingNode<<")"<<std::endl; 335 335 OSG_INFO<<" _previous.size()="<<_previous.size()<<std::endl; 336 336 OSG_INFO<<" _current.size()="<<_current.size()<<std::endl; 337 337 338 338 _outgoing.clear(); 339 339 _incomming.clear(); 340 340 _maintained.clear(); 341 341 342 342 for(OperatorList::iterator itr = _previous.begin(); 343 343 itr != _previous.end(); … … 348 348 else _maintained.insert(prev); 349 349 } 350 350 351 351 for(OperatorList::iterator itr = _current.begin(); 352 352 itr != _current.end(); … … 389 389 void ActiveOperators::processOutgoing() 390 390 { 391 OSG_INFO<<" outgoing.size()="<<_outgoing.size()<<std::endl; 391 OSG_INFO<<" outgoing.size()="<<_outgoing.size()<<std::endl; 392 392 for(OperatorList::iterator itr = _outgoing.begin(); 393 393 itr != _outgoing.end(); … … 430 430 FindHomePositionVisitor(): 431 431 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {} 432 432 433 433 void apply(osg::Node& node) 434 434 { … … 438 438 _homePosition = homePosition; 439 439 } 440 440 441 441 traverse(node); 442 442 } 443 443 444 444 osg::ref_ptr<HomePosition> _homePosition; 445 445 446 446 }; 447 447 … … 454 454 _name(name), 455 455 _switch(0) {} 456 456 457 457 void apply(osg::Switch& sw) 458 458 { … … 462 462 return; // note, no need to do traverse now we've located the relevant switch 463 463 } 464 464 465 465 traverse(sw); 466 466 } 467 467 468 468 std::string _name; 469 469 osg::Switch* _switch; 470 470 471 471 }; 472 472 … … 478 478 FindFilePathDataVisitor(): 479 479 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {} 480 480 481 481 void apply(osg::Node& node) 482 482 { 483 483 FilePathData* fdd = dynamic_cast<FilePathData*>(node.getUserData()); 484 if (fdd) 484 if (fdd) 485 485 { 486 486 OSG_INFO<<"Recorded FilePathData"<<std::endl; 487 487 osgDB::setDataFilePathList(fdd->filePathList); 488 488 } 489 489 490 490 traverse(node); 491 491 } 492 492 493 493 }; 494 494 … … 501 501 _viewMatrix(viewMatrix), 502 502 _currentX(currentX), _currentY(currentY) {} 503 503 504 504 void apply(osg::Node& node) 505 505 { 506 506 traverse(node); 507 507 } 508 508 509 509 void apply(osg::LightSource& lightsource) 510 510 { … … 520 520 } 521 521 } 522 522 523 523 traverse(lightsource); 524 524 } … … 531 531 if (sum_x2_y2<1.0) direction.set(_currentX, _currentY, sqrtf(1.0-sum_x2_y2)); 532 532 else direction.set(_currentX, _currentY, 0.0); 533 533 534 534 direction.normalize(); 535 535 536 536 direction = osg::Matrixd::transform3x3(matrix, direction); 537 537 direction.normalize(); … … 542 542 osg::Matrixd _viewMatrix; 543 543 float _currentX, _currentY; 544 544 545 545 }; 546 546 … … 553 553 _modAlphaFunc(modAlphaFunc), _modMaterial(modMaterial), 554 554 _currentX(currentX), _currentY(currentY) {} 555 555 556 556 void apply(osg::Node& node) 557 557 { … … 559 559 traverse(node); 560 560 } 561 561 562 562 void apply(osg::StateSet& stateset) 563 563 { … … 575 575 } 576 576 } 577 577 578 578 if (_modMaterial) 579 { 579 { 580 580 osg::Material* material = dynamic_cast<osg::Material*>(stateset.getAttribute(osg::StateAttribute::MATERIAL)); 581 581 if (material) … … 590 590 bool _modAlphaFunc, _modMaterial; 591 591 float _currentX, _currentY; 592 592 593 593 }; 594 594 … … 652 652 FindNamedSwitchVisitor findPresentation("Presentation"); 653 653 model->accept(findPresentation); 654 654 655 655 if (findPresentation._switch) 656 656 { 657 657 OSG_INFO<<"Presentation '"<<model->getName()<<"'"<<std::endl; 658 658 _presentationSwitch = findPresentation._switch; 659 659 660 660 double duration = getDuration(_presentationSwitch.get()); 661 661 if (duration>=0.0) … … 664 664 _timePerSlide = duration; 665 665 } 666 666 667 667 //selectSlide(0); 668 668 } … … 673 673 _presentationSwitch = 0; 674 674 _activeSlide = 0; 675 675 676 676 FindNamedSwitchVisitor findSlide("Slide"); 677 677 model->accept(findSlide); 678 678 679 679 if (findSlide._switch) 680 680 { … … 688 688 OSG_INFO<<"No slides present in scene, unable to operate as a slideshow."<<std::endl; 689 689 } 690 690 691 691 } 692 692 } … … 710 710 { 711 711 return duration; 712 } 713 } 714 712 } 713 } 714 715 715 return _timePerSlide; 716 716 } … … 758 758 { 759 759 double time = ea.time(); 760 760 761 761 if (_firstTraversal) 762 762 { … … 767 767 { 768 768 // _previousTime = time; 769 769 770 770 if (!_hold) 771 771 { … … 794 794 { 795 795 break; 796 } 797 796 } 797 798 798 _timeLastKeyPresses = time; 799 799 … … 852 852 return true; 853 853 } 854 else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Page_Down || 854 else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Page_Down || 855 855 ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Page_Down) 856 856 { … … 866 866 return true; 867 867 } 868 else if (ea.getKey()=='N' || 869 ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || 868 else if (ea.getKey()=='N' || 869 ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || 870 870 ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) 871 871 { … … 875 875 return true; 876 876 } 877 else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || 877 else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || 878 878 ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) 879 879 { … … 888 888 { 889 889 _pause = true; 890 #if 0 890 #if 0 891 891 resetUpdateCallbackActivity(ALL_OBJECTS); 892 892 #endif 893 893 _activeOperators.setPause(_pause); 894 894 } 895 896 return true; 897 895 896 return true; 897 898 898 } 899 899 else if (ea.getKey()=='o') … … 902 902 { 903 903 _pause = false; 904 #if 0 904 #if 0 905 905 resetUpdateCallbackActivity(ALL_OBJECTS); 906 906 #endif … … 908 908 } 909 909 return true; 910 910 911 911 } 912 912 else if (ea.getKey()=='h') … … 923 923 return true; 924 924 } 925 /* 925 /* 926 926 else if (ea.getKey()=='c') 927 927 { 928 928 _cursorOn = !_cursorOn; 929 929 930 930 for( unsigned int i = 0; i < _viewer->getCameraConfig()->getNumberOfCameras(); i++ ) 931 931 { … … 995 995 996 996 OSG_INFO<<"selectSlide("<<slideNum<<","<<layerNum<<")"<<std::endl; 997 997 998 998 if (slideNum>=static_cast<int>(_presentationSwitch->getNumChildren())) 999 999 { … … 1005 1005 slideNum = _presentationSwitch->getNumChildren()-1; 1006 1006 } 1007 1007 1008 1008 if (slideNum>=static_cast<int>(_presentationSwitch->getNumChildren())) return false; 1009 1009 … … 1019 1019 1020 1020 OSG_INFO<<"selectSlide("<<slideNum<<","<<layerNum<<") at time "<<osg::Timer::instance()->delta_s(_tickAtFirstSlideOrLayerChange, tick)<<" seconds, length ="<<osg::Timer::instance()->delta_s(_tickAtLastSlideOrLayerChange, tick)<<" seconds"<<std::endl; 1021 1021 1022 1022 _tickAtLastSlideOrLayerChange = tick; 1023 1023 1024 1024 // dectivate movies etc on current active slide. 1025 1025 bool newSlide = _activeSlide!=slideNum; … … 1037 1037 //OSG_INFO<<"Selected slide '"<<_presentationSwitch->getChild(_activeSlide)->getName()<<"'"<<std::endl; 1038 1038 1039 1039 1040 1040 FindNamedSwitchVisitor findSlide("Slide"); 1041 1041 _presentationSwitch->getChild(_activeSlide)->accept(findSlide); … … 1049 1049 result = selectLayer(layerNum); 1050 1050 1051 1051 1052 1052 } 1053 1053 else … … 1056 1056 updateOperators(); 1057 1057 } 1058 1058 1059 1059 1060 1060 // refersh the viewer. 1061 1061 //_viewer->getKeySwitchMatrixManipulator()->setMinimumDistance(0.001); 1062 1062 1063 1063 _viewer->getCameraManipulator()->setNode(_slideSwitch.get()); 1064 1064 1065 1065 _viewer->computeActiveCoordinateSystemNodePath(); 1066 1066 1067 1067 // resetUpdateCallbacks(ALL_OBJECTS); 1068 1068 1069 1069 bool _useSlideFilePaths = false; 1070 1070 if (_useSlideFilePaths) … … 1074 1074 _presentationSwitch->accept(ffpdv); 1075 1075 } 1076 1076 1077 1077 if (newSlide && _releaseAndCompileOnEachNewSlide) 1078 1078 { … … 1081 1081 1082 1082 return result; 1083 1083 1084 1084 } 1085 1085 … … 1102 1102 1103 1103 if (layerNum>=static_cast<int>(_slideSwitch->getNumChildren())) return false; 1104 1104 1105 1105 _activeLayer = layerNum; 1106 1106 _slideSwitch->setSingleChildOn(_activeLayer); … … 1144 1144 int newSlide = previousSlide + la->getSlideNum(); 1145 1145 int newLayer = previousLayer + la->getLayerNum(); 1146 if (newLayer<0) 1146 if (newLayer<0) 1147 1147 { 1148 1148 newLayer = 0; … … 1184 1184 { 1185 1185 la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer)); 1186 1186 1187 1187 if (la->requiresJump()) 1188 1188 { … … 1193 1193 int newSlide = previousSlide + la->getSlideNum(); 1194 1194 int newLayer = previousLayer + la->getLayerNum(); 1195 if (newLayer<0) 1195 if (newLayer<0) 1196 1196 { 1197 1197 newLayer = 0; … … 1268 1268 { 1269 1269 OSG_INFO<<"updateAlpha("<<x<<","<<y<<")"<<std::endl; 1270 1270 1271 1271 UpdateAlphaVisitor uav(modAlphaFunc, modMaterial, x,y); 1272 1272 if (_presentationSwitch.valid()) _presentationSwitch->accept(uav); … … 1312 1312 } 1313 1313 1314 } 1315 1314 } 1315 1316 1316 _compileSlideCallback->needCompile(_presentationSwitch->getChild(slideNum)); 1317 1317 1318 1318 } 1319 1319 … … 1323 1323 osgUtil::GLObjectsVisitor::RELEASE_STATE_ATTRIBUTES); 1324 1324 globjVisitor.setNodeMaskOverride(0xffffffff); 1325 1325 1326 1326 _presentationSwitch->getChild(slideNum)->accept(globjVisitor); 1327 1327 } … … 1333 1333 // reset the time of the last key press to ensure that the event is disgarded as a key repeat. 1334 1334 _timeLastKeyPresses = -1.0; 1335 1335 1336 1336 if (keyPosition._x!=FLT_MAX) 1337 1337 { … … 1339 1339 eq->getCurrentEventState()->setX(xRescaled); 1340 1340 } 1341 1341 1342 1342 if (keyPosition._y!=FLT_MAX) 1343 1343 { 1344 1344 float y = (eq->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS) ? 1345 1345 keyPosition._y : -keyPosition._y; 1346 1346 1347 1347 float yRescaled = eq->getCurrentEventState()->getYmin() + (y+1.0f)*0.5f*(eq->getCurrentEventState()->getYmax()-eq->getCurrentEventState()->getYmin()); 1348 1348 eq->getCurrentEventState()->setY(yRescaled);
