| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgAnimation/BasicAnimationManager> |
|---|
| 16 | #include <osgAnimation/LinkVisitor> |
|---|
| 17 | |
|---|
| 18 | using namespace osgAnimation; |
|---|
| 19 | |
|---|
| 20 | BasicAnimationManager::BasicAnimationManager() |
|---|
| 21 | : _lastUpdate(0.0) |
|---|
| 22 | { |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | BasicAnimationManager::BasicAnimationManager(const AnimationManagerBase& b, const osg::CopyOp& copyop) |
|---|
| 26 | : AnimationManagerBase(b,copyop) |
|---|
| 27 | , _lastUpdate(0.0) |
|---|
| 28 | { |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | BasicAnimationManager::~BasicAnimationManager() |
|---|
| 32 | { |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void BasicAnimationManager::stopAll() |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim ) |
|---|
| 39 | { |
|---|
| 40 | AnimationList& list = iterAnim->second; |
|---|
| 41 | for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) |
|---|
| 42 | (*it)->resetTargets(); |
|---|
| 43 | } |
|---|
| 44 | _animationsPlaying.clear(); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void BasicAnimationManager::playAnimation(Animation* pAnimation, int priority, float weight) |
|---|
| 48 | { |
|---|
| 49 | if (!findAnimation(pAnimation)) |
|---|
| 50 | return; |
|---|
| 51 | |
|---|
| 52 | if ( isPlaying(pAnimation) ) |
|---|
| 53 | stopAnimation(pAnimation); |
|---|
| 54 | |
|---|
| 55 | _animationsPlaying[priority].push_back(pAnimation); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | pAnimation->setStartTime(_lastUpdate); |
|---|
| 59 | pAnimation->setWeight(weight); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | bool BasicAnimationManager::stopAnimation(Animation* pAnimation) |
|---|
| 63 | { |
|---|
| 64 | |
|---|
| 65 | for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim ) |
|---|
| 66 | { |
|---|
| 67 | AnimationList& list = iterAnim->second; |
|---|
| 68 | for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) |
|---|
| 69 | if( (*it) == pAnimation ) |
|---|
| 70 | { |
|---|
| 71 | (*it)->resetTargets(); |
|---|
| 72 | list.erase(it); |
|---|
| 73 | return true; |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | return false; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | void BasicAnimationManager::update (double time) |
|---|
| 81 | { |
|---|
| 82 | _lastUpdate = time; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it) |
|---|
| 86 | (*it).get()->reset(); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | for( AnimationLayers::reverse_iterator iterAnim = _animationsPlaying.rbegin(); iterAnim != _animationsPlaying.rend(); ++iterAnim ) |
|---|
| 90 | { |
|---|
| 91 | |
|---|
| 92 | std::vector<int> toremove; |
|---|
| 93 | int priority = iterAnim->first; |
|---|
| 94 | AnimationList& list = iterAnim->second; |
|---|
| 95 | for (unsigned int i = 0; i < list.size(); i++) |
|---|
| 96 | { |
|---|
| 97 | if (! list[i]->update(time, priority)) |
|---|
| 98 | { |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | toremove.push_back(i); |
|---|
| 102 | } else |
|---|
| 103 | { |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | while (!toremove.empty()) |
|---|
| 111 | { |
|---|
| 112 | list.erase(list.begin() + toremove.back()); |
|---|
| 113 | toremove.pop_back(); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | bool BasicAnimationManager::findAnimation(Animation* pAnimation) |
|---|
| 120 | { |
|---|
| 121 | for( AnimationList::const_iterator iterAnim = _animations.begin(); iterAnim != _animations.end(); ++iterAnim ) |
|---|
| 122 | { |
|---|
| 123 | if ( (*iterAnim) == pAnimation ) |
|---|
| 124 | return true; |
|---|
| 125 | } |
|---|
| 126 | return false; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | bool BasicAnimationManager::isPlaying(Animation* pAnimation) |
|---|
| 131 | { |
|---|
| 132 | for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim ) |
|---|
| 133 | { |
|---|
| 134 | AnimationList& list = iterAnim->second; |
|---|
| 135 | for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) |
|---|
| 136 | if ( (*it) == pAnimation ) |
|---|
| 137 | return true; |
|---|
| 138 | } |
|---|
| 139 | return false; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | bool BasicAnimationManager::isPlaying(const std::string& name) |
|---|
| 143 | { |
|---|
| 144 | |
|---|
| 145 | for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim ) |
|---|
| 146 | { |
|---|
| 147 | AnimationList& list = iterAnim->second; |
|---|
| 148 | for (AnimationList::iterator it = list.begin(); it != list.end(); ++it) |
|---|
| 149 | if ( (*it)->getName() == name ) |
|---|
| 150 | return true; |
|---|
| 151 | } |
|---|
| 152 | return false; |
|---|
| 153 | } |
|---|