goat3dgfx

changeset 21:7c593721547f

integrated support for the multiple animation system of libanim
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Dec 2013 11:59:32 +0200
parents d9c8cd19c606
children 92bfb0206969
files src/xform_node.cc src/xform_node.h
diffstat 2 files changed, 90 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/src/xform_node.cc	Sun Dec 08 03:00:49 2013 +0200
     1.2 +++ b/src/xform_node.cc	Fri Dec 27 11:59:32 2013 +0200
     1.3 @@ -90,6 +90,77 @@
     1.4  	return 0;
     1.5  }
     1.6  
     1.7 +
     1.8 +void XFormNode::use_animation(int idx)
     1.9 +{
    1.10 +	if(idx >= 0) {
    1.11 +		anm_use_animation(anm, idx);
    1.12 +	}
    1.13 +}
    1.14 +
    1.15 +void XFormNode::use_animation(const char *name)
    1.16 +{
    1.17 +	anm_use_animation(anm, anm_find_animation(anm, name));
    1.18 +}
    1.19 +
    1.20 +void XFormNode::use_animation(int aidx, int bidx, float t)
    1.21 +{
    1.22 +	anm_use_animations(anm, aidx, bidx, t);
    1.23 +}
    1.24 +
    1.25 +void XFormNode::use_animation(const char *aname, const char *bname, float t)
    1.26 +{
    1.27 +	int aidx = anm_find_animation(anm, aname);
    1.28 +	int bidx = anm_find_animation(anm, bname);
    1.29 +
    1.30 +	if(aidx == -1) {
    1.31 +		use_animation(bidx);
    1.32 +	}
    1.33 +	if(bidx == -1) {
    1.34 +		use_animation(aidx);
    1.35 +	}
    1.36 +	anm_use_animations(anm, aidx, bidx, t);
    1.37 +}
    1.38 +
    1.39 +int XFormNode::get_active_animation_index(int which) const
    1.40 +{
    1.41 +	return anm_get_active_animation_index(anm, which);
    1.42 +}
    1.43 +
    1.44 +float XFormNode::get_active_animation_mix() const
    1.45 +{
    1.46 +	return anm_get_active_animation_mix(anm);
    1.47 +}
    1.48 +
    1.49 +int XFormNode::get_animation_count() const
    1.50 +{
    1.51 +	return anm_get_animation_count(anm);
    1.52 +}
    1.53 +
    1.54 +void XFormNode::add_animation(const char *name)
    1.55 +{
    1.56 +	int idx = get_animation_count();
    1.57 +
    1.58 +	anm_add_animation(anm);
    1.59 +	use_animation(idx);
    1.60 +
    1.61 +	if(name) {
    1.62 +		set_animation_name(name);
    1.63 +	}
    1.64 +}
    1.65 +
    1.66 +void XFormNode::set_animation_name(const char *name)
    1.67 +{
    1.68 +	anm_set_active_animation_name(anm, name);
    1.69 +}
    1.70 +
    1.71 +const char *XFormNode::get_animation_name() const
    1.72 +{
    1.73 +	return anm_get_active_animation_name(anm);
    1.74 +}
    1.75 +
    1.76 +
    1.77 +
    1.78  void XFormNode::set_position(const Vector3 &pos, long tmsec)
    1.79  {
    1.80  	anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec));
     2.1 --- a/src/xform_node.h	Sun Dec 08 03:00:49 2013 +0200
     2.2 +++ b/src/xform_node.h	Fri Dec 27 11:59:32 2013 +0200
     2.3 @@ -1,6 +1,3 @@
     2.4 -/*
     2.5 -TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks)
     2.6 -*/
     2.7  #ifndef XFORM_NODE_H_
     2.8  #define XFORM_NODE_H_
     2.9  
    2.10 @@ -18,7 +15,7 @@
    2.11  enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
    2.12  enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
    2.13  
    2.14 -// XXX all time arguments are milliseconds
    2.15 +// NOTE: all time arguments are milliseconds
    2.16  
    2.17  class XFormNode {
    2.18  private:
    2.19 @@ -55,6 +52,24 @@
    2.20  	const XFormNode *get_child(int idx) const;
    2.21  
    2.22  
    2.23 +	void use_animation(int idx);
    2.24 +	void use_animation(const char *name);
    2.25 +	void use_animation(int aidx, int bidx, float t);
    2.26 +	void use_animation(const char *aname, const char *bname, float t);
    2.27 +
    2.28 +	int get_active_animation_index(int which = 0) const;
    2.29 +	float get_active_animation_mix() const;
    2.30 +
    2.31 +	int get_animation_count() const;
    2.32 +
    2.33 +	// add a new empty animation slot (recursive)
    2.34 +	void add_animation(const char *name = 0);
    2.35 +
    2.36 +	// set/get the current animation name (set is recursive)
    2.37 +	void set_animation_name(const char *name);
    2.38 +	const char *get_animation_name() const;
    2.39 +
    2.40 +
    2.41  	void set_position(const Vector3 &pos, long tmsec = 0);
    2.42  	Vector3 get_node_position(long tmsec = 0) const;
    2.43