goat3d

diff src/xform_node.cc @ 47:498ca7ac7047

- placed all the implementation stuff in the g3dimpl namespace - added animation stuff to the public API - started writing animation saving/loading
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Dec 2013 06:47:39 +0200
parents 0fe02696fb1e
children 9ef9de80649c
line diff
     1.1 --- a/src/xform_node.cc	Sun Dec 08 03:00:25 2013 +0200
     1.2 +++ b/src/xform_node.cc	Sat Dec 28 06:47:39 2013 +0200
     1.3 @@ -1,8 +1,10 @@
     1.4  #include <assert.h>
     1.5  #include <algorithm>
     1.6  #include "xform_node.h"
     1.7 -#include "anim.h"
     1.8 -#include "track.h"
     1.9 +#include "anim/anim.h"
    1.10 +#include "anim/track.h"
    1.11 +
    1.12 +using namespace g3dimpl;
    1.13  
    1.14  static inline anm_interpolator track_interpolator(Interp in);
    1.15  static inline anm_extrapolator track_extrapolator(Extrap ex);
    1.16 @@ -11,8 +13,11 @@
    1.17  {
    1.18  	anm = new anm_node;
    1.19  	anm_init_node(anm);
    1.20 +	parent = 0;
    1.21  
    1.22 -	parent = 0;
    1.23 +	// TODO read them from anm to get the correct initial values
    1.24 +	interp = INTERP_LINEAR;
    1.25 +	extrap = EXTRAP_EXTEND;
    1.26  }
    1.27  
    1.28  XFormNode::~XFormNode()
    1.29 @@ -21,6 +26,11 @@
    1.30  	delete anm;
    1.31  }
    1.32  
    1.33 +struct anm_node *XFormNode::get_libanim_node() const
    1.34 +{
    1.35 +	return anm;
    1.36 +}
    1.37 +
    1.38  void XFormNode::set_name(const char *name)
    1.39  {
    1.40  	anm_set_node_name(anm, name);
    1.41 @@ -53,6 +63,16 @@
    1.42  	return extrap;
    1.43  }
    1.44  
    1.45 +XFormNode *XFormNode::get_parent()
    1.46 +{
    1.47 +	return parent;
    1.48 +}
    1.49 +
    1.50 +const XFormNode *XFormNode::get_parent() const
    1.51 +{
    1.52 +	return parent;
    1.53 +}
    1.54 +
    1.55  void XFormNode::add_child(XFormNode *child)
    1.56  {
    1.57  	children.push_back(child);
    1.58 @@ -67,8 +87,11 @@
    1.59  	if(it != children.end()) {
    1.60  		children.erase(it);
    1.61  		anm_unlink_node(anm, child->anm);
    1.62 +
    1.63 +		if(child->parent == this) {
    1.64 +			child->parent = 0;
    1.65 +		}
    1.66  	}
    1.67 -	child->parent = 0;
    1.68  }
    1.69  
    1.70  int XFormNode::get_children_count() const
    1.71 @@ -92,11 +115,77 @@
    1.72  	return 0;
    1.73  }
    1.74  
    1.75 -XFormNode *XFormNode::get_parent() const
    1.76 +
    1.77 +void XFormNode::use_animation(int idx)
    1.78  {
    1.79 -	return parent;
    1.80 +	if(idx >= 0) {
    1.81 +		anm_use_animation(anm, idx);
    1.82 +	}
    1.83  }
    1.84  
    1.85 +void XFormNode::use_animation(const char *name)
    1.86 +{
    1.87 +	anm_use_animation(anm, anm_find_animation(anm, name));
    1.88 +}
    1.89 +
    1.90 +void XFormNode::use_animation(int aidx, int bidx, float t)
    1.91 +{
    1.92 +	anm_use_animations(anm, aidx, bidx, t);
    1.93 +}
    1.94 +
    1.95 +void XFormNode::use_animation(const char *aname, const char *bname, float t)
    1.96 +{
    1.97 +	int aidx = anm_find_animation(anm, aname);
    1.98 +	int bidx = anm_find_animation(anm, bname);
    1.99 +
   1.100 +	if(aidx == -1) {
   1.101 +		use_animation(bidx);
   1.102 +	}
   1.103 +	if(bidx == -1) {
   1.104 +		use_animation(aidx);
   1.105 +	}
   1.106 +	anm_use_animations(anm, aidx, bidx, t);
   1.107 +}
   1.108 +
   1.109 +int XFormNode::get_active_animation_index(int which) const
   1.110 +{
   1.111 +	return anm_get_active_animation_index(anm, which);
   1.112 +}
   1.113 +
   1.114 +float XFormNode::get_active_animation_mix() const
   1.115 +{
   1.116 +	return anm_get_active_animation_mix(anm);
   1.117 +}
   1.118 +
   1.119 +int XFormNode::get_animation_count() const
   1.120 +{
   1.121 +	return anm_get_animation_count(anm);
   1.122 +}
   1.123 +
   1.124 +void XFormNode::add_animation(const char *name)
   1.125 +{
   1.126 +	int idx = get_animation_count();
   1.127 +
   1.128 +	anm_add_animation(anm);
   1.129 +	use_animation(idx);
   1.130 +
   1.131 +	if(name) {
   1.132 +		set_animation_name(name);
   1.133 +	}
   1.134 +}
   1.135 +
   1.136 +void XFormNode::set_animation_name(const char *name)
   1.137 +{
   1.138 +	anm_set_active_animation_name(anm, name);
   1.139 +}
   1.140 +
   1.141 +const char *XFormNode::get_animation_name() const
   1.142 +{
   1.143 +	return anm_get_active_animation_name(anm);
   1.144 +}
   1.145 +
   1.146 +
   1.147 +
   1.148  void XFormNode::set_position(const Vector3 &pos, long tmsec)
   1.149  {
   1.150  	anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec));