void CClientSound::Process3D ( CVector vecPosition ) { if ( !m_pSound || !m_b3D ) return; // Update our position and velocity if we're attached CClientEntity* pAttachedToEntity = GetAttachedTo (); if ( pAttachedToEntity ) { DoAttaching (); CVector vecVelocity; if ( CStaticFunctionDefinitions::GetElementVelocity ( *pAttachedToEntity, vecVelocity ) ) SetVelocity ( vecVelocity ); } // Volume float fDistance = DistanceBetweenPoints3D ( vecPosition, m_vecPosition ); float fDistDiff = m_fMaxDistance - m_fMinDistance; float fVolume = 1.0; //Transform e^-x to suit our sound if ( fDistance <= m_fMinDistance ) fVolume = 1.0f; else if ( fDistance >= m_fMaxDistance ) fVolume = 0.0f; else fVolume = exp ( - ( fDistance - m_fMinDistance ) * ( CUT_OFF / fDistDiff ) ); BASS_ChannelSetAttribute( m_pSound, BASS_ATTRIB_VOL, fVolume * m_fVolume ); }
void CClientSound::Process3D ( CVector vecPosition, CVector vecLookAt ) { if ( !m_b3D ) return; // Update our position/rotation if we're attached DoAttaching (); if ( m_pSound ) { // Pan CVector vecLook = vecLookAt - vecPosition; CVector vecSound = m_vecPosition - vecPosition; vecLook.fZ = vecSound.fZ = 0.0f; vecLook.Normalize (); vecSound.Normalize (); vecLook.CrossProduct ( &vecSound ); // The length of the cross product (which is simply fZ in this case) // is equal to the sine of the angle between the vectors float fPan = vecLook.fZ; if ( fPan < -1.0f + SOUND_PAN_THRESHOLD ) fPan = -1.0f + SOUND_PAN_THRESHOLD; else if ( fPan > 1.0f - SOUND_PAN_THRESHOLD ) fPan = 1.0f - SOUND_PAN_THRESHOLD; m_pSound->setPan ( fPan ); // Volume float fDistance = DistanceBetweenPoints3D ( vecPosition, m_vecPosition ); float fSilenceDistance = m_fMinDistance * 20.0f; float fVolume = 1.0; if ( fDistance <= m_fMinDistance ) { fVolume = 1.0f; } else if ( fDistance >= fSilenceDistance ) { fVolume = 0.0f; } else { float fLinear = (fSilenceDistance - fDistance) / fSilenceDistance; fVolume = sqrt ( fLinear ) * fLinear; } m_pSound->setVolume ( m_fVolume * fVolume ); } }
void CBassAudio::Process3D ( const CVector& vecPlayerPosition, const CVector& vecCameraPosition, const CVector& vecLookAt ) { assert ( m_b3D && m_pSound ); float fDistance = DistanceBetweenPoints3D ( vecCameraPosition, m_vecPosition ); if ( m_bPan ) { // Limit panning when getting close to the min distance float fPanSharpness = UnlerpClamped ( m_fMinDistance, fDistance, m_fMinDistance * 2 ); float fPanLimit = Lerp ( 0.35f, fPanSharpness, 1.0f ); // Pan CVector vecLook = vecLookAt - vecCameraPosition; CVector vecSound = m_vecPosition - vecCameraPosition; vecLook.fZ = vecSound.fZ = 0.0f; vecLook.Normalize (); vecSound.Normalize (); vecLook.CrossProduct ( &vecSound ); // The length of the cross product (which is simply fZ in this case) // is equal to the sine of the angle between the vectors float fPan = Clamp ( -fPanLimit, -vecLook.fZ, fPanLimit ); BASS_ChannelSetAttribute( m_pSound, BASS_ATTRIB_PAN, fPan ); } else { // Revert to middle. BASS_ChannelSetAttribute( m_pSound, BASS_ATTRIB_PAN, 0.0f ); } // Volume float fDistDiff = m_fMaxDistance - m_fMinDistance; //Transform e^-x to suit our sound float fVolume; if ( fDistance <= m_fMinDistance ) fVolume = 1.0f; else if ( fDistance >= m_fMaxDistance ) fVolume = 0.0f; else fVolume = exp ( - ( fDistance - m_fMinDistance ) * ( CUT_OFF / fDistDiff ) ); BASS_ChannelSetAttribute( m_pSound, BASS_ATTRIB_VOL, fVolume * m_fVolume ); }
void CRPCFunctions::RequestStealthKill ( NetBitStreamInterface & bitStream ) { ElementID ID; bitStream.ReadCompressed ( ID ); CElement * pElement = CElementIDs::GetElement ( ID ); if ( pElement ) { int elementType = pElement->GetType (); if ( elementType == CElement::PLAYER || elementType == CElement::PED ) { CPed * pTarget = static_cast < CPed * > ( pElement ); // Are they both alive? if ( !m_pSourcePlayer->IsDead () && !pTarget->IsDead () ) { //Do we have any record of the killer currently having a knife? if ( m_pSourcePlayer->GetWeaponType( 1 ) == 4 ) { // Are they close enough? if ( DistanceBetweenPoints3D ( m_pSourcePlayer->GetPosition (), pTarget->GetPosition () ) <= STEALTH_KILL_RANGE ) { CLuaArguments Arguments; Arguments.PushElement ( pTarget ); if ( m_pSourcePlayer->CallEvent ( "onPlayerStealthKill", Arguments, false ) ) { // Start the stealth kill CStaticFunctionDefinitions::KillPed ( pTarget, m_pSourcePlayer, 4 /*WEAPONTYPE_KNIFE*/, 9/*BODYPART_HEAD*/, true ); } } } else { //You shouldn't be able to get here without cheating to get a knife. if ( !g_pGame->GetConfig ()->IsDisableAC ( "2" ) ) { CStaticFunctionDefinitions::KickPlayer ( m_pSourcePlayer, NULL, "AC #2: You were kicked from the game" ); } } } } } }
int CLuaFunctionDefs::GetDistanceBetweenPoints3D ( lua_State* luaVM ) { CVector vecA, vecB; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecA ); argStream.ReadVector3D ( vecB ); if ( !argStream.HasErrors () ) { lua_pushnumber ( luaVM, DistanceBetweenPoints3D ( vecA, vecB ) ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetDistanceBetweenPoints3D ( lua_State* luaVM ) { // float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 ) CVector vecPointA; CVector vecPointB; CScriptArgReader argStream ( luaVM ); argStream.ReadVector3D ( vecPointA ); argStream.ReadVector3D ( vecPointB ); if ( !argStream.HasErrors () ) { // Return the distance lua_pushnumber ( luaVM, DistanceBetweenPoints3D ( vecPointA, vecPointB ) ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }