//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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; } }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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( ... ) { } }