goat3d
diff src/xform_node.cc @ 95:da100bf13f7f
[goat3d] implemented animation loading
[goatview] working on the animation controls
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 19 May 2014 06:42:40 +0300 |
parents | 8ecaf9cd3ce7 |
children |
line diff
1.1 --- a/src/xform_node.cc Sun May 18 19:58:47 2014 +0300 1.2 +++ b/src/xform_node.cc Mon May 19 06:42:40 2014 +0300 1.3 @@ -90,6 +90,18 @@ 1.4 return parent; 1.5 } 1.6 1.7 +XFormNode *XFormNode::get_root() 1.8 +{ 1.9 + if(!parent) return this; 1.10 + return parent->get_root(); 1.11 +} 1.12 + 1.13 +const XFormNode *XFormNode::get_root() const 1.14 +{ 1.15 + if(!parent) return this; 1.16 + return parent->get_root(); 1.17 +} 1.18 + 1.19 void XFormNode::add_child(XFormNode *child) 1.20 { 1.21 if(!child || child == this) return; 1.22 @@ -203,6 +215,37 @@ 1.23 return anm_get_active_animation_name(anm); 1.24 } 1.25 1.26 +bool XFormNode::get_timeline_bounds(long *start, long *end) 1.27 +{ 1.28 + long node_start = LONG_MAX; 1.29 + long node_end = LONG_MIN; 1.30 + 1.31 + for(int i=0; i<3; i++) { 1.32 + int nkeys = get_key_count(i); 1.33 + if(nkeys > 0) { 1.34 + long tmp = get_key_time(i, 0); 1.35 + if(tmp < node_start) node_start = tmp; 1.36 + tmp = get_key_time(i, nkeys - 1); 1.37 + if(tmp > node_end) node_end = tmp; 1.38 + } 1.39 + } 1.40 + 1.41 + for(size_t i=0; i<children.size(); i++) { 1.42 + long cstart, cend; 1.43 + if(children[i]->get_timeline_bounds(&cstart, &cend)) { 1.44 + if(cstart < node_start) node_start = cstart; 1.45 + if(cend > node_end) node_end = cend; 1.46 + } 1.47 + } 1.48 + 1.49 + if(node_start != LONG_MAX) { 1.50 + *start = node_start; 1.51 + *end = node_end; 1.52 + return true; 1.53 + } 1.54 + return false; 1.55 +} 1.56 + 1.57 static const int track_type_base[] = {ANM_TRACK_POS_X, ANM_TRACK_ROT_X, ANM_TRACK_SCL_X}; 1.58 static const int track_type_nelem[] = {3, 4, 3}; 1.59