//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CTriggerPortalCleanser::TransferPhysicsObject( CBaseEntity *pFrom, CBaseEntity *pTo, bool wakeUp ) { IPhysicsObject *pVPhysics = pFrom->VPhysicsGetObject(); if ( !pVPhysics || pVPhysics->IsStatic() ) return false; Vector vecVelocity, vecAngular; pVPhysics->GetVelocity( &vecVelocity, &vecAngular ); // clear out the pointer so it won't get deleted pFrom->VPhysicsSwapObject( NULL ); // remove any AI behavior bound to it pVPhysics->RemoveShadowController(); // transfer to the new owner pTo->VPhysicsSetObject( pVPhysics ); pVPhysics->SetGameData( (void *)pTo ); pTo->VPhysicsUpdate( pVPhysics ); // may have been temporarily disabled by the old object pVPhysics->EnableMotion( true ); pVPhysics->EnableGravity( false ); // Slow down and push up the object. vecVelocity /= 2; vecAngular /= 2; vecVelocity.z += 10; pVPhysics->SetVelocity( &vecVelocity, &vecAngular ); // Update for the new entity solid type pVPhysics->RecheckCollisionFilter(); if ( wakeUp ) { pVPhysics->Wake(); } return true; }
void CCollisionEvent::ObjectSound( int index, vcollisionevent_t *pEvent ) { IPhysicsObject *pObject = pEvent->pObjects[index]; if ( !pObject || pObject->IsStatic() ) return; float speed = pEvent->collisionSpeed * pEvent->collisionSpeed; int surfaceProps = pEvent->surfaceProps[index]; void *pGameData = pObject->GetGameData(); if ( pGameData ) { float volume = speed * (1.0f/(320.0f*320.0f)); // max volume at 320 in/s if ( volume > 1.0f ) volume = 1.0f; if ( surfaceProps >= 0 ) { g_PhysicsSystem.AddImpactSound( pGameData, pObject, surfaceProps, pEvent->surfaceProps[!index], volume, speed ); } } }
// UNDONE: Is this worth it?, just recreate the object instead? (that happens when this returns false anyway) // recreating works, but is more expensive and won't inherit properties (velocity, constraints, etc) bool TransferPhysicsObject( CBaseEntity *pFrom, CBaseEntity *pTo ) { IPhysicsObject *pVPhysics = pFrom->VPhysicsGetObject(); if ( !pVPhysics || pVPhysics->IsStatic() ) return false; // clear out the pointer so it won't get deleted pFrom->VPhysicsSwapObject( NULL ); // remove any AI behavior bound to it pVPhysics->RemoveShadowController(); // transfer to the new owner pTo->VPhysicsSetObject( pVPhysics ); pVPhysics->SetGameData( (void *)pTo ); pTo->VPhysicsUpdate( pVPhysics ); // may have been temporarily disabled by the old object pVPhysics->EnableMotion( true ); pVPhysics->EnableGravity( true ); // Update for the new entity solid type pVPhysics->RecheckCollisionFilter(); return true; }