Пример #1
0
void SSBoneFrame_Update(struct ss_bone_frame_s *bf, float time)
{
    float t = 1.0f - bf->animations.lerp;
    ss_bone_tag_p btag = bf->bone_tags;
    bone_tag_p src_btag, next_btag;
    bone_frame_p prev_bf = &bf->animations.prev_bf;
    bone_frame_p curr_bf = &bf->animations.current_bf;
    
    vec3_interpolate_macro(bf->bb_max, prev_bf->bb_max, curr_bf->bb_max, bf->animations.lerp, t);
    vec3_interpolate_macro(bf->bb_min, prev_bf->bb_min, curr_bf->bb_min, bf->animations.lerp, t);
    vec3_interpolate_macro(bf->centre, prev_bf->centre, curr_bf->centre, bf->animations.lerp, t);
    vec3_interpolate_macro(bf->pos, prev_bf->pos, curr_bf->pos, bf->animations.lerp, t);
    
    next_btag = curr_bf->bone_tags;
    src_btag = prev_bf->bone_tags;
    for(uint16_t k = 0; k < prev_bf->bone_tag_count; k++, btag++, src_btag++, next_btag++)
    {
        vec3_interpolate_macro(btag->offset, src_btag->offset, next_btag->offset, bf->animations.lerp, t);
        vec3_copy(btag->local_transform + 12, btag->offset);
        btag->local_transform[15] = 1.0f;
        if(k == 0)
        {
            vec3_add(btag->local_transform + 12, btag->local_transform + 12, bf->pos);
            vec4_slerp(btag->qrotate, src_btag->qrotate, next_btag->qrotate, bf->animations.lerp);
        }
        else
        {
            bone_tag_p ov_src_btag = src_btag;
            bone_tag_p ov_next_btag = next_btag;
            float ov_lerp = bf->animations.lerp;
            if(btag->alt_anim && btag->alt_anim->model && btag->alt_anim->enabled && (btag->alt_anim->model->mesh_tree[k].replace_anim != 0))
            {
                bone_frame_p ov_curr_bf = &btag->alt_anim->prev_bf;
                bone_frame_p ov_next_bf = &btag->alt_anim->current_bf;
                ov_lerp = btag->alt_anim->lerp;
                ov_src_btag = ov_curr_bf->bone_tags + k;
                ov_next_btag = ov_next_bf->bone_tags + k;
            }
            vec4_slerp(btag->qrotate, ov_src_btag->qrotate, ov_next_btag->qrotate, ov_lerp);
        }
        Mat4_set_qrotation(btag->local_transform, btag->qrotate);
    }

    /*
     * build absolute coordinate matrix system
     */
    btag = bf->bone_tags;
    Mat4_Copy(btag->current_transform, btag->local_transform);
    btag++;
    for(uint16_t k = 1; k < prev_bf->bone_tag_count; k++, btag++)
    {
        Mat4_Mat4_mul(btag->current_transform, btag->parent->current_transform, btag->local_transform);
        SSBoneFrame_TargetBoneToSlerp(bf, btag, time);
    }
}
Пример #2
0
void SSBoneFrame_Update(struct ss_bone_frame_s *bf)
{
    float cmd_tr[3], tr[3], t;
    ss_bone_tag_p btag = bf->bone_tags;
    bone_tag_p src_btag, next_btag;
    skeletal_model_p model = bf->animations.model;
    bone_frame_p curr_bf, next_bf;

    next_bf = model->animations[bf->animations.next_animation].frames + bf->animations.next_frame;
    curr_bf = model->animations[bf->animations.current_animation].frames + bf->animations.current_frame;

    t = 1.0 - bf->animations.lerp;
    if(bf->transform && (curr_bf->command & ANIM_CMD_MOVE))
    {
        Mat4_vec3_rot_macro(tr, bf->transform, curr_bf->move);
        vec3_mul_scalar(cmd_tr, tr, bf->animations.lerp);
    }
    else
    {
        vec3_set_zero(tr);
        vec3_set_zero(cmd_tr);
    }

    vec3_interpolate_macro(bf->bb_max, curr_bf->bb_max, next_bf->bb_max, bf->animations.lerp, t);
    vec3_add(bf->bb_max, bf->bb_max, cmd_tr);
    vec3_interpolate_macro(bf->bb_min, curr_bf->bb_min, next_bf->bb_min, bf->animations.lerp, t);
    vec3_add(bf->bb_min, bf->bb_min, cmd_tr);
    vec3_interpolate_macro(bf->centre, curr_bf->centre, next_bf->centre, bf->animations.lerp, t);
    vec3_add(bf->centre, bf->centre, cmd_tr);

    vec3_interpolate_macro(bf->pos, curr_bf->pos, next_bf->pos, bf->animations.lerp, t);
    vec3_add(bf->pos, bf->pos, cmd_tr);
    next_btag = next_bf->bone_tags;
    src_btag = curr_bf->bone_tags;
    for(uint16_t k = 0; k < curr_bf->bone_tag_count; k++, btag++, src_btag++, next_btag++)
    {
        vec3_interpolate_macro(btag->offset, src_btag->offset, next_btag->offset, bf->animations.lerp, t);
        vec3_copy(btag->transform+12, btag->offset);
        btag->transform[15] = 1.0;
        if(k == 0)
        {
            vec3_add(btag->transform+12, btag->transform+12, bf->pos);
            vec4_slerp(btag->qrotate, src_btag->qrotate, next_btag->qrotate, bf->animations.lerp);
        }
        else
        {
            bone_tag_p ov_src_btag = src_btag;
            bone_tag_p ov_next_btag = next_btag;
            float ov_lerp = bf->animations.lerp;
            if(btag->alt_anim && btag->alt_anim->model && (btag->alt_anim->model->mesh_tree[k].replace_anim != 0))
            {
                bone_frame_p ov_curr_bf = btag->alt_anim->model->animations[btag->alt_anim->current_animation].frames + btag->alt_anim->current_frame;
                bone_frame_p ov_next_bf = btag->alt_anim->model->animations[btag->alt_anim->next_animation].frames + btag->alt_anim->next_frame;
                ov_src_btag = ov_curr_bf->bone_tags + k;
                ov_next_btag = ov_next_bf->bone_tags + k;
                ov_lerp = btag->alt_anim->lerp;
            }
            vec4_slerp(btag->qrotate, ov_src_btag->qrotate, ov_next_btag->qrotate, ov_lerp);
        }
        Mat4_set_qrotation(btag->transform, btag->qrotate);
    }

    /*
     * build absolute coordinate matrix system
     */
    btag = bf->bone_tags;
    Mat4_Copy(btag->full_transform, btag->transform);
    btag++;
    for(uint16_t k = 1; k < curr_bf->bone_tag_count; k++, btag++)
    {
        Mat4_Mat4_mul(btag->full_transform, btag->parent->full_transform, btag->transform);
    }

    for(ss_animation_p ss_anim = &bf->animations; ss_anim; ss_anim = ss_anim->next)
    {
        SSBoneFrame_TargetBoneToSlerp(bf, ss_anim);
    }
}