コード例 #1
0
        private List <Gerstner2.Settings> CreateWaves(double angle, double wavelength, double amplitude, double steepness)
        {
            var waveSettings = new List <Gerstner2.Settings>();
            var random       = new Random(4711);
            int waves        = 5;

            for (var i = 0; i < waves; i++)
            {
                var waveLengthFactor = wavelength * 2 - wavelength / 2;
                var minWaveLength    = wavelength / 2;
                var nextDouble       = random.NextDouble();
                var waveLength2      = minWaveLength + nextDouble * waveLengthFactor;

                var amplitudeSpan = amplitude * 2 - amplitude / 2;
                var minAmplitude  = amplitude / 2;
                var amplitude2    = minAmplitude + nextDouble * amplitudeSpan;

                var frequency = CalculateFrequency(waveLength2);

                var directionRad = angle + (random.NextDouble() - 0.5);
                var direction    = new Vector2d(Math.Cos(directionRad), Math.Sin(directionRad));

                //How to handle the amplitude is a matter of opinion. Although derivations of wave amplitude as a function of wavelength and current weather conditions probably exist,
                //we use a constant (or scripted) ratio, specified at authoring time. More exactly, along with a median wavelength, the artist specifies a median amplitude.
                //For a wave of any size, the ratio of its amplitude to its wavelength will match the ratio of the median amplitude to the median wavelength.

                var q = steepness / (frequency * amplitude2 * waves);

                var s = new Gerstner2.Settings
                {
                    Direction  = direction.Normalized(),
                    WaveLength = waveLength2,
                    Frequency  = frequency,
                    Steepness  = steepness,
                    Phase      = nextDouble,
                };

                waveSettings.Add(s);
            }

            return(waveSettings);
        }
コード例 #2
0
        private List<Gerstner2.Settings> CreateWaves(double angle, double wavelength, double amplitude, double steepness)
        {
            var waveSettings = new List<Gerstner2.Settings>();
            var random = new Random(4711);
            int waves = 5;
            for (var i = 0; i < waves; i++)
            {
                var waveLengthFactor = wavelength * 2 - wavelength / 2;
                var minWaveLength = wavelength / 2;
                var nextDouble = random.NextDouble();
                var waveLength2 = minWaveLength + nextDouble * waveLengthFactor;

                var amplitudeSpan = amplitude * 2 - amplitude / 2;
                var minAmplitude = amplitude / 2;
                var amplitude2 = minAmplitude + nextDouble * amplitudeSpan;

                var frequency = CalculateFrequency(waveLength2);

                var directionRad = angle + (random.NextDouble() - 0.5);
                var direction = new Vector2d(Math.Cos(directionRad), Math.Sin(directionRad));

                //How to handle the amplitude is a matter of opinion. Although derivations of wave amplitude as a function of wavelength and current weather conditions probably exist,
                //we use a constant (or scripted) ratio, specified at authoring time. More exactly, along with a median wavelength, the artist specifies a median amplitude.
                //For a wave of any size, the ratio of its amplitude to its wavelength will match the ratio of the median amplitude to the median wavelength.

                var q = steepness / (frequency * amplitude2 * waves);

                var s = new Gerstner2.Settings
                {
                    Direction = direction.Normalized(),
                    WaveLength = waveLength2,
                    Frequency = frequency,
                    Steepness = steepness,
                    Phase = nextDouble,
                };

                waveSettings.Add(s);
            }

            return waveSettings;
        }