float time,
mdl_keyframe *output )
{
- float animtime = time*anim->rate;
+ f32 animtime = fmodf( time*anim->rate, anim->length ),
+ animframe = floorf( animtime ),
+ t = animtime - animframe;
- u32 frame = ((u32)animtime) % anim->length,
+ u32 frame = (u32)animframe % anim->length,
next = (frame+1) % anim->length;
- float t = vg_fractf( animtime );
-
mdl_keyframe *base = anim->anim_data + (skele->bone_count-1)*frame,
*nbase = anim->anim_data + (skele->bone_count-1)*next;
{
k_anim_apply_always,
k_anim_apply_defer_ik,
- k_anim_apply_deffered_only
+ k_anim_apply_deffered_only,
+ k_anim_apply_absolute
}
anim_apply;
VG_STATIC void skeleton_apply_pose( struct skeleton *skele, mdl_keyframe *pose,
anim_apply passtype )
{
+ if( passtype == k_anim_apply_absolute ){
+ for( u32 i=1; i<skele->bone_count; i++ ){
+ mdl_keyframe *kf = &pose[i-1];
+
+ v3f *posemtx = skele->final_mtx[i];
+
+ q_m3x3( kf->q, posemtx );
+ v3_copy( kf->co, posemtx[3] );
+ }
+ return;
+ }
+
m4x3_identity( skele->final_mtx[0] );
skele->bones[0].defer = 0;
skele->bones[0].flags &= ~k_bone_flag_ik;
}
}
+/*
+ * Take the final matrices and decompose it into an absolute positioned anim
+ */
+VG_STATIC void skeleton_decompose_mtx_absolute( struct skeleton *skele,
+ mdl_keyframe *anim ){
+ for( u32 i=1; i<skele->bone_count; i++ ){
+ struct skeleton_bone *sb = &skele->bones[i];
+ mdl_keyframe *kf = &anim[i-1];
+ m4x3_decompose( skele->final_mtx[i], kf->co, kf->q, kf->s );
+ }
+}
+
/*
* creates the reference inverse matrix for an IK bone, as it has an initial
* intrisic rotation based on the direction that the IK is setup..