Esempio n. 1
0
        static public bool create(Dictionary <string, object> dict, List <Wave> waves)
        {
            if (MiniJsonHelper.getString(dict, "type", "") != "trochoidStraight")
            {
                return(false);
            }
            int num = MiniJsonHelper.getInt(dict, "num", 1);

            float[] degree        = MiniJsonHelper.getFloatArray(dict, "degree");
            float[] waveLength    = MiniJsonHelper.getFloatArray(dict, "waveLength");
            float[] amplitudeRate = MiniJsonHelper.getFloatArray(dict, "amplitudeRate");
            float[] phase         = MiniJsonHelper.getFloatArray(dict, "phase");
            float[] sec           = MiniJsonHelper.getFloatArray(dict, "sec");

            // 生成
            var rand = new Random();

            for (int i = 0; i < num; ++i)
            {
                var wave = new TrochoidStraightWave();
                wave.Degree        = frand(degree, rand);
                wave.WaveLength    = frand(waveLength, rand);
                wave.AmplitudeRate = frand(amplitudeRate, rand);
                wave.PhaseSpeed    = frand(phase, rand);
                wave.setTime(frand(sec, rand));
                waves.Add(wave);
            }

            return(true);
        }
        static public bool create(Dictionary <string, object> dict, List <Wave> waves)
        {
            if (MiniJsonHelper.getString(dict, "type", "") != "trochoidRipple")
            {
                return(false);
            }
            int num = MiniJsonHelper.getInt(dict, "num", 1);

            float[] radius        = MiniJsonHelper.getFloatArray(dict, "radius");
            float[] waveLength    = MiniJsonHelper.getFloatArray(dict, "waveLength");
            float[] amplitudeRate = MiniJsonHelper.getFloatArray(dict, "amplitudeRate");
            float[] phase         = MiniJsonHelper.getFloatArray(dict, "phase");
            float[] sec           = MiniJsonHelper.getFloatArray(dict, "sec");

            // 生成
            var rand = new Random();

            for (int i = 0; i < num; ++i)
            {
                var     wave   = new TrochoidRippleWave();
                float   rad    = ( float )(rand.NextDouble() * 2.0 * Math.PI);
                float   r      = frand(radius, rand);
                Vector2 center = new Vector2();
                wave.Center        = circleRrand(radius, rand, ref center);
                wave.WaveLength    = frand(waveLength, rand);
                wave.AmplitudeRate = frand(amplitudeRate, rand);
                wave.PhaseSpeed    = frand(phase, rand);
                wave.setTime(frand(sec, rand));
                waves.Add(wave);
            }

            return(true);
        }
Esempio n. 3
0
        // 外部データで波を生成
        private void loadGenDataBtn_Click(object sender, EventArgs e)
        {
            // Jsonからデータ読み込み

            var dialog = new OpenFileDialog();

            dialog.Filter = "JSON(*.json)|*.json";
            dialog.Title  = "Select wave generate data.";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var stream = new System.IO.StreamReader(dialog.FileName);
            var json   = stream.ReadToEnd();

            stream.Close();
            var root = MiniJSON.Json.Deserialize(json);

            if (root == null)
            {
                MessageBox.Show("読み込みに失敗しました。");
                return;
            }
            var rootDict = root as Dictionary <string, object>;

            var newWaves = new List <Wave>();

            foreach (var obj in rootDict)
            {
                var waveData = obj.Value as Dictionary <string, object>;
                if (waveData == null)
                {
                    continue;
                }
                string type = MiniJsonHelper.getString(waveData, "type", "");
                switch (( string )waveData["type"])
                {
                case "sinRipple":
                    SinRippleWaveData.create(waveData, newWaves);
                    break;

                case "sinStraight":
                    SinStraightWaveData.create(waveData, newWaves);
                    break;

                case "trochoidRipple":
                    TrochoidRippleWaveData.create(waveData, newWaves);
                    break;

                case "trochoidStraight":
                    TrochoidStraightWaveData.create(waveData, newWaves);
                    break;
                }
            }

            foreach (var wave in newWaves)
            {
                // Wave追加
                waves_.Add(wave);
                waveSelector.Items.Add("Wave", true);
            }
        }