//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // The player object class constructor. //----------------------------------------------------------------------------- PlayerObject::PlayerObject( PlayerInfo *player, Script *script, unsigned long type ) : AnimatedObject( script->GetStringData( "mesh_name" ), script->GetStringData( "mesh_path" ), type ) { // Set the player's DirectPlay ID. m_dpnid = player->dpnid; // Set the players's name. m_name = new char[strlen( player->name ) + 1]; strcpy( m_name, player->name ); // Players start with full health; m_health = 100.0f; m_dying = false; // Indicate that the view transform is not being taken from this player. m_isViewing = false; // Clear the player's score. m_frags = 0; m_deaths = 0; // Player objects start off invisible and disabled. SetVisible( false ); SetEnabled( false ); // Clear the player's input. m_drive = 0.0f; m_strafe = 0.0f; m_fire = false; // Set the correct ellipse radius. SetEllipsoidRadius( *script->GetVectorData( "ellipse_radius" ) ); // Level the player's view tilt. m_viewTilt = 0.0f; // Set the default view smoothing and sensitivity. m_viewSmoothing = 0.5f; m_viewSensitivity = 0.65f; // Get the view weapon offset. m_viewWeaponOffset = *script->GetVectorData( "view_weapon_offset" ); // Clear the weapons array. for( unsigned char w = 0; w < 10; w++ ) m_weapons[w] = NULL; // The player starts with the first basic weapon. Script *weaponScript = new Script( "Gun1.txt", "./Assets/Objects/Gun1/" ); m_weapons[0] = new Weapon( weaponScript, m_viewWeaponOffset ); m_currentWeapon = 0; if( player->dpnid == g_engine->GetNetwork()->GetLocalID() ) m_weapons[m_currentWeapon]->UseViewWeapon( true ); else m_weapons[m_currentWeapon]->UseViewWeapon( false ); SAFE_DELETE( weaponScript ); // Indicate that the player is not changing weapons. m_changingWeapon = 0.0f; m_weaponChanging = false; // Create the callback data used for tracking the player's foot steps. m_callbackData[0].foot = 0; m_callbackData[1].foot = 1; // Create the callback keys. The second key time is set per animation. D3DXKEY_CALLBACK keys[2]; keys[0].Time = 0; keys[0].pCallbackData = &m_callbackData[0]; keys[1].pCallbackData = &m_callbackData[1]; LPD3DXKEYFRAMEDANIMATIONSET oldAS; LPD3DXCOMPRESSEDANIMATIONSET newAS; LPD3DXBUFFER buffer; // Go through the four movement animations and set the foot step keys. for( char a = 1; a < 5; a++ ) { // Get the old animation. GetAnimationController()->GetAnimationSet( a, (LPD3DXANIMATIONSET*)&oldAS ); // Set the time for the second key. keys[1].Time = float( oldAS->GetPeriod() / 2.0f * oldAS->GetSourceTicksPerSecond() ); // Compress the old animation set. oldAS->Compress( D3DXCOMPRESS_DEFAULT, 0.4f, NULL, &buffer ); // Create the new animation using the old one and the foot step keys. D3DXCreateCompressedAnimationSet( oldAS->GetName(), oldAS->GetSourceTicksPerSecond(), oldAS->GetPlaybackType(), buffer, 2, keys, &newAS ); SAFE_RELEASE( buffer ); // Unregister the old animation set. GetAnimationController()->UnregisterAnimationSet( oldAS ); SAFE_RELEASE( oldAS ); // Register the new animation set. // Note: The new animation is appended to the end of the list. GetAnimationController()->RegisterAnimationSet( newAS ); SAFE_RELEASE( newAS ); } // Play the idle animation. PlayAnimation( 0, 0.0f ); // Create the step sound audio paths. m_leftStepAudioPath = new AudioPath3D; m_rightStepAudioPath = new AudioPath3D; // Set the friction on this object. SetFriction( 8.0f ); }