DX9动画控制

SmoothChangeAnimation函数申明:

void SmoothChangeAnimation(LPD3DXANIMATIONCONTROLLER pAnimController,LPD3DXANIMATIONSET pAnimSet,FLOAT fCurrTime);

SmoothChangeAnimation函数实现:

void SmoothChangeAnimation( LPD3DXANIMATIONCONTROLLER pAnimController, LPD3DXANIMATIONSET pAnimSet, FLOAT fCurrTime )
{
    static DWORD dwOldTrack = 0;
    static DWORD dwNewTrack = 1;

    dwNewTrack  = dwOldTrack == 0 ? 1 : 0;
    pAnimController->SetTrackAnimationSet( dwNewTrack, pAnimSet );

    pAnimController->UnkeyAllTrackEvents( dwOldTrack );
    pAnimController->UnkeyAllTrackEvents( dwNewTrack );

    pAnimController->KeyTrackEnable( dwOldTrack, FALSE, fCurrTime + 0.125f );
    pAnimController->KeyTrackSpeed(  dwOldTrack, 0.0f,  fCurrTime, 0.125f, D3DXTRANSITION_LINEAR );
    pAnimController->KeyTrackWeight( dwOldTrack, 0.0f,  fCurrTime, 0.125f, D3DXTRANSITION_LINEAR );

    pAnimController->SetTrackEnable( dwNewTrack, TRUE );
    pAnimController->KeyTrackSpeed(  dwNewTrack, 1.0f,  fCurrTime, 0.125f, D3DXTRANSITION_LINEAR );
    pAnimController->KeyTrackWeight( dwNewTrack, 1.0f,  fCurrTime, 0.125f, D3DXTRANSITION_LINEAR );

    dwOldTrack = dwNewTrack;
}

控制动作

static float fCurrTime=0.0f;
    fCurrTime += timeDelta;

    LPD3DXANIMATIONSET pAnimationSet=NULL;

    if(::GetAsyncKeyState(0x31)&0x8000f)

    {
    g_pAnimController->GetAnimationSetByName("stand",&pAnimationSet);
    SmoothChangeAnimation(g_pAnimController,pAnimationSet,fCurrTime);
    }
    if(::GetAsyncKeyState(0x32)&0x8000f)

    {
    g_pAnimController->GetAnimationSetByName("sworddance",&pAnimationSet);
    SmoothChangeAnimation(g_pAnimController,pAnimationSet,fCurrTime);
    }
    SAFE_RELEASE(pAnimationSet);


    Device->SetTransform(D3DTS_WORLD, &matFinal);

    g_pAnimController->AdvanceTime(timeDelta,NULL);
    UpdateFrameMatrices(g_pFrameRoot, &matFinal);

 

posted @ 2022-05-12 08:37  szmtjs10  阅读(166)  评论(0编辑  收藏  举报