mrmoment / min3d

Automatically exported from code.google.com/p/min3d
0 stars 0 forks source link

Keyframe animation does not reset on call to stop() (FIX included) #25

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Calling play() on an AnimatedObject3d and then stop() results in the animated 
object being paused, rather than reset to it's default stance. If you call the 
Ogre 'run' action for example and then stop it half way through, the ogre is 
paused mid-step.

The stop() function looks like it is attempting to reset the animation (i.e. 
currentFrame = 0) but the vertices are never reset to match in the update 
method because isPlaying is now false.

My (maybe crude) fix to this was to introduce a flag called 'isResetNeeded'. 
This is set to true when stop is called. The update method then checks this 
flag to see if it needs to reset the vertices.

So, in AnimationObject3d I have:

    public void stop() {
        isPlaying = false;
        currentFrameIndex = 0;
        isResetNeeded = true;
    }

And:

    public void update() {

        if (isResetNeeded) {
            KeyFrame currentFrame = frames[currentFrameIndex];
            vertices().overwriteNormals(currentFrame.getNormals());
            vertices().overwriteVerts(currentFrame.getVertices());
            isResetNeeded = false;
            return;
        }

        if (!isPlaying || !updateVertices) {
            return;
        }

        // ... rest of update method exactly as before ...
    }

Enjoy, 
zonski

Original issue reported on code.google.com by zonski on 13 Dec 2010 at 11:17