コード例 #1
0
    private Vector3 WaveFunction(Vector3 origin, float timeCode)
    {
        // sine wave with an amplitude of 1 unit and a period of 2π units,
        // traveling with a speed of 1 unit per second.
        // Change this to your own wave function.
        if (manager.ApplyP())
        {
            Vector3 newVertex = origin;

            d      = v_p * (timeCode % 5);
            lambda = (float)(v_p / f);
            if (origin.x < d)
            {
                newVertex = new Vector3((float)(origin.x - A * Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (origin.x / v_p)))),
                                        origin.y,
                                        origin.z);
            }

            return(newVertex);
        }
        else if (manager.ApplyS())
        {
            Vector3 newVertex = origin;
            d      = v_s * (timeCode % 5);
            lambda = (float)(v_s / f);
            if (origin.x < d)
            {
                newVertex = new Vector3(
                    origin.x,
                    origin.y,
                    origin.z + (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (origin.x / v_s)))));
            }

            return(newVertex);
        }
        else if (manager.ApplyEarthquake())
        {
            return(origin);
        }
        else
        {
            return(origin);
        }
    }
コード例 #2
0
    private Vector3 WaveFunction(Vector3 origin, float timeCode)
    {
        // sine wave with an amplitude of 1 unit and a period of 2π units,
        // traveling with a speed of 1 unit per second.
        // Change this to your own wave function.
        if (manager.ApplyP())
        {
            d = v_p * (timeCode);
            float   r         = Mathf.Sqrt(Mathf.Pow(origin.x, 2) + Mathf.Pow(origin.y, 2));
            float   cos_theta = origin.x / r;
            float   sin_theta = origin.y / r;
            Vector3 newVertex = origin;
            if (r < d)
            {
                newVertex = new Vector3(
                    origin.x + (cos_theta) * (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_p)))),
                    origin.y + (sin_theta) * (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_p)))),
                    origin.z);
            }
            ;

            return(newVertex);
        }
        else if (manager.ApplyS())
        {
            d = v_s * (timeCode);
            float   r         = Mathf.Sqrt(Mathf.Pow(origin.x, 2) + Mathf.Pow(origin.y, 2));
            Vector3 newVertex = origin;

            if (r < d)
            {
                newVertex = new Vector3(
                    origin.x,
                    origin.y,
                    origin.z + (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_s)))));
            }
            return(newVertex);
        }
        else if (manager.ApplyEarthquake())
        {
            if ((int)timeCode % 40 == 0)
            {
                time_spend = timeCode;
            }

            float r = Mathf.Sqrt(Mathf.Pow(origin.x, 2) + Mathf.Pow(origin.y, 2));

            float d_p_start = v_p * (timeCode - time_spend);
            float d_p_end   = d_p_start - v_p * 2;
            float cos_theta = origin.x / r;
            float sin_theta = origin.y / r;

            float d_s_start = v_s * (timeCode - time_spend);
            float d_s_end   = d_s_start - v_s * 2;


            Vector3 newVertex = origin;

            if (r > d_p_end && r < d_p_start)
            {
                newVertex = new Vector3(
                    origin.x + (cos_theta) * (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_p)))),
                    origin.y + (sin_theta) * (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_p)))),
                    origin.z);
            }

            if (r > d_s_end && r < d_s_start)
            {
                newVertex = new Vector3(
                    origin.x,
                    origin.y,
                    origin.z + (float)A * (Mathf.Cos(2 * Mathf.PI * (Time.fixedTime - (r / v_s)))));
            }

            return(newVertex);
        }
        else
        {
            return(origin);
        }
    }