public static bool UpdateInfluenceSphereSoundScript(MyInfluenceSphereSound influenceSphereSound) { if ((m_remainingPrimaryTargetsCounter == 0) && (MyHud.ContainsTextForEntity(influenceSphereSound) == false)) { MyHud.AddText(influenceSphereSound, new StringBuilder("Russian Drop Zone"), Color.Green); } return(true); }
// This method is responsible for getting only nearest spheres and apply volume change/interpolation of ambient sounds public void UpdateSounds(ref BoundingSphere boundingSphere) { foreach (MyInfluenceSphereSound soundSphere in m_soundSpheresSAP) { float dx = soundSphere.WorldVolume.Radius * 2; if (dx > m_largestDustX) { m_largestSoundX = dx; } soundSphere.Enabled = false; if (MyFakes.TEST_MISSION_1_ENABLED) { MyTestMission.UpdateInfluenceSphereSoundScript(soundSphere); } } m_sortedSoundSpheres.Clear(); float xMin = boundingSphere.Center.X - boundingSphere.Radius; float xMax = boundingSphere.Center.X + boundingSphere.Radius; // Take only sounds that can have influence on our bounding sphere int search = BinarySearchSAP(m_soundSpheresSAP, xMin - m_largestSoundX); while (search < m_soundSpheresSAP.Count && (m_soundSpheresSAP[search].GetPosition().X - m_soundSpheresSAP[search].WorldVolume.Radius) < xMax) { MyInfluenceSphereSound soundSphere = (MyInfluenceSphereSound)m_soundSpheresSAP[search]; if ((soundSphere.GetPosition().X + soundSphere.WorldVolume.Radius) > xMin) { // Don't add more sounds into sorting list than our 'sorting list' can handle if (m_sortedSoundSpheres.Count >= MyInfluenceSphereConstants.MAX_SOUND_SPHERES_COUNT_FOR_SORT) { break; } float distance = Vector3.Distance(soundSphere.GetPosition(), boundingSphere.Center); float maxDistance = boundingSphere.Radius + soundSphere.WorldVolume.Radius; if (distance <= maxDistance) { m_sortedSoundSpheres.Add(soundSphere); } } ++search; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Now in 'm_sortedSoundSpheres' we have only sounds that intersects bounding sphere in SAP list //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // handle sounds foreach (MyInfluenceSphereSound soundSphere in m_sortedSoundSpheres) { soundSphere.Enabled = true; float normalizedVolume = 0.0f; Vector3 influencedPosition = boundingSphere.Center; Vector3 soundSpherePosition = soundSphere.GetPosition(); float distance = Math.Abs(Vector3.Distance(soundSpherePosition, influencedPosition)); float radiusMin = soundSphere.InnerBoundingSphere.Radius; float radiusMax = soundSphere.WorldVolume.Radius; // if we are located in the center sphere, sound volume must be full if (distance <= radiusMin) { normalizedVolume = 1.0f; } else if ((distance > radiusMin) && (distance <= radiusMax)) // interpolate volume between radiusMin and radiusMax { float total = (radiusMax - radiusMin); float normalizedDistance = MathHelper.Clamp((distance - radiusMin) / total, 0, 1); normalizedVolume = MathHelper.Lerp(1, 0, normalizedDistance); } soundSphere.SetVolume(normalizedVolume); soundSphere.UpdateAfterIntegration(); } }
public static bool UpdateInfluenceSphereSoundScript(MyInfluenceSphereSound influenceSphereSound) { if ((m_remainingPrimaryTargetsCounter == 0) && (MyHud.ContainsTextForEntity(influenceSphereSound) == false)) { MyHud.AddText(influenceSphereSound, new StringBuilder("Russian Drop Zone"), Color.Green); } return true; }