X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimation.cpp;h=744262d84781ae40e0b2c42b604b1b2badb516cf;hp=2f78d1eafad574b4d1c060a8209d0527309cc393;hb=19555043d70f972feedb89786fc24a2b83b4f7e9;hpb=89a1ada18430079896cfb28862e61bb32d66b8a0 diff --git a/source/animation.cpp b/source/animation.cpp index 2f78d1ea..744262d8 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -3,6 +3,7 @@ #include #include #include "animation.h" +#include "animationeventobserver.h" #include "armature.h" #include "error.h" #include "pose.h" @@ -71,6 +72,15 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtrkeyframes.begin()), + event_iter(animation->events.begin()), end(false) { } @@ -263,6 +274,24 @@ Animation::Iterator &Animation::Iterator::operator+=(const Time::TimeDelta &t) return *this; } +void Animation::Iterator::dispatch_events(AnimationEventObserver &observer) +{ + vector::const_iterator events_end = animation->events.end(); + if(end) + { + for(; event_iter!=events_end; ++event_iter) + observer.animation_event(0, event_iter->name, event_iter->value); + } + else if(event_iter!=events_end) + { + Time::TimeDelta t = time_since_keyframe; + if(iter->prev) + t += iter->prev->time; + for(; (event_iter!=events_end && event_iter->time<=t); ++event_iter) + observer.animation_event(0, event_iter->name, event_iter->value); + } +} + Matrix Animation::Iterator::get_matrix() const { if(!iter->prev) @@ -329,12 +358,48 @@ Animation::Loader::Loader(Animation &a, Collection &c): void Animation::Loader::init() { add("armature", &Animation::armature); + add("event", &Loader::event); + add("event", &Loader::event1i); + add("event", &Loader::event1f); + add("event", &Loader::event2f); + add("event", &Loader::event3f); + add("event", &Loader::event4f); add("interval", &Loader::interval); add("keyframe", &Loader::keyframe); add("keyframe", &Loader::keyframe_inline); add("looping", &Animation::looping); } +void Animation::Loader::event(const string &n) +{ + obj.add_event(current_time, n); +} + +void Animation::Loader::event1i(const string &n, int v) +{ + obj.add_event(current_time, n, v); +} + +void Animation::Loader::event1f(const string &n, float v) +{ + obj.add_event(current_time, n, v); +} + +void Animation::Loader::event2f(const string &n, float v0, float v1) +{ + obj.add_event(current_time, n, LinAl::Vector(v0, v1)); +} + +void Animation::Loader::event3f(const string &n, float v0, float v1, float v2) +{ + obj.add_event(current_time, n, Vector3(v0, v1, v2)); +} + +void Animation::Loader::event4f(const string &n, float v0, float v1, float v2, float v3) +{ + obj.add_event(current_time, n, Vector4(v0, v1, v2, v3)); +} + void Animation::Loader::keyframe(const string &n) { obj.add_keyframe(current_time, get_collection().get(n));