]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation.cpp
Check for armature mismatches in Animation
[libs/gl.git] / source / animation.cpp
index 1cfb533f94eb3cd901ecba9dc501d28433224a15..6c9e179dc749dc16642b5b755f6afd7e36fecf2b 100644 (file)
@@ -1,7 +1,6 @@
 #include <cmath>
 #include <msp/core/maputils.h>
 #include <msp/datafile/collection.h>
-#include <msp/time/units.h>
 #include "animation.h"
 #include "animationeventobserver.h"
 #include "armature.h"
@@ -24,6 +23,8 @@ Animation::~Animation()
 
 void Animation::set_armature(const Armature &a)
 {
+       if(!keyframes.empty() && &a!=armature)
+               throw invalid_operation("Animation::set_armature");
        armature = &a;
 }
 
@@ -65,9 +66,14 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtr<const KeyFra
                throw invalid_argument("Animation::add_keyframe");
        if(!keyframes.empty() && t<keyframes.back().time)
                throw invalid_argument("Animation::add_keyframe");
+       if(kf->get_pose() && armature && kf->get_pose()->get_armature()!=armature)
+               throw invalid_argument("Animation::add_keyframe");
 
        bool realloc = (keyframes.size()>=keyframes.capacity());
 
+       if(kf->get_pose() && !armature)
+               armature = kf->get_pose()->get_armature();
+
        keyframes.push_back(TimedKeyFrame());
        TimedKeyFrame &tkf = keyframes.back();
        tkf.time = t;
@@ -78,9 +84,10 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtr<const KeyFra
        if(realloc)
        {
                for(unsigned i=1; i<keyframes.size(); ++i)
-                       keyframes[i].prev = &keyframes[i-1];
+                       if(keyframes[i].prev)
+                               keyframes[i].prev = &keyframes[i-1];
        }
-       else if(keyframes.size()>1)
+       if(keyframes.size()>1 && t>(&tkf-1)->time)
                tkf.prev = &tkf-1;
 
        prepare_keyframe(tkf);