Пример #1
0
 public void ChangeRotorSpeed(HelicopterRotor rotor, float targetVelocity, float rampTime)
 {
     if (rotor == null)
     {
         return;
     }
     if (m_rotorSpeedCoroutine != null)
     {
         StopCoroutine(m_rotorSpeedCoroutine);
     }
     m_rotorSpeedCoroutine = RotorSpeedCoroutine(rotor, targetVelocity, rampTime);
     StartCoroutine(m_rotorSpeedCoroutine);
 }
Пример #2
0
    private IEnumerator RotorSpeedCoroutine(HelicopterRotor rotor, float targetVelocity, float rampTime)
    {
        float startVelocity   = rotor.angularVelocity;
        float currentVelocity = startVelocity;
        float timeElapsed     = 0;

        while (Mathf.Abs(currentVelocity - targetVelocity) > 0)
        {
            currentVelocity       = startVelocity + (targetVelocity - startVelocity) * Mathf.Min(timeElapsed / rampTime, 1);
            rotor.angularVelocity = currentVelocity;
            timeElapsed          += Time.deltaTime;
            yield return(null);
        }
    }
Пример #3
0
    private float Delay(float sample, HelicopterRotor rotor, int sampleIndex, int channelIndex, float currentSampleRate, int totalChannels)
    {
        if (currentDelayBufferIndex >= maxDelayBufferIndex)
        {
            currentDelayBufferIndex = 0;
        }

        if (rotor == HelicopterRotor.First)
        {
            offset = (delay / 2.0f) * (1 + (float)GenerateSineSample(firstRotorPosition - Math.Floor(firstRotorPosition)) * depth) * currentSampleRate;
        }
        else if (rotor == HelicopterRotor.Second)
        {
            offset = (delay / 2.0f) * (1 + (float)GenerateSineSample(secondRotorPosition - Math.Floor(secondRotorPosition)) * depth) * currentSampleRate;
        }


        offset = offset - (offset % totalChannels) + channelIndex;
        if (offset >= maxDelayBufferIndex)
        {
            offset = maxDelayBufferIndex - 1;
        }
        else if (offset < 0)
        {
            offset = 0;
        }

        delayBufferReader = currentDelayBufferIndex - offset;

        //sprawdzamy poprawnosc indeksu, czy na pewno miesci sie w indeksach tablicy
        if (delayBufferReader >= 0)
        {
            if (delayBufferReader >= maxDelayBufferIndex)
            {
                delayBufferReader = delayBufferReader - maxDelayBufferIndex;
            }
        }
        else if (delayBufferReader < 0)
        {
            delayBufferReader = delayBufferReader + maxDelayBufferIndex;
        }

        float sampleToReturn = sample;

        try
        {
            int   firstInterpolatedSampleIndex = (int)delayBufferReader;
            float firstInterpolatedSample      = currentDelayBuffer[firstInterpolatedSampleIndex];

            int secondInterpolatedSampleIndex = ((int)delayBufferReader >= maxDelayBufferIndex - 1 - totalChannels ?
                                                 0 + sampleIndex % totalChannels
                : (int)delayBufferReader + totalChannels);

            float secondInterpolatedSample = currentDelayBuffer[secondInterpolatedSampleIndex];

            //interpolacja pomiedzy 2ma probkami
            float percent = delayBufferReader - (int)delayBufferReader;

            sampleToReturn = Mathf.Clamp(firstInterpolatedSample + (secondInterpolatedSample - firstInterpolatedSample) * percent,
                                         -1.0f, 1.0f);
        }
        catch (NullReferenceException nre)
        {
            UnityEngine.Debug.Log(nre.Message);
        }
        currentDelayBuffer[currentDelayBufferIndex] = sample;
        if (rotor == HelicopterRotor.Second)
        {
            currentDelayBufferIndex++;
        }

        return(sampleToReturn);
    }