- Timestamp:
- 12/16/08 21:29:00 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osganimationtimeline/osganimationtimeline.cpp
r9151 r9370 30 30 #include <osgAnimation/Timeline> 31 31 #include <osgAnimation/AnimationManagerBase> 32 #include <osgAnimation/TimelineAnimationManager> 32 33 33 34 … … 55 56 osg::ref_ptr<osgAnimation::StripAnimation> _scratchHead; 56 57 osg::ref_ptr<osgAnimation::StripAnimation> _scratchNose; 57 osg::ref_ptr<osgAnimation:: AnimationManagerTimeline> _manager;58 osg::ref_ptr<osgAnimation::TimelineAnimationManager> _manager; 58 59 59 60 bool _releaseKey; 60 61 61 ExampleTimelineUsage(osgAnimation:: AnimationManagerTimeline* manager)62 ExampleTimelineUsage(osgAnimation::TimelineAnimationManager* manager) 62 63 { 63 64 _releaseKey = false; 64 65 _manager = manager; 65 66 66 osgAnimation::AnimationMap map = _manager->getAnimationMap(); 67 const osgAnimation::AnimationList& list = _manager->getAnimationList(); 68 osgAnimation::AnimationMap map; 69 for (osgAnimation::AnimationList::const_iterator it = list.begin(); it != list.end(); it++) 70 map[(*it)->getName()] = *it; 71 67 72 _mainLoop = new osgAnimation::StripAnimation(map["Idle_Main"].get(),0.0,0.0); 68 73 _mainLoop->setLoop(0); // means forever … … 158 163 159 164 osgViewer::Viewer viewer(psr); 160 osg::ref_ptr<osg::Group> group = new osg::Group();161 165 162 166 std::string file = "osgAnimation/nathan.osg"; … … 165 169 166 170 // replace the manager 167 osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(osgDB::readNodeFile(file)); 171 osg::Group* root = dynamic_cast<osg::Group*>(osgDB::readNodeFile(file)); 172 osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback()); 168 173 if(!animationManager) 169 174 { 170 std::cerr << " Couldn't convert the file's toplevel object into an AnimationManager." << std::endl;175 std::cerr << "Did not found AnimationManagerBase updateCallback needed to animate elements" << std::endl; 171 176 return 1; 172 177 } 173 178 174 osg::ref_ptr<osgAnimation::AnimationManagerTimeline> tl = new osgAnimation::AnimationManagerTimeline(*animationManager); 175 176 animationManager->removeChildren(0, animationManager->getNumChildren()); 179 osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager); 180 root->setUpdateCallback(tl); 177 181 ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get()); 178 group->addChild(tl.get());179 group->setEventCallback(callback);180 group->setUpdateCallback(callback);182 root->setEventCallback(callback); 183 root->getUpdateCallback()->addNestedCallback(callback); 184 181 185 182 186 … … 202 206 viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); 203 207 204 viewer.setSceneData( group.get());208 viewer.setSceneData(root); 205 209 206 210 return viewer.run();
