X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanimation.cpp;h=94c96809214215aa890797a24a9c774ff0401f74;hb=d42c443d24a8e428c43f849b218c9e1a1dca4189;hp=0e4bd3e6ff26c26a4e4b7204c487fa6715148be7;hpb=f88bce7df357cf12ce20b7dc8c7d179d2ae95920;p=libs%2Fgl.git diff --git a/source/animation.cpp b/source/animation.cpp index 0e4bd3e6..94c96809 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -18,9 +18,11 @@ Animation::Animation(): looping(false) { } -// Avoid synthesizing ~RefPtr in files including animation.h Animation::~Animation() -{ } +{ + for(vector::iterator i=curves.begin(); i!=curves.end(); ++i) + delete *i; +} void Animation::set_armature(const Armature &a) { @@ -234,6 +236,7 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract typename Interpolate::SplineValue::Type value; if(extract(*i->keyframe, value)) { + typename Knot::Value dvalue = value; float x = i->time/Time::sec; if(i->control) { @@ -246,14 +249,14 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract if(n_control==1) { typename Knot::Value cv = knots.back().y; - knots.back().y = (knots[knots.size()-2].y+cv*2.0f)/3.0f; - knots.push_back(Knot(x, (value+cv*2.0f)/3.0f)); + knots.back().y = (knots[knots.size()-2].y+cv*2.0)/3.0; + knots.push_back(Knot(x, (dvalue+cv*2.0)/3.0)); } else if(n_control==0 && !knots.empty()) { typename Knot::Value prev = knots.back().y; - knots.push_back(Knot(knots.back().x, (prev*2.0f+value)/3.0f)); - knots.push_back(Knot(x, (prev+value*2.0f)/3.0f)); + knots.push_back(Knot(knots.back().x, (prev*2.0+dvalue)/3.0)); + knots.push_back(Knot(x, (prev+dvalue*2.0)/3.0)); } n_control = 0; } @@ -264,6 +267,14 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract while(n_control--) knots.pop_back(); + if(knots.size()==1) + { + knots.push_back(knots.back()); + knots.push_back(knots.back()); + knots.back().x += 1; + knots.push_back(knots.back()); + } + curves.push_back(new ValueCurve(target, component, knots)); } @@ -318,7 +329,7 @@ Animation::Curve::Curve(CurveTarget t, int c): template Animation::ValueCurve::ValueCurve(CurveTarget t, int c, const vector &k): Curve(t, c), - spline(Interpolate::BezierSpline(k)) + spline(Interpolate::BezierSpline(k)) { } template @@ -372,7 +383,7 @@ template void Animation::ValueCurve::apply(float x, KeyFrame::AnimatedUniform &uni) const { uni.size = N; - typename Interpolate::Spline::Value value = spline(x); + typename Interpolate::Spline::Value value = spline(x); for(unsigned i=0; i::get(value, i); }