Example #1
0
        void PaintPath(SimulationTarget target)
        {
            Vector3 lastPos   = transform.position;
            Color   lastColor = new Color(0, 1, 0, .5f);
            float   colorStep = 1f / Bounces,
                    alphaStep = colorStep * .25f;

            for (int hit = 0; hit < hitCount; ++hit)
            {
                lastColor.r += colorStep;
                lastColor.b += colorStep;
                lastColor.a -= alphaStep;
                Gizmos.color = lastColor;
                Gizmos.DrawLine(lastPos, hits[hit]);
                lastPos = hits[hit];
            }
        }
Example #2
0
        void MixImpulse(SimulationTarget target)
        {
            if (!target.HasClip)
            {
                return;
            }
            float distance;

            if (hitCount != 0)
            {
                distance = Vector3.Distance(transform.position, hits[0]);
                int lastHit = hitCount - 1;
                for (int hit = 0; hit < lastHit; ++hit)
                {
                    distance += Vector3.Distance(hits[hit], hits[hit + 1]);
                }
                distance += Vector3.Distance(hits[lastHit], target.transform.position);
            }
            else
            {
                distance = Vector3.Distance(transform.position, target.transform.position);
            }
            float timeOffset = distance / SpeedOfSound * target.SampleRate;

            if (timeOffset < target.MaxSamples - 1)
            {
                float gain = 1f / timeOffset;
                if (gain > 1)
                {
                    gain = 1;
                }
                if (ChangePhase && hitCount % 2 == 1)
                {
                    gain = -gain;
                }
                target.Impulse[(int)timeOffset] += gain;
            }
        }