コード例 #1
0
 public void UpdateSpectralValues(Vector2 windDirection, float directionality)
 {
     this.ValidateSpectrumData();
     if (this._CpuWavesDirty)
     {
         lock (this)
         {
             if (this.CpuWaves != null && this._CpuWavesDirty)
             {
                 object cpuWaves = this.CpuWaves;
                 lock (cpuWaves)
                 {
                     this._CpuWavesDirty = false;
                     float       directionalityInv           = 1f - directionality;
                     float       horizontalDisplacementScale = this._Water.Materials.HorizontalDisplacementScale;
                     int         finalResolution             = this._WindWaves.FinalResolution;
                     bool        mostlySorted = Vector2.Dot(this._LastWindDirection, windDirection) >= 0.97f;
                     WaterWave[] cpuWaves2    = this.CpuWaves;
                     for (int i = 0; i < cpuWaves2.Length; i++)
                     {
                         cpuWaves2[i].UpdateSpectralValues(this.SpectrumValues, windDirection, directionalityInv, finalResolution, horizontalDisplacementScale);
                     }
                     WaterWavesSpectrumDataBase.SortCpuWaves(cpuWaves2, mostlySorted);
                     WaterWave[] shorelineCandidates = this.ShorelineCandidates;
                     for (int j = 0; j < shorelineCandidates.Length; j++)
                     {
                         shorelineCandidates[j].UpdateSpectralValues(this.SpectrumValues, windDirection, directionalityInv, finalResolution, horizontalDisplacementScale);
                     }
                     this._LastWindDirection = windDirection;
                 }
             }
         }
     }
 }
コード例 #2
0
        private void AnalyzeSpectrum()
        {
            int finalResolution    = this._WindWaves.FinalResolution;
            int num                = finalResolution >> 1;
            int num2               = Mathf.RoundToInt(Mathf.Log((float)(finalResolution >> 1), 2f)) - 4;
            Heap <WaterWave> heap  = new Heap <WaterWave>();
            Heap <WaterWave> heap2 = new Heap <WaterWave>();

            this._StdDev = 0f;
            for (byte b = 0; b < 4; b += 1)
            {
                Vector3[] array   = this.SpectrumValues[(int)b];
                float[]   array2  = this._StandardDeviationData[(int)b] = new float[num2 + 1];
                float     num3    = 6.28318548f / this._TileSize;
                float     offsetX = this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                float     offsetZ = -this._TileSize + 0.5f / (float)finalResolution * this._TileSize;
                for (int i = 0; i < finalResolution; i++)
                {
                    float  num4 = num3 * (float)(i - num);
                    ushort num5 = (ushort)((i + num) % finalResolution);
                    ushort num6 = (ushort)((int)num5 * finalResolution);
                    for (int j = 0; j < finalResolution; j++)
                    {
                        float   num7   = num3 * (float)(j - num);
                        ushort  num8   = (ushort)((j + num) % finalResolution);
                        Vector3 vector = array[(int)(num6 + num8)];
                        float   num9   = vector.x * vector.x + vector.y * vector.y;
                        float   num10  = Mathf.Sqrt(num9);
                        float   num11  = Mathf.Sqrt(num4 * num4 + num7 * num7);
                        float   w      = Mathf.Sqrt(this._Gravity * num11);
                        if (num10 >= 0.0025f)
                        {
                            heap2.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap2.Count > 100)
                            {
                                heap2.ExtractMax();
                            }
                        }
                        if (num10 > 0.025f)
                        {
                            heap.Insert(new WaterWave(b, offsetX, offsetZ, num5, num8, num4, num7, num11, w, num10));
                            if (heap.Count > 200)
                            {
                                heap.ExtractMax();
                            }
                        }
                        int mipIndex = WaterWavesSpectrumDataBase.GetMipIndex(Mathf.Max(Mathf.Min((int)num5, finalResolution - (int)num5 - 1), Mathf.Min((int)num8, finalResolution - (int)num8 - 1)));
                        array2[mipIndex] += num9;
                    }
                }
                for (int k = 0; k < array2.Length; k++)
                {
                    array2[k]     = Mathf.Sqrt(2f * array2[k]);
                    this._StdDev += array2[k];
                }
            }
            this.CpuWaves = heap2.ToArray <WaterWave>();
            WaterWavesSpectrumDataBase.SortCpuWaves(this.CpuWaves, false);
            this.ShorelineCandidates = heap.ToArray <WaterWave>();
            Array.Sort <WaterWave>(this.ShorelineCandidates);
        }