示例#1
0
    // Update is called once per frame
    void Update()
    {
        /*
         * Performs the various tasks in sequence
         * 1) Takes user input
         * 2) Calculates fourier series for all approximators
         * 3) Calls FunctionUpdate for each approximator
         * 4) Checks for display toggled on/off for a particular approximator.
         */

        if (!input_taken)
        {
            input_taken = userFunction.CheckForInput();
        }

        else if (!fourier_series_calculated)
        {
            for (int i = 0; i < number_of_approximators; i++)
            {
                ApplyFourierSeries temp = fourier_series_drawers[i].GetComponent <ApplyFourierSeries>();
                temp.CalculateFourierSeries(userFunction.function_to_transform, (int)Math.Pow(2, i + 2));
            }
            drawcoefficients.CalculateFourierSeries(userFunction.function_to_transform, 16);
            fourier_series_calculated = true;
        }
        else
        {
            for (int i = 0; i < number_of_approximators; i++)
            {
                ApplyFourierSeries temp = fourier_series_drawers[i].GetComponent <ApplyFourierSeries>();
                temp.FunctionUpdate();
            }

            drawcoefficients.FunctionUpdate();
        }

        foreach (KeyValuePair <KeyCode, int> entry in keyCodeDic)
        {
            //Check if the keycode is pressed
            if (Input.GetKeyDown(entry.Key))
            {
                //Toggle visibility of GameObject and line renderer

                LineRenderer lr = fourier_series_drawers[entry.Value].GetComponent <LineRenderer>();
                Renderer     r  = fourier_series_drawers[entry.Value].GetComponent <Renderer>();
                lr.enabled = !lr.enabled;
                r.enabled  = !r.enabled;
            }
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            //Toggle visibility of DrawCoefficients
            drawcoefficients.ToggleVisibility();
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            //Toggle visibility of DrawCoefficients
            userFunction.ToggleVisibility();
        }
    }