Ejemplo n.º 1
0
        public void SetLinearRolloff(double minDistance, double maxDistance)
        {
            if (maxDistance < minDistance)
            {
                maxDistance = minDistance;
            }

            if (rolloffGraph == null || rolloffGraph.Length != 2)
            {
                rolloffGraph = new RolloffGraphItem[2];
            }
            rolloffGraph[0] = new RolloffGraphItem(minDistance, 1);
            rolloffGraph[1] = new RolloffGraphItem(maxDistance, 0);
        }
Ejemplo n.º 2
0
        public void SetLogarithmicRolloff(double minDistance, double maxDistance, double rolloffFactor)
        {
            //!!!!slowly

            if (maxDistance < minDistance)
            {
                maxDistance = minDistance;
            }

            int count = 10;

            if (rolloffGraph == null || rolloffGraph.Length != count)
            {
                rolloffGraph = new RolloffGraphItem[count];
            }
            rolloffGraph[0]         = new RolloffGraphItem(minDistance, 1);
            rolloffGraph[count - 1] = new RolloffGraphItem(maxDistance, 0);

            double distanceOffset = (maxDistance - minDistance) * .5f;

            for (int index = count - 2; index >= 1; index--)
            {
                double distance = minDistance + distanceOffset;
                double divisor  = minDistance + rolloffFactor * distanceOffset;
                double gain;
                if (divisor != 0)
                {
                    gain = minDistance / divisor;
                }
                else
                {
                    gain = 1;
                }
                MathEx.Saturate(ref gain);
                rolloffGraph[index] = new RolloffGraphItem(distance, gain);

                distanceOffset *= .5f;
            }
        }