Beispiel #1
0
        public void SetNormalizedSamples(int xWorldLocationMeters, int zWorldLocationMeters, int metersPerSample, float[,] normalizedSamples)
        {
            int sizeXSamples = normalizedSamples.GetLength(0);
            int sizeZSamples = normalizedSamples.GetLength(1);

            float[,] diffArray = new float[sizeXSamples, sizeZSamples];

            bool wasModified = Mosaic.Modified;

            try
            {
                changeNotificationEnabled = false;

                // Calculate the heights and set them
                {
                    int worldZMeters = zWorldLocationMeters;
                    for (int sampleZ = 0; sampleZ < sizeZSamples; sampleZ++)
                    {
                        int worldXMeters = xWorldLocationMeters;
                        for (int sampleX = 0; sampleX < sizeXSamples; sampleX++)
                        {
                            float heightNormalized = normalizedSamples[sampleX, sampleZ];

                            // Make sure the normalized height is within the proper bounds
                            if (heightNormalized < 0)
                            {
                                heightNormalized = 0;
                            }
                            else if (heightNormalized > 1)
                            {
                                heightNormalized = 1;
                            }

                            float heightMM = ConvertNormalizedHeightToMM(heightNormalized);
                            diffArray[sampleX, sampleZ] = heightMM - Mosaic.GetWorldHeightMM(worldXMeters, worldZMeters);

                            worldXMeters += metersPerSample;
                        }

                        worldZMeters += metersPerSample;
                    }

                    Mosaic.AdjustWorldSamplesMM(xWorldLocationMeters, zWorldLocationMeters, metersPerSample, diffArray);
                }
            }
            finally
            {
                changeNotificationEnabled = true;

                if (Modified != wasModified)
                {
                    FireTerrainModificationStateChanged();
                }

                FireTerrainChanged(xWorldLocationMeters, zWorldLocationMeters, sizeXSamples * metersPerSample, sizeZSamples * metersPerSample);
            }
        }