goat3d
diff src/xform_node.cc @ 48:9ef9de80649c
implemented animation track XML saving
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 29 Dec 2013 06:01:59 +0200 |
parents | 498ca7ac7047 |
children | dad392c710df 3751aabbc5b3 |
line diff
1.1 --- a/src/xform_node.cc Sat Dec 28 06:47:39 2013 +0200 1.2 +++ b/src/xform_node.cc Sun Dec 29 06:01:59 2013 +0200 1.3 @@ -184,7 +184,84 @@ 1.4 return anm_get_active_animation_name(anm); 1.5 } 1.6 1.7 +static const int track_type_base[] = {ANM_TRACK_POS_X, ANM_TRACK_ROT_X, ANM_TRACK_SCL_X}; 1.8 +static const int track_type_nelem[] = {3, 4, 3}; 1.9 1.10 +int XFormNode::get_key_count(int trackid) const 1.11 +{ 1.12 + struct anm_animation *anim = anm_get_active_animation(anm, 0); 1.13 + return anim->tracks[track_type_base[trackid]].count; 1.14 +} 1.15 + 1.16 +int XFormNode::get_position_key_count() const 1.17 +{ 1.18 + return get_key_count(POSITION_TRACK); 1.19 +} 1.20 + 1.21 +int XFormNode::get_rotation_key_count() const 1.22 +{ 1.23 + return get_key_count(ROTATION_TRACK); 1.24 +} 1.25 + 1.26 +int XFormNode::get_scaling_key_count() const 1.27 +{ 1.28 + return get_key_count(SCALING_TRACK); 1.29 +} 1.30 + 1.31 +long XFormNode::get_key_time(int trackid, int idx) const 1.32 +{ 1.33 + struct anm_animation *anim = anm_get_active_animation(anm, 0); 1.34 + struct anm_keyframe *key = anm_get_keyframe(anim->tracks + track_type_base[trackid], idx); 1.35 + return ANM_TM2MSEC(key->time); 1.36 +} 1.37 + 1.38 +long XFormNode::get_position_key_time(int idx) const 1.39 +{ 1.40 + return get_key_time(POSITION_TRACK, idx); 1.41 +} 1.42 + 1.43 +long XFormNode::get_rotation_key_time(int idx) const 1.44 +{ 1.45 + return get_key_time(ROTATION_TRACK, idx); 1.46 +} 1.47 + 1.48 +long XFormNode::get_scaling_key_time(int idx) const 1.49 +{ 1.50 + return get_key_time(SCALING_TRACK, idx); 1.51 +} 1.52 + 1.53 +int XFormNode::get_key_value(int trackid, int idx, float *val) const 1.54 +{ 1.55 + struct anm_animation *anim = anm_get_active_animation(anm, 0); 1.56 + 1.57 + int nelem = track_type_nelem[trackid]; 1.58 + for(int i=0; i<nelem; i++) { 1.59 + struct anm_keyframe *key = anm_get_keyframe(anim->tracks + track_type_base[trackid] + i, idx); 1.60 + val[i] = key->val; 1.61 + } 1.62 + return nelem; 1.63 +} 1.64 + 1.65 +Vector3 XFormNode::get_position_key_value(int idx) const 1.66 +{ 1.67 + float val[3]; 1.68 + get_key_value(POSITION_TRACK, idx, val); 1.69 + return Vector3(val[0], val[1], val[2]); 1.70 +} 1.71 + 1.72 +Quaternion XFormNode::get_rotation_key_value(int idx) const 1.73 +{ 1.74 + float val[4]; 1.75 + get_key_value(ROTATION_TRACK, idx, val); 1.76 + return Quaternion(val[3], val[0], val[1], val[2]); 1.77 +} 1.78 + 1.79 +Vector3 XFormNode::get_scaling_key_value(int idx) const 1.80 +{ 1.81 + float val[3]; 1.82 + get_key_value(SCALING_TRACK, idx, val); 1.83 + return Vector3(val[0], val[1], val[2]); 1.84 +} 1.85 1.86 void XFormNode::set_position(const Vector3 &pos, long tmsec) 1.87 {