X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skeleton.h;h=2be9a9aaff7ac7bd8945f9b5e37ed5d0ca0ff7ff;hb=14b3d5c13faab36bd37ae27aa8c1501ba7146f89;hp=052975239bd6988290a2c731b8d4d4565fdc4b7a;hpb=aed3995840d5472275b7bf143efed7c4f9daa358;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skeleton.h b/skeleton.h index 0529752..2be9a9a 100644 --- a/skeleton.h +++ b/skeleton.h @@ -134,13 +134,13 @@ VG_STATIC void skeleton_sample_anim( struct skeleton *skele, 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; @@ -165,7 +165,8 @@ typedef enum anim_apply { 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; @@ -203,6 +204,18 @@ int should_apply_bone( struct skeleton *skele, u32 id, anim_apply type ) 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; ibone_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; @@ -233,6 +246,18 @@ VG_STATIC void skeleton_apply_pose( struct skeleton *skele, mdl_keyframe *pose, } } +/* + * 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; ibone_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..