本文整理汇总了C++中LPD3DXANIMATIONCONTROLLER类的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXANIMATIONCONTROLLER类的具体用法?C++ LPD3DXANIMATIONCONTROLLER怎么用?C++ LPD3DXANIMATIONCONTROLLER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPD3DXANIMATIONCONTROLLER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAnimIndex
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::GetAnimIndex()
// Desc: Returns the index of an animation set within this animation instance's
// animation controller given an animation set name.
//-----------------------------------------------------------------------------
DWORD CXFileAnimInstance::GetAnimIndex( char sString[] )
{
HRESULT hr;
LPD3DXANIMATIONCONTROLLER pAC;
LPD3DXANIMATIONSET pAS;
DWORD dwRet = ANIMINDEX_FAIL;
m_pAI->GetAnimController( & pAC );
for( DWORD i = 0; i < pAC->GetNumAnimationSets(); ++ i )
{
hr = pAC->GetAnimationSet( i, & pAS );
if( FAILED( hr ) )
continue;
if( pAS->GetName() &&
!strncmp( pAS->GetName(), sString, min( strlen( pAS->GetName() ), strlen( sString ) ) ) )
{
dwRet = i;
pAS->Release();
break;
}
pAS->Release();
}
pAC->Release();
return dwRet;
}
示例2: InvalidateDeviceObjects
//-----------------------------------------------------------------------------
// Name: CTiny::RestoreDeviceObjects()
// Desc: Free D3D objects so that the device can be reset.
//-----------------------------------------------------------------------------
HRESULT CTiny::InvalidateDeviceObjects()
{
// Save the current track's animation set name
// so we can reset it again in RestoreDeviceObjects later.
LPD3DXANIMATIONCONTROLLER pAC = NULL;
m_pAI->GetAnimController( &pAC );
if( pAC )
{
LPD3DXANIMATIONSET pAS = NULL;
pAC->GetTrackAnimationSet( m_dwCurrentTrack, &pAS );
if( pAS )
{
if( pAS->GetName() )
strcpy_s( m_szASName, 64, pAS->GetName() );
SAFE_RELEASE( pAS );
}
SAFE_RELEASE( pAC );
}
CMultiAnimAllocateHierarchy AH;
AH.SetMA( m_pMA );
m_pMA->Cleanup( &AH );
return S_OK;
}
示例3: SmoothLoiter
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::SmoothLoiter()
// Desc: If Biped is loitering, check if we have reached the end of animation.
// If so, set up a new track to play Loiter animation from the start and
// smoothly transition to the track, so that Biped can loiter more.
//-----------------------------------------------------------------------------
void CXFileAnimInstance::SmoothLoiter()
{
LPD3DXANIMATIONCONTROLLER pAC;
LPD3DXANIMATIONSET pASTrack, pASLoiter;
m_pAI->GetAnimController( & pAC );
// check if we're loitering
pAC->GetTrackAnimationSet( m_dwCurrentTrack, & pASTrack );
pAC->GetAnimationSet( m_dwAnimIdxLoiter, & pASLoiter );
if( pASTrack && pASTrack == pASLoiter )
{
D3DXTRACK_DESC td;
pAC->GetTrackDesc( m_dwCurrentTrack, & td );
if( td.Position > pASTrack->GetPeriod() - IDLE_TRANSITION_TIME ) // come within the change delta of the end
{
// play loiter animation again (from the beginning)
strcpy(m_szASNameTarget, "Loiter");
PlayAnimation(false);
}
}
SAFE_RELEASE( pASTrack );
SAFE_RELEASE( pASLoiter );
SAFE_RELEASE( pAC );
}
示例4: GetAnimIndex
//-----------------------------------------------------------------------------
// Name: CTiny::Setup
// Desc: Initializes the class and readies it for animation
//-----------------------------------------------------------------------------
HRESULT CTiny::Setup(double dTimeCurrent, D3DXVECTOR3 pInitialPosition, CSoundManager *p_sound )
{
HRESULT hr;
WCHAR str[MAX_PATH];
// set the current and prev time
m_dTimeCurrent = m_dTimePrev = dTimeCurrent;
hr = m_pMA->CreateNewInstance( &m_dwMultiAnimIdx );
if( FAILED( hr ) )
return E_OUTOFMEMORY;
m_pAI = m_pMA->GetInstance( m_dwMultiAnimIdx );
// set initial position
m_vPos = pInitialPosition;
m_fFacing = 0.0f;
// set up anim indices
m_dwAnimIdxLoiter = GetAnimIndex( "Loiter" );
m_dwAnimIdxWalk = GetAnimIndex( "Walk" );
m_dwAnimIdxJog = GetAnimIndex( "Jog" );
if( m_dwAnimIdxLoiter == ANIMINDEX_FAIL ||
m_dwAnimIdxWalk == ANIMINDEX_FAIL ||
m_dwAnimIdxJog == ANIMINDEX_FAIL )
return E_FAIL;
// compute reorientation matrix based on default orientation and bounding radius
D3DXMATRIX mx;
float fScale = 1.f / m_pMA->GetBoundingRadius() / 2.5f;
D3DXMatrixScaling( &mx, fScale, fScale, fScale );
m_mxOrientation = mx;
D3DXMatrixRotationX( &mx, -D3DX_PI / 2.0f );
D3DXMatrixMultiply( &m_mxOrientation, &m_mxOrientation, &mx );
D3DXMatrixRotationY( &mx, D3DX_PI / 2.0f );
D3DXMatrixMultiply( &m_mxOrientation, &m_mxOrientation, &mx );
// set track to idle
SetIdleKey(false);
LPD3DXANIMATIONCONTROLLER pAC;
m_pAI->GetAnimController( &pAC );
pAC->AdvanceTime( m_dTimeCurrent, NULL );
pAC->Release();
// Use D3DX to create a texture from a file based image
DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"metalplate.wav" );
// load the sound
hr = p_sound->Create(&m_pSound,str,DSBCAPS_CTRLVOLUME);
return S_OK;
}
示例5: SetupCallbacksAndCompression
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::RestoreDeviceObjects()
// Desc: Reinitialize necessary objects
//-----------------------------------------------------------------------------
HRESULT CXFileAnimInstance::RestoreDeviceObjects()
{
// Compress the animation sets in the new animation controller
SetupCallbacksAndCompression();
LPD3DXANIMATIONCONTROLLER pAC;
m_pAI->GetAnimController( & pAC );
pAC->ResetTime();
pAC->AdvanceTime( m_dTimeCurrent, NULL );
// Initialize current track
if( m_szASName[0] != '\0' )
{
DWORD dwActiveSet = GetAnimIndex( m_szASName );
LPD3DXANIMATIONSET pAS = NULL;
pAC->GetAnimationSet( dwActiveSet, &pAS );
pAC->SetTrackAnimationSet( m_dwCurrentTrack, pAS );
SAFE_RELEASE( pAS );
}
pAC->SetTrackEnable( m_dwCurrentTrack, TRUE );
pAC->SetTrackWeight( m_dwCurrentTrack, 1.0f );
pAC->SetTrackSpeed( m_dwCurrentTrack, 1.0f );
SAFE_RELEASE( pAC );
// Call animate to initialize the tracks.
Animate( 0.0 );
return S_OK;
}
示例6: GetSpeedScale
//-----------------------------------------------------------------------------
// Name: CTiny::GetSpeedScale()
// Desc: Returns the speed of the current track.
//-----------------------------------------------------------------------------
double CTiny::GetSpeedScale()
{
LPD3DXANIMATIONCONTROLLER pAC;
D3DXTRACK_DESC td;
if( m_bIdle )
return 1.0;
else
{
m_pAI->GetAnimController( &pAC );
pAC->GetTrackDesc( m_dwCurrentTrack, &td );
pAC->Release();
return td.Speed;
}
}
示例7: CreateInstance
//-----------------------------------------------------------------------------
// Name: CMultiAnim::CreateInstance()
// Desc: Create a new animation instance based on our animation frames and
// animation controller.
//-----------------------------------------------------------------------------
HRESULT CMultiAnim::CreateInstance( CAnimInstance ** ppAnimInstance )
{
* ppAnimInstance = NULL;
LPD3DXANIMATIONCONTROLLER pNewAC = NULL;
HRESULT hr;
CAnimInstance * pAI = NULL;
// Clone the original AC. This clone is what we will use to animate
// this mesh; the original never gets used except to clone, since we
// always need to be able to add another instance at any time.
hr = m_pAC->CloneAnimationController( m_pAC->GetMaxNumAnimationOutputs(),
m_pAC->GetMaxNumAnimationSets(),
m_pAC->GetMaxNumTracks(),
m_pAC->GetMaxNumEvents(),
&pNewAC );
if( SUCCEEDED( hr ) )
{
// create the new AI
pAI = new CAnimInstance( this );
if( pAI == NULL )
{
hr = E_OUTOFMEMORY;
goto e_Exit;
}
// set it up
hr = pAI->Setup( pNewAC );
if( FAILED( hr ) )
goto e_Exit;
* ppAnimInstance = pAI;
}
e_Exit:
if( FAILED( hr ) )
{
if( pAI )
delete pAI;
if( pNewAC )
pNewAC->Release();
}
return hr;
}
示例8: AddCallbackKeysAndCompress
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::AddCallbackKeysAndCompress()
// Desc: Replaces an animation set in the animation controller with the
// compressed version and callback keys added to it.
//-----------------------------------------------------------------------------
HRESULT CXFileAnimInstance::AddCallbackKeysAndCompress( LPD3DXANIMATIONCONTROLLER pAC,
LPD3DXKEYFRAMEDANIMATIONSET pAS,
DWORD dwNumCallbackKeys,
D3DXKEY_CALLBACK aKeys[],
DWORD dwCompressionFlags,
FLOAT fCompression )
{
HRESULT hr;
LPD3DXCOMPRESSEDANIMATIONSET pASNew = NULL;
LPD3DXBUFFER pBufCompressed = NULL;
hr = pAS->Compress( dwCompressionFlags, fCompression, NULL, &pBufCompressed );
if( FAILED( hr ) )
goto e_Exit;
hr = D3DXCreateCompressedAnimationSet( pAS->GetName(),
pAS->GetSourceTicksPerSecond(),
pAS->GetPlaybackType(),
pBufCompressed,
dwNumCallbackKeys,
aKeys,
&pASNew );
pBufCompressed->Release();
if( FAILED( hr ) )
goto e_Exit;
pAC->UnregisterAnimationSet( pAS );
pAS->Release();
hr = pAC->RegisterAnimationSet( pASNew );
if( FAILED( hr ) )
goto e_Exit;
pASNew->Release();
pASNew = NULL;
e_Exit:
if( pASNew )
pASNew->Release();
return hr;
}
示例9: InvalidateDeviceObjects
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::InvalidateDeviceObjects()
// Desc: Free D3D objects so that the device can be reset.
//-----------------------------------------------------------------------------
HRESULT CXFileAnimInstance::InvalidateDeviceObjects()
{
// Save the current track's animation set name
// so we can reset it again in RestoreDeviceObjects later.
LPD3DXANIMATIONCONTROLLER pAC = NULL;
m_pAI->GetAnimController( & pAC );
if( pAC )
{
LPD3DXANIMATIONSET pAS = NULL;
pAC->GetTrackAnimationSet( m_dwCurrentTrack, &pAS );
if( pAS )
{
if( pAS->GetName() )
strcpy( m_szASName, pAS->GetName() );
SAFE_RELEASE( pAS );
}
SAFE_RELEASE( pAC );
}
return S_OK;
}
示例10: SetAnimController
//アニメーションコントローラの設置
void Dx_AnimeAuxiliary::SetAnimController(LPD3DXANIMATIONCONTROLLER lpAnimCont)
{
//
if(lpAnimCont!=NULL)
{
//アニメーションコントローラのアドレスを登録
this->lpAnimCont = lpAnimCont;
//登録トラック数を取得
this->max_num_track = lpAnimCont->GetMaxNumTracks();
}
}
示例11: SmoothLoiter
//-----------------------------------------------------------------------------
// Name: CTiny::SmoothLoiter()
// Desc: If Tiny is loitering, check if we have reached the end of animation.
// If so, set up a new track to play Loiter animation from the start and
// smoothly transition to the track, so that Tiny can loiter more.
//-----------------------------------------------------------------------------
void CTiny::SmoothLoiter()
{
LPD3DXANIMATIONCONTROLLER pAC;
LPD3DXANIMATIONSET pASTrack, pASLoiter;
m_pAI->GetAnimController( &pAC );
// check if we're loitering
pAC->GetTrackAnimationSet( m_dwCurrentTrack, &pASTrack );
pAC->GetAnimationSet( m_dwAnimIdxLoiter, &pASLoiter );
if( pASTrack && pASTrack == pASLoiter )
{
D3DXTRACK_DESC td;
pAC->GetTrackDesc( m_dwCurrentTrack, &td );
if( td.Position > pASTrack->GetPeriod() - IDLE_TRANSITION_TIME ) // come within the change delta of the end
SetIdleKey( true );
}
SAFE_RELEASE( pASTrack );
SAFE_RELEASE( pASLoiter );
SAFE_RELEASE( pAC );
}
示例12: Create
INT CLcXSkinIns::Create(void* p1, void* p2, void* p3, void* p4)
{
XTrack* pInst = NULL;
m_pOrg = (CLcXSkinSrc*)p1;
pInst =(XTrack*)p2;
LPD3DXANIMATIONCONTROLLER pAcOrg = (LPD3DXANIMATIONCONTROLLER)m_pOrg->GetAniController();
m_pFrameOrg = (LPD3DXFRAME)m_pOrg->GetFrameRoot();
HRESULT hr=-1;
DWORD i, dwTracks;
LPD3DXANIMATIONCONTROLLER pNewAC = NULL;
if(pAcOrg)
{
if(m_pAC)
m_pAC->Release();
UINT MaxNumAnimationOutputs = pAcOrg->GetMaxNumAnimationOutputs();
UINT MaxNumAnimationSets = pAcOrg->GetMaxNumAnimationSets();
UINT MaxNumTracks = pAcOrg->GetMaxNumTracks();
UINT MaxNumEvents = pAcOrg->GetMaxNumEvents();
hr = pAcOrg->CloneAnimationController(MaxNumAnimationOutputs
, MaxNumAnimationSets
, MaxNumTracks
, MaxNumEvents
, &pNewAC);
if(FAILED(hr))
return -1;
m_pAC = pNewAC;
// LPD3DXTRACK_DESC;
//LPD3DXANIMATIONSET pAS= NULL;
FLOAT fTrackPosition = pInst->fTrackPosition;
FLOAT fTrackSpeed = pInst->fTrackSpeed;
// Start with all tracks disabled
dwTracks = m_pAC->GetMaxNumTracks();
for( i = 0; i < dwTracks; ++ i )
{
m_pAC->SetTrackEnable( i, TRUE );
m_pAC->SetTrackWeight( i, 1.0f );
m_pAC->SetTrackSpeed( i, 1);
m_pAC->SetTrackPosition(i, fTrackPosition);
}
}
return 0;
}
示例13: GetAnimationIndex
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::InitDeviceObjects
// Desc: Initializes the class and readies it for animation
//-----------------------------------------------------------------------------
HRESULT CXFileAnimInstance::InitDeviceObjects()
{
HRESULT hr;
hr = m_pMA->CreateNewInstance( & m_dwMultiAnimIdx );
if( FAILED( hr ) )
return E_OUTOFMEMORY;
m_pAI = m_pMA->GetInstance( m_dwMultiAnimIdx );
// set up anim indices
GetAnimationIndex();
// set up footstep callbacks
SetupCallbacksAndCompression();
// compute reorientation matrix based on default orientation and bounding radius
Matrix4 mx;
// Set the raduis of the object as it appears in the scene to 1/7.0f units
float fScale = 1.f / m_pMA->GetBoundingRadius() / 7.f;
ParaMatrixScaling( & mx, fScale, fScale, fScale );
m_mxOrientation = mx;
// the following code is required by DirectX model trandsformation.
ParaMatrixRotationX( & mx, -MATH_PI / 2.0f );
ParaMatrixMultiply( & m_mxOrientation, & m_mxOrientation, & mx );
ParaMatrixRotationY( & mx, MATH_PI / 2.0f );
ParaMatrixMultiply( & m_mxOrientation, & m_mxOrientation, & mx );
// default: play idle animation
strcpy(m_szASNameTarget,"Loiter");
//ComputeFacingTarget();
PlayAnimation(false); //force loading the first animation
LPD3DXANIMATIONCONTROLLER pAC;
m_pAI->GetAnimController( & pAC );
pAC->AdvanceTime( m_dTimeCurrent, NULL );
pAC->Release();
return S_OK;
}
示例14: SetupCallbacksAndCompression
//-----------------------------------------------------------------------------
// Name: CTiny::SetupCallbacksAndCompression()
// Desc: Add callback keys to the walking and jogging animation sets in the
// animation controller for playing footstepping sound. Then compress
// all animation sets in the animation controller.
//-----------------------------------------------------------------------------
HRESULT CTiny::SetupCallbacksAndCompression()
{
LPD3DXANIMATIONCONTROLLER pAC;
LPD3DXKEYFRAMEDANIMATIONSET pASLoiter, pASWalk, pASJog;
m_pAI->GetAnimController( &pAC );
pAC->GetAnimationSet( m_dwAnimIdxLoiter, ( LPD3DXANIMATIONSET* )&pASLoiter );
pAC->GetAnimationSet( m_dwAnimIdxWalk, ( LPD3DXANIMATIONSET* )&pASWalk );
pAC->GetAnimationSet( m_dwAnimIdxJog, ( LPD3DXANIMATIONSET* )&pASJog );
D3DXKEY_CALLBACK aKeysWalk[ 2 ];
aKeysWalk[ 0 ].Time = 0;
aKeysWalk[ 0 ].pCallbackData = &m_CallbackData[ 0 ];
aKeysWalk[ 1 ].Time = float( pASWalk->GetPeriod() / 2.0 * pASWalk->GetSourceTicksPerSecond() );
aKeysWalk[ 1 ].pCallbackData = &m_CallbackData[ 1 ];
D3DXKEY_CALLBACK aKeysJog[ 8 ];
for( int i = 0; i < 8; ++ i )
{
aKeysJog[ i ].Time = float( pASJog->GetPeriod() / 8 * ( double )i * pASWalk->GetSourceTicksPerSecond() );
aKeysJog[ i ].pCallbackData = &m_CallbackData[ ( i + 1 ) % 2 ];
}
AddCallbackKeysAndCompress( pAC, pASLoiter, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
AddCallbackKeysAndCompress( pAC, pASWalk, 2, aKeysWalk, D3DXCOMPRESS_DEFAULT, .4f );
AddCallbackKeysAndCompress( pAC, pASJog, 8, aKeysJog, D3DXCOMPRESS_DEFAULT, .25f );
m_dwAnimIdxLoiter = GetAnimIndex( "Loiter" );
m_dwAnimIdxWalk = GetAnimIndex( "Walk" );
m_dwAnimIdxJog = GetAnimIndex( "Jog" );
if( m_dwAnimIdxLoiter == ANIMINDEX_FAIL ||
m_dwAnimIdxWalk == ANIMINDEX_FAIL ||
m_dwAnimIdxJog == ANIMINDEX_FAIL )
return E_FAIL;
pAC->Release();
return S_OK;
}
示例15: strcpy
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::PlayAnimation()
// Desc: Initialize a new track in the animation controller for the movement
// animation (run or walk), and set up the smooth transition from the idle
// animation (current track) to it (new track).
// Params: bContinue: If it's true,load new animation track only if sAnimName is
// different from the track that is being played
// note: m_szASNameTarget can be numbers, which is translated as index into the
// model file's animation sets.
//-----------------------------------------------------------------------------
void CXFileAnimInstance::PlayAnimation(bool bContinue)
{
// -- return if no new animation is specified
if(bContinue && strcmp(m_szASNameTarget, m_szASName) == 0)
return;
strcpy(m_szASName, m_szASNameTarget);
// -- create new track
DWORD dwNewTrack = ( m_dwCurrentTrack == 0 ? 1 : 0 );
LPD3DXANIMATIONCONTROLLER pAC;
LPD3DXANIMATIONSET pAS;
m_pAI->GetAnimController( & pAC );
// TODO: use hash tablle to get the animation set
// -- Get the animation set
HRESULT hr;
double dTransitionPeriod = MOVE_TRANSITION_TIME;
if(strcmp(m_szASName, "Walk") == 0)
{
hr = pAC->GetAnimationSet( m_dwAnimIdxWalk, & pAS );
dTransitionPeriod = MOVE_TRANSITION_TIME;
}
else if(strcmp(m_szASName, "Jog") == 0)
{
hr = pAC->GetAnimationSet( m_dwAnimIdxJog, & pAS );
dTransitionPeriod = MOVE_TRANSITION_TIME;
}
else if( ('0'<= m_szASName[0]) && (m_szASName[0]<='9') )
{// if it's a number from 0~99
UINT nIndex = 0;
if(('0'<= m_szASName[1]) && (m_szASName[1]<='9'))
nIndex = (m_szASName[0] - '0')*10+m_szASName[1]-'0';
else
nIndex = (m_szASName[0] - '0');
// use the name as the index of the animation set.
hr = pAC->GetAnimationSet( nIndex, & pAS );
dTransitionPeriod = MOVE_TRANSITION_TIME;
}
else //if(strcmp(m_szASName, "Loiter"))
{
hr = pAC->GetAnimationSet( m_dwAnimIdxLoiter, & pAS );
dTransitionPeriod = IDLE_TRANSITION_TIME;
}
if( ! SUCCEEDED(hr) ) // failed to load
{
// TODO: Load default animation
hr = pAC->GetAnimationSet( m_dwAnimIdxLoiter, & pAS );
dTransitionPeriod = IDLE_TRANSITION_TIME;
if( ! SUCCEEDED(hr) )// failed to load the default
return;
}
// -- Enable new track and set transition weight
pAC->SetTrackAnimationSet( dwNewTrack, pAS );
pAS->Release();
pAC->UnkeyAllTrackEvents( m_dwCurrentTrack );
pAC->UnkeyAllTrackEvents( dwNewTrack );
pAC->KeyTrackEnable( m_dwCurrentTrack, FALSE, m_dTimeCurrent + dTransitionPeriod );
pAC->KeyTrackSpeed( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, dTransitionPeriod, D3DXTRANSITION_LINEAR );
pAC->KeyTrackWeight( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, dTransitionPeriod, D3DXTRANSITION_LINEAR );
pAC->SetTrackEnable( dwNewTrack, TRUE );
pAC->KeyTrackSpeed( dwNewTrack, 1.0f, m_dTimeCurrent, dTransitionPeriod, D3DXTRANSITION_LINEAR );
pAC->KeyTrackWeight( dwNewTrack, 1.0f, m_dTimeCurrent, dTransitionPeriod, D3DXTRANSITION_LINEAR );
if(!bContinue) // restart
pAC->SetTrackPosition( dwNewTrack, 0.0 );
m_dwCurrentTrack = dwNewTrack;
pAC->Release();
}