X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanimation.cpp;h=37f583d5ec53b43324e67f7fcd1237a25bbefa80;hb=39488946c441f4007396e438f522609a8b2943ce;hp=0d0ce75e951176dc3444b29c1b231b7f8c530735;hpb=553f3ec4fbe28a37978ee53b9b6e22fedb691e1d;p=libs%2Fgl.git diff --git a/source/animation.cpp b/source/animation.cpp index 0d0ce75e..37f583d5 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -50,6 +50,12 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame &kf) create_curves(); } +void Animation::add_keyframe_owned(const Time::TimeDelta &t, const KeyFrame *kf) +{ + add_keyframe(t, kf, false, true); + create_curves(); +} + void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame &kf, float slope) { add_keyframe(t, &kf, slope, slope, false); @@ -70,6 +76,14 @@ void Animation::add_control_keyframe(const KeyFrame &kf) add_keyframe(keyframes.back().time, &kf, true, false); } +void Animation::add_control_keyframe_owned(const KeyFrame *kf) +{ + if(keyframes.empty()) + throw invalid_operation("Animation::add_control_keyframe_owned"); + + add_keyframe(keyframes.back().time, kf, true, true); +} + void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, float ss, float es, bool owned) { if(keyframes.empty()) @@ -220,6 +234,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) { @@ -232,14 +247,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; } @@ -304,7 +319,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 @@ -358,7 +373,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); }