Esempio n. 1
0
 public Gerstner4(GerstnerWave wave0, GerstnerWave wave1, GerstnerWave wave2, GerstnerWave wave3)
 {
     this.Wave0 = wave0;
     this.Wave1 = wave1;
     this.Wave2 = wave2;
     this.Wave3 = wave3;
 }
        private void FindMostMeaningfulWaves()
        {
            this._WindWaves.SpectrumResolver.SetDirectWaveEvaluationMode(this._Data.NumGerstners);
            WaterWave[] directWaves = this._WindWaves.SpectrumResolver.DirectWaves;
            int         num         = 0;
            int         num2        = directWaves.Length >> 2;

            this._GerstnerFours = new Gerstner4[num2];
            Vector2[] array = new Vector2[4];
            for (int i = 0; i < 4; i++)
            {
                float num3 = this._WindWaves.TileSizes[i];
                array[i].x = num3 + 0.5f / (float)this._WindWaves.FinalResolution * num3;
                array[i].y = -num3 + 0.5f / (float)this._WindWaves.FinalResolution * num3;
            }
            for (int j = 0; j < num2; j++)
            {
                GerstnerWave wave  = (num >= directWaves.Length) ? new GerstnerWave() : new GerstnerWave(directWaves[num++], array);
                GerstnerWave wave2 = (num >= directWaves.Length) ? new GerstnerWave() : new GerstnerWave(directWaves[num++], array);
                GerstnerWave wave3 = (num >= directWaves.Length) ? new GerstnerWave() : new GerstnerWave(directWaves[num++], array);
                GerstnerWave wave4 = (num >= directWaves.Length) ? new GerstnerWave() : new GerstnerWave(directWaves[num++], array);
                this._GerstnerFours[j] = new Gerstner4(wave, wave2, wave3, wave4);
            }
            this.UpdateMaterial();
        }
        private void CreateShoalingSpawnPoints()
        {
            Bounds bounds = new Bounds(base.transform.position, new Vector3(this._BoundsSize.x, 0f, this._BoundsSize.y));
            float  x      = bounds.min.x;
            float  z      = bounds.min.z;
            float  x2     = bounds.max.x;
            float  z2     = bounds.max.z;
            float  num    = Mathf.Sqrt(this._SpawnPointsDensity);
            float  num2   = Mathf.Max(35f, bounds.size.x / 256f) / num;
            float  num3   = Mathf.Max(35f, bounds.size.z / 256f) / num;

            bool[,] array = new bool[32, 32];
            List <ComplexWavesEmitter.SpawnPoint> list = new List <ComplexWavesEmitter.SpawnPoint>();

            GerstnerWave[] array2 = this._WindWaves.SpectrumResolver.SelectShorelineWaves(50, 0f, 360f);
            if (array2.Length == 0)
            {
                this._SpawnPoints = new ComplexWavesEmitter.SpawnPoint[0];
                return;
            }
            float num4 = this._SpawnDepth * 0.85f;
            float num5 = this._SpawnDepth * 1.18f;

            for (float num6 = z; num6 < z2; num6 += num3)
            {
                for (float num7 = x; num7 < x2; num7 += num2)
                {
                    int num8 = Mathf.FloorToInt(32f * (num7 - x) / (x2 - x));
                    int num9 = Mathf.FloorToInt(32f * (num6 - z) / (z2 - z));
                    if (!array[num8, num9])
                    {
                        float totalDepthAt = StaticWaterInteraction.GetTotalDepthAt(num7, num6);
                        if (totalDepthAt > num4 && totalDepthAt < num5 && UnityEngine.Random.value < 0.06f)
                        {
                            array[num8, num9] = true;
                            Vector2 vector;
                            vector.x = StaticWaterInteraction.GetTotalDepthAt(num7 - 3f, num6) - StaticWaterInteraction.GetTotalDepthAt(num7 + 3f, num6);
                            vector.y = StaticWaterInteraction.GetTotalDepthAt(num7, num6 - 3f) - StaticWaterInteraction.GetTotalDepthAt(num7, num6 + 3f);
                            vector.Normalize();
                            GerstnerWave gerstnerWave = array2[0];
                            float        num10        = Vector2.Dot(vector, array2[0].Direction);
                            for (int i = 1; i < array2.Length; i++)
                            {
                                float num11 = Vector2.Dot(vector, array2[i].Direction);
                                if (num11 > num10)
                                {
                                    num10        = num11;
                                    gerstnerWave = array2[i];
                                }
                            }
                            list.Add(new ComplexWavesEmitter.SpawnPoint(new Vector2(num7, num6), vector, gerstnerWave.Frequency, Mathf.Abs(gerstnerWave.Amplitude), gerstnerWave.Speed));
                        }
                    }
                }
            }
            this._SpawnPoints = list.ToArray();
        }
Esempio n. 4
0
        public GerstnerWave[] SelectShorelineWaves(int waveCount, float angle, float coincidenceRange)
        {
            Heap <WaterWave> heap = new Heap <WaterWave>();

            for (int i = this._SpectraDataList.Count - 1; i >= 0; i--)
            {
                WaterWavesSpectrumDataBase waterWavesSpectrumDataBase = this._SpectraDataList[i];
                waterWavesSpectrumDataBase.UpdateSpectralValues(this.WindDirection, this._WindWaves.SpectrumDirectionality);
                object obj = waterWavesSpectrumDataBase;
                lock (obj)
                {
                    float weight = waterWavesSpectrumDataBase.Weight;
                    foreach (WaterWave element in waterWavesSpectrumDataBase.ShorelineCandidates)
                    {
                        element._Amplitude   *= weight;
                        element._CPUPriority *= weight;
                        float current = Mathf.Atan2(element._Nkx, element._Nky) * 57.29578f;
                        if (Mathf.Abs(Mathf.DeltaAngle(current, angle)) < coincidenceRange && element._Amplitude > 0.025f)
                        {
                            heap.Insert(element);
                            if (heap.Count > waveCount)
                            {
                                heap.ExtractMax();
                            }
                        }
                    }
                }
            }
            Vector2[] array = new Vector2[4];
            for (int k = 0; k < 4; k++)
            {
                float num = this._WindWaves.TileSizes[k];
                array[k].x = num + 0.5f / (float)this._WindWaves.FinalResolution * num;
                array[k].y = -num + 0.5f / (float)this._WindWaves.FinalResolution * num;
            }
            WaterWave[] array2 = heap.ToArray <WaterWave>();
            int         num2   = Mathf.Min(heap.Count, waveCount);

            GerstnerWave[] array3 = new GerstnerWave[num2];
            for (int l = 0; l < num2; l++)
            {
                array3[l] = new GerstnerWave(array2[heap.Count - l - 1], array);
            }
            return(array3);
        }
        private void CreateSpectralWavesSpawnPoints()
        {
            Vector3 normalized = base.transform.forward.normalized;
            float   num        = Mathf.Atan2(normalized.x, normalized.z);

            GerstnerWave[] array = this._WindWaves.SpectrumResolver.SelectShorelineWaves(this._SpectrumWavesCount, num * 57.29578f, this._SpectrumCoincidenceRange);
            this._SpectrumWavesCount = array.Length;
            Vector3 vector = new Vector3(base.transform.position.x + this._Span * 0.5f, 0f, base.transform.position.z + this._Span * 0.5f);
            Vector2 a      = new Vector2(vector.x, vector.z);
            List <ComplexWavesEmitter.SpawnPoint> list = new List <ComplexWavesEmitter.SpawnPoint>();

            for (int i = 0; i < this._SpectrumWavesCount; i++)
            {
                GerstnerWave gerstnerWave = array[i];
                if (gerstnerWave.Amplitude != 0f)
                {
                    Vector2 position = a - gerstnerWave.Direction * this._Span * 0.5f;
                    list.Add(new ComplexWavesEmitter.SpawnPoint(position, gerstnerWave.Direction, gerstnerWave.Frequency, Mathf.Abs(gerstnerWave.Amplitude), gerstnerWave.Speed));
                }
            }
            this._SpawnPoints = list.ToArray();
        }