示例#1
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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;
}
//アニメーションコントローラの設置
void Dx_AnimeAuxiliary::SetAnimController(LPD3DXANIMATIONCONTROLLER lpAnimCont)
{
	//
	if(lpAnimCont!=NULL)
	{
		//アニメーションコントローラのアドレスを登録
		this->lpAnimCont = lpAnimCont;

		//登録トラック数を取得
		this->max_num_track = lpAnimCont->GetMaxNumTracks();
	}
}
示例#11
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// 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
0
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
0
//-----------------------------------------------------------------------------
// 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
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// 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
0
//-----------------------------------------------------------------------------
// 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();
}
示例#16
0
//-----------------------------------------------------------------------------
// Name: CBipedAnimInstance::SetupCallbacksAndCompression()
// Desc: 2004-5-5 LiXizhi
//       Only compress, I have removed any callbacks. The old code is commented, which
//       Adds 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.
// you can change the input values of AddCallbackKeysAndCompress(..., .8f) to your desired ones.
// such as Compression Lossiness, which is Desired compression loss ratio, in the range from 0 to 1.
// currenly this value is set to 0.8f.
//-----------------------------------------------------------------------------
HRESULT CXFileAnimInstance::SetupCallbacksAndCompression()
{
    LPD3DXANIMATIONCONTROLLER pAC;
    LPD3DXKEYFRAMEDANIMATIONSET pASLoiter, pASWalk, pASJog;

    m_pAI->GetAnimController( & pAC );
    
	// -- compress Loiter animation
	pAC->GetAnimationSet( m_dwAnimIdxLoiter, (LPD3DXANIMATIONSET *) & pASLoiter );
	AddCallbackKeysAndCompress( pAC, pASLoiter, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
    
	// -- compress <removed:and set callback> for Walk animation
	if(m_dwAnimIdxLoiter != m_dwAnimIdxWalk)
	{
		pAC->GetAnimationSet( m_dwAnimIdxWalk, (LPD3DXANIMATIONSET *) & pASWalk );
		AddCallbackKeysAndCompress( pAC, pASWalk, 0, NULL, D3DXCOMPRESS_DEFAULT, .4f );

		/*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 ];

		AddCallbackKeysAndCompress( pAC, pASWalk, 2, aKeysWalk, D3DXCOMPRESS_DEFAULT, .4f );*/
	
		// -- compress <removed: and set callback> for Jog animation
		if(m_dwAnimIdxWalk != m_dwAnimIdxJog)
		{
			pAC->GetAnimationSet( m_dwAnimIdxJog, (LPD3DXANIMATIONSET *) & pASJog );
		    AddCallbackKeysAndCompress( pAC, pASJog, 0, NULL, D3DXCOMPRESS_DEFAULT, .25f );

			/*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, pASJog, 8, aKeysJog, D3DXCOMPRESS_DEFAULT, .25f );*/
		}
	}

	// -- compress and set callback for Action# animation
	if(m_dwAnimIdxLoiter != m_dwAnimIdxAction[0])
	{
		LPD3DXKEYFRAMEDANIMATIONSET pASAction;
		pAC->GetAnimationSet( m_dwAnimIdxAction[0], (LPD3DXANIMATIONSET *) & (pASAction) );
		AddCallbackKeysAndCompress( pAC, pASAction, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );

		// -- compress and set callback for Action1 animation
		if(m_dwAnimIdxAction[0] != m_dwAnimIdxAction[1])
		{
			pAC->GetAnimationSet( m_dwAnimIdxAction[1], (LPD3DXANIMATIONSET *) & (pASAction) );
			AddCallbackKeysAndCompress( pAC, pASAction, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
			// -- compress and set callback for Action2-5 animation
			for(int i=2;i<=5;i++)
			{
				if(m_dwAnimIdxAction[1] != m_dwAnimIdxAction[i])
				{
					pAC->GetAnimationSet( m_dwAnimIdxAction[i], (LPD3DXANIMATIONSET *) & (pASAction) );
					AddCallbackKeysAndCompress( pAC, pASAction, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
				}
			}
		}
		// -- compress and set callback for Action6 animation
		if(m_dwAnimIdxAction[0] != m_dwAnimIdxAction[6])
		{
			pAC->GetAnimationSet( m_dwAnimIdxAction[6], (LPD3DXANIMATIONSET *) & (pASAction) );
			AddCallbackKeysAndCompress( pAC, pASAction, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
			// -- compress and set callback for Action7-10 animation
			for(int i=7;i<=10;i++)
			{
				if(m_dwAnimIdxAction[6] != m_dwAnimIdxAction[i])
				{
					pAC->GetAnimationSet( m_dwAnimIdxAction[i], (LPD3DXANIMATIONSET *) & (pASAction) );
					AddCallbackKeysAndCompress( pAC, pASAction, 0, NULL, D3DXCOMPRESS_DEFAULT, .8f );
				}
			}
		}
	}

    GetAnimationIndex();

    pAC->Release();

    return S_OK;
}
示例#17
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// Name: CTiny::SetMoveKey()
// 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).
//-----------------------------------------------------------------------------
void CTiny::SetMoveKey()
{
    DWORD dwNewTrack = ( m_dwCurrentTrack == 0 ? 1 : 0 );
    LPD3DXANIMATIONCONTROLLER pAC;
    LPD3DXANIMATIONSET pAS;
    m_pAI->GetAnimController( &pAC );

    if( m_fSpeed == m_fSpeedWalk )
        pAC->GetAnimationSet( m_dwAnimIdxWalk, &pAS );
    else
        pAC->GetAnimationSet( m_dwAnimIdxJog, &pAS );

    pAC->SetTrackAnimationSet( dwNewTrack, pAS );
    pAS->Release();

    pAC->UnkeyAllTrackEvents( m_dwCurrentTrack );
    pAC->UnkeyAllTrackEvents( dwNewTrack );

    pAC->KeyTrackEnable( m_dwCurrentTrack, FALSE, m_dTimeCurrent + MOVE_TRANSITION_TIME );
    pAC->KeyTrackSpeed( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, MOVE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->KeyTrackWeight( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, MOVE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->SetTrackEnable( dwNewTrack, TRUE );
    pAC->KeyTrackSpeed( dwNewTrack, 1.0f, m_dTimeCurrent, MOVE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->KeyTrackWeight( dwNewTrack, 1.0f, m_dTimeCurrent, MOVE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );

    m_dwCurrentTrack = dwNewTrack;

    pAC->Release();
}
示例#18
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// Name: CTiny::SetIdleKey()
// Desc: Initialize a new track in the animation controller for the idle
//       (loiter ) animation, and set up the smooth transition from the
//       movement animation (current track) to it (new track).
//
//       bResetPosition controls whether we start the Loiter animation from
//       its beginning or current position.
//-----------------------------------------------------------------------------
void CTiny::SetIdleKey( bool bResetPosition )
{
    DWORD dwNewTrack = ( m_dwCurrentTrack == 0 ? 1 : 0 );
    LPD3DXANIMATIONCONTROLLER pAC;
    LPD3DXANIMATIONSET pAS;
    m_pAI->GetAnimController( &pAC );

    pAC->GetAnimationSet( m_dwAnimIdxLoiter, &pAS );
    pAC->SetTrackAnimationSet( dwNewTrack, pAS );
    pAS->Release();

    pAC->UnkeyAllTrackEvents( m_dwCurrentTrack );
    pAC->UnkeyAllTrackEvents( dwNewTrack );

    pAC->KeyTrackEnable( m_dwCurrentTrack, FALSE, m_dTimeCurrent + IDLE_TRANSITION_TIME );
    pAC->KeyTrackSpeed( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, IDLE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->KeyTrackWeight( m_dwCurrentTrack, 0.0f, m_dTimeCurrent, IDLE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->SetTrackEnable( dwNewTrack, TRUE );
    pAC->KeyTrackSpeed( dwNewTrack, 1.0f, m_dTimeCurrent, IDLE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    pAC->KeyTrackWeight( dwNewTrack, 1.0f, m_dTimeCurrent, IDLE_TRANSITION_TIME, D3DXTRANSITION_LINEAR );
    if( bResetPosition )
        pAC->SetTrackPosition( dwNewTrack, 0.0 );

    m_dwCurrentTrack = dwNewTrack;

    pAC->Release();
}
示例#19
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// Name: CTiny::Report()
// Desc: Add to the vector of strings, v_sReport, with useful information
//       about this instance of CTiny.
//-----------------------------------------------------------------------------
void CTiny::Report( vector <String>& v_sReport )
{
    WCHAR s[ 256 ];

    try
    {
        swprintf_s( s, 256, L"Pos: %f, %f", m_vPos.x, m_vPos.z );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"Facing: %f", m_fFacing );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"Local time: %f", m_dTimeCurrent );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"Pos Target: %f, %f", m_vPosTarget.x, m_vPosTarget.z );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"Facing Target: %f", m_fFacingTarget );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"Status: %s", m_bIdle ? L"Idle" : ( m_bWaiting ? L"Waiting" : L"Moving" ) );
        v_sReport.push_back( String( s ) );

        // report track data
        LPD3DXANIMATIONCONTROLLER pAC;
        LPD3DXANIMATIONSET pAS;
        D3DXTRACK_DESC td;
        m_pAI->GetAnimController( &pAC );

        pAC->GetTrackAnimationSet( 0, &pAS );
        WCHAR wstr[256];
        MultiByteToWideChar( CP_ACP, 0, pAS->GetName(), -1, wstr, 256 );
        swprintf_s( s, 256, L"Track 0: %s%s", wstr, m_dwCurrentTrack == 0 ? L" (current)" : L"" );
        v_sReport.push_back( String( s ) );
        pAS->Release();

        pAC->GetTrackDesc( 0, &td );
        swprintf_s( s, 256, L"  Weight: %f", td.Weight );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Speed: %f", td.Speed );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Position: %f", td.Position );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Enable: %s", td.Enable ? L"true" : L"false" );
        v_sReport.push_back( String( s ) );

        pAC->GetTrackAnimationSet( 1, &pAS );
        if( pAS )
        {
            MultiByteToWideChar( CP_ACP, 0, pAS->GetName(), -1, wstr, 256 );
            pAS->Release();
        }
        else
        {
            swprintf_s( wstr, 256, L"n/a" );
        }
        swprintf_s( s, 256, L"Track 1: %s%s", wstr, m_dwCurrentTrack == 1 ? L" (current)" : L"" );
        v_sReport.push_back( String( s ) );

        pAC->GetTrackDesc( 1, &td );
        swprintf_s( s, 256, L"  Weight: %f", td.Weight );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Speed: %f", td.Speed );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Position: %f", td.Position );
        v_sReport.push_back( String( s ) );
        swprintf_s( s, 256, L"  Enable: %s", td.Enable ? L"true" : L"false" );
        v_sReport.push_back( String( s ) );

        if( m_bUserControl )
        {
            swprintf_s( s, 256, L"Control: USER" );
            v_sReport.push_back( String( s ) );
        }
        else
        {
            swprintf_s( s, 256, L"Control: AUTO" );
            v_sReport.push_back( String( s ) );
        }

        pAC->Release();
    }
    catch( ... )
    {
    }
}
示例#20
0
文件: Tiny.cpp 项目: KNeal/Oculus
//-----------------------------------------------------------------------------
// Name: CTiny::Setup
// Desc: Initializes the class and readies it for animation
//-----------------------------------------------------------------------------
HRESULT CTiny::Setup( CMultiAnim* pMA,
                      vector <CTiny*>* pv_pChars,
                      CSoundManager* pSM,
                      double dTimeCurrent )
{
    m_pMA = pMA;
    m_pv_pChars = pv_pChars;
    m_pSM = pSM;

    m_dTimeCurrent = m_dTimePrev = dTimeCurrent;

    HRESULT hr;
    hr = m_pMA->CreateNewInstance( &m_dwMultiAnimIdx );
    if( FAILED( hr ) )
        return E_OUTOFMEMORY;

    m_pAI = m_pMA->GetInstance( m_dwMultiAnimIdx );

    // set initial position
    bool bBlocked = true;
    DWORD dwAttempts;
    for( dwAttempts = 0; dwAttempts < 1000 && bBlocked; ++ dwAttempts )
    {
        ChooseNewLocation( &m_vPos );
        bBlocked = IsBlockedByCharacter( &m_vPos );
    }

    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;

    // set up callback key data
    m_CallbackData[ 0 ].m_dwFoot = 0;
    m_CallbackData[ 0 ].m_pvTinyPos = &m_vPos;
    m_CallbackData[ 1 ].m_dwFoot = 1;
    m_CallbackData[ 1 ].m_pvTinyPos = &m_vPos;

    // set up footstep callbacks
    SetupCallbacksAndCompression();
    m_pCallbackHandler = new CBHandlerTiny;
    if( m_pCallbackHandler == NULL )
        return E_OUTOFMEMORY;

    // set up footstep sounds
    WCHAR sPath[ MAX_PATH ];
    if( g_apSoundsTiny[ 0 ] == NULL )
    {
        hr = DXUTFindDXSDKMediaFileCch( sPath, MAX_PATH, FOOTFALLSOUND00 );
        if( FAILED( hr ) )
            wcscpy_s( sPath, MAX_PATH, FOOTFALLSOUND00 );

        hr = m_pSM->Create( &g_apSoundsTiny[ 0 ], sPath, DSBCAPS_CTRLVOLUME );
        if( FAILED( hr ) )
        {
            OutputDebugString( FOOTFALLSOUND00 L" not found; continuing without sound.\n" );
            m_bPlaySounds = false;
        }
    }

    if( g_apSoundsTiny[ 1 ] == NULL )
    {
        hr = DXUTFindDXSDKMediaFileCch( sPath, MAX_PATH, FOOTFALLSOUND01 );
        if( FAILED( hr ) )
            wcscpy_s( sPath, MAX_PATH, FOOTFALLSOUND01 );

        hr = m_pSM->Create( &g_apSoundsTiny[ 1 ], sPath, DSBCAPS_CTRLVOLUME );
        if( FAILED( hr ) )
        {
            OutputDebugString( FOOTFALLSOUND01 L" not found; continuing without sound.\n" );
            m_bPlaySounds = false;
        }
    }

    // compute reorientation matrix based on default orientation and bounding radius
    D3DXMATRIX mx;
    float fScale = 1.f / m_pMA->GetBoundingRadius() / 7.f;
    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 starting target
    SetSeekingState();
    ComputeFacingTarget();

    LPD3DXANIMATIONCONTROLLER pAC;
    m_pAI->GetAnimController( &pAC );
    pAC->AdvanceTime( m_dTimeCurrent, NULL );
    pAC->Release();

    // Add this instance to the list
    try
    {
        pv_pChars->push_back( this );
    }
    catch( ... )
    {
        return E_OUTOFMEMORY;
    }

    return S_OK;
}
示例#21
0
HRESULT MeshManager::LoadAnimeFromX(LPD3DXANIMATIONCONTROLLER &pAnimControllerTmp,DxAnimeMesh *mesh,
																		const string& fName,const string& path)
{
	//読み込み用アニメーションコントローラ
//	LPD3DXANIMATIONCONTROLLER pAnimControllerTmp = NULL;

	/*アニメーションコントローラ関連*/
	//アニメーションコントローラの設定
	if(pAnimControllerTmp!=NULL)
	{
		//トラック数をアニメーションセット数に増やす
		unsigned TracksNum   = pAnimControllerTmp->GetMaxNumTracks();
		unsigned AnimSetsNum = pAnimControllerTmp->GetMaxNumAnimationSets();

		//
		if(TracksNum < AnimSetsNum)
		{
			TracksNum = AnimSetsNum;
		}

		//読み込んだアニメーションコントローラから新たに設定された複製を生成
		if(FAILED(pAnimControllerTmp->CloneAnimationController(
					pAnimControllerTmp->GetMaxNumAnimationOutputs(),
					pAnimControllerTmp->GetMaxNumAnimationSets(),
					TracksNum,
					pAnimControllerTmp->GetMaxNumEvents(),
					&mesh->pAnimController)))
		{
		}
		//読み込み用アニメーションコントローラの開放
//		SAFE_RELEASE(pAnimControllerTmp);

		//トラックに全てのアニメーションセットを読み込む
		for(unsigned i = 1; i < AnimSetsNum; i++ )
		{
			//読み込み用オブジェクトの宣言
			LPD3DXANIMATIONSET pAnimSet = NULL;
			//アニメーションコントローラからアニメーションセットを読み込む
			if(FAILED(mesh->pAnimController->GetAnimationSet(i, &pAnimSet)))
			{
			}
			//指定トラックにアニメーションセットを設定
			if(FAILED(mesh->pAnimController->SetTrackAnimationSet(i, pAnimSet)))
			{
			}
			//トラックに設定済みのアニメーションセットを開放
			SAFE_RELEASE(pAnimSet);
		}
	}
	else
	{
		mesh->pAnimController = NULL;
	}

	//フレームの全階層をチェックしてボーンの関連付けを行う
	if(FAILED((this->SetupBoneFromFrame(mesh->pFrameRoot, mesh->pFrameRoot))))
	{
		return E_FAIL;
	}

	return S_OK;
}