Sign in to follow this  
DaveMS

Ogre AnimationState iterator

Recommended Posts

Hi, I using Ogre, and want to iterate through the enabled AnimationStates in a AnimationStateSet, and add time to them. Seems simple enough, but i'm doing it as so...
while(it->second->getEnabledAnimationStateIterator().hasMoreElements())
   it->second->getEnabledAnimationStateIterator().getNext()->addTime(0.3f);

it->second is pointing to an AnimationStateSet. I grab an iterator to iterate through all the enabled AnimationStates, check if there are more elements, and grab the next element. I then add time to it, and check if there is a next one, and so on... I'm getting stuck in an infinite loop though, so i'm guessing the .hasMoreElements() method of the iterator doesn't stop when it reaches the end of the AnimationStateSet, but loops around to the beginning and starts again. Anyone got any ideas how to iterate through all the AnimationStates of an AnimationStateSet until the last one is reached?

Share this post


Link to post
Share on other sites
No worries, I've found the problem.


while(it->second->getEnabledAnimationStateIterator().hasMoreElements())
it->second->getEnabledAnimationStateIterator().getNext()->addTime(0.3f);




getEnabledAnimationStateIterator() will obviously get a new iterator starting from the beginning of the set.

So, i've been getting a new iterator from the beginning every time I request it.

I needed to keep hold of the iterator, and now it's working fine.


Ogre::ConstEnabledAnimationStateIterator asit = it->second->getEnabledAnimationStateIterator();

while(asit.hasMoreElements())
asit.getNext()->addTime(0.3f);



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this