# HG changeset patch # User John Tsiombikas # Date 1388138372 -7200 # Node ID 7c593721547ff385a1ddc3fe2a15a62383d372d6 # Parent d9c8cd19c6066bb7572e9586bbb346c7e4ae81f0 integrated support for the multiple animation system of libanim diff -r d9c8cd19c606 -r 7c593721547f src/xform_node.cc --- a/src/xform_node.cc Sun Dec 08 03:00:49 2013 +0200 +++ b/src/xform_node.cc Fri Dec 27 11:59:32 2013 +0200 @@ -90,6 +90,77 @@ return 0; } + +void XFormNode::use_animation(int idx) +{ + if(idx >= 0) { + anm_use_animation(anm, idx); + } +} + +void XFormNode::use_animation(const char *name) +{ + anm_use_animation(anm, anm_find_animation(anm, name)); +} + +void XFormNode::use_animation(int aidx, int bidx, float t) +{ + anm_use_animations(anm, aidx, bidx, t); +} + +void XFormNode::use_animation(const char *aname, const char *bname, float t) +{ + int aidx = anm_find_animation(anm, aname); + int bidx = anm_find_animation(anm, bname); + + if(aidx == -1) { + use_animation(bidx); + } + if(bidx == -1) { + use_animation(aidx); + } + anm_use_animations(anm, aidx, bidx, t); +} + +int XFormNode::get_active_animation_index(int which) const +{ + return anm_get_active_animation_index(anm, which); +} + +float XFormNode::get_active_animation_mix() const +{ + return anm_get_active_animation_mix(anm); +} + +int XFormNode::get_animation_count() const +{ + return anm_get_animation_count(anm); +} + +void XFormNode::add_animation(const char *name) +{ + int idx = get_animation_count(); + + anm_add_animation(anm); + use_animation(idx); + + if(name) { + set_animation_name(name); + } +} + +void XFormNode::set_animation_name(const char *name) +{ + anm_set_active_animation_name(anm, name); +} + +const char *XFormNode::get_animation_name() const +{ + return anm_get_active_animation_name(anm); +} + + + void XFormNode::set_position(const Vector3 &pos, long tmsec) { anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec)); diff -r d9c8cd19c606 -r 7c593721547f src/xform_node.h --- a/src/xform_node.h Sun Dec 08 03:00:49 2013 +0200 +++ b/src/xform_node.h Fri Dec 27 11:59:32 2013 +0200 @@ -1,6 +1,3 @@ -/* -TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks) -*/ #ifndef XFORM_NODE_H_ #define XFORM_NODE_H_ @@ -18,7 +15,7 @@ enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC }; enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT }; -// XXX all time arguments are milliseconds +// NOTE: all time arguments are milliseconds class XFormNode { private: @@ -55,6 +52,24 @@ const XFormNode *get_child(int idx) const; + void use_animation(int idx); + void use_animation(const char *name); + void use_animation(int aidx, int bidx, float t); + void use_animation(const char *aname, const char *bname, float t); + + int get_active_animation_index(int which = 0) const; + float get_active_animation_mix() const; + + int get_animation_count() const; + + // add a new empty animation slot (recursive) + void add_animation(const char *name = 0); + + // set/get the current animation name (set is recursive) + void set_animation_name(const char *name); + const char *get_animation_name() const; + + void set_position(const Vector3 &pos, long tmsec = 0); Vector3 get_node_position(long tmsec = 0) const;