Ejemplo n.º 1
0
        //This is a bit of a replacement of the curves, small but powerful and quite simple
        public static float SmoothValue(SmoothingMethod method, float x)
        {
            switch (method)
            {
            case SmoothingMethod.Linear:
                return(x);

            case SmoothingMethod.Smooth:
                return(x * x * (3.0f - 2.0f * x));

            case SmoothingMethod.Accelerate:
                return(x * x);

            case SmoothingMethod.Decelerate:
                x  = 1.0f - x;
                x *= x;
                return(1.0f - x);

            case SmoothingMethod.Back:
                x = 1.0f - x;
                x = (float)(x * x * x - x * Math.Sin(x * Math.PI));
                return(1.0f - x);
            }

            return(x);
        }
Ejemplo n.º 2
0
    void OnEnable()
    {
        // init the serial connections
        axiomserialController.Init();
        bfPedalController.Init();
        bfWheelController.Init();
        bfTiltController.Init();

        layerIndices = new Dictionary <Layers, int>();

        smoothingMethod      = SmoothingMethod.Average;
        wheelSmooth          = new float[wheelSmoothFactor];
        invWheelSmoothFactor = 1f / wheelSmoothFactor;

        //- debug

        profiler = GameProfiler.Get("GameProfiler");
        var settings = profiler.Add("Raw");

        settings.min = 0;
        settings.max = 60;
        var settings2 = profiler.Add("Median");

        settings2.min = 0;
        settings2.max = 60;
        var settings3 = profiler.Add("Mean");

        settings3.min = 0;
        settings3.max = 60;
    }
Ejemplo n.º 3
0
    float GetRelativeRearWheelAngle(SmoothingMethod sMethod)
    {
        float newWheelAngle = bfWheelController.GetAbsoluteAngle();
        float ret           = MathUtils.GetSignedAngleDiff(newWheelAngle, oldWheelAngle);

        //- Debug

        profiler.Update("Raw", ret);
        profiler.Update("Mean", GetAverage());
        profiler.Update("Median", GetMedian());


        oldWheelAngle = newWheelAngle;

        if (sMethod == SmoothingMethod.None)
        {
            return(ret);
        }
        else
        {
            return(LowPass(ret, sMethod));
        }
    }
Ejemplo n.º 4
0
    float LowPass(float newVal, SmoothingMethod sMethod)
    {
        wheelSmooth[wheelSmoothPtr] = newVal;

        float ret;

        if (sMethod == SmoothingMethod.Average)
        {
            ret = GetAverage();
        }
        else if (sMethod == SmoothingMethod.Median)
        {
            ret = GetMedian();
        }
        else
        {
            Debug.LogError("Wrong SmoothingMethod: Return 0");
            ret = 0.0f;
        }

        wheelSmoothPtr = ++wheelSmoothPtr % wheelSmoothFactor;

        return(ret);
    }