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);
            }
        }
Beispiel #2
0
        public void GenerateNormal(Vector3 worldLocationMM, out Vector3 normal)
        {
            int   x          = (int)(worldLocationMM.x / TerrainManager.oneMeter);
            int   z          = (int)(worldLocationMM.z / TerrainManager.oneMeter);
            float x1HeightMM = Mosaic.GetWorldHeightMM(x - 1, z);
            float x2HeightMM = Mosaic.GetWorldHeightMM(x + 1, z);
            float z1HeightMM = Mosaic.GetWorldHeightMM(x, z - 1);
            float z2HeightMM = Mosaic.GetWorldHeightMM(x, z + 1);

            GenerateNormal(x1HeightMM, x2HeightMM, z1HeightMM, z2HeightMM, out normal);
        }
Beispiel #3
0
        public float[,] GetNormalizedSamples(int xWorldLocationMeters, int zWorldLocationMeters, int sizeXSamples, int sizeZSamples, int metersPerSample)
        {
            float[,] normalizedSamples = new float[sizeXSamples, sizeZSamples];

            int worldZMeters = zWorldLocationMeters;

            for (int sampleZ = 0; sampleZ < sizeZSamples; sampleZ++)
            {
                int worldXMeters = xWorldLocationMeters;
                for (int sampleX = 0; sampleX < sizeXSamples; sampleX++)
                {
                    float heightMM         = Mosaic.GetWorldHeightMM(worldXMeters, worldZMeters);
                    float heightNormalized = ConvertHeightMMToNormalized(heightMM);

                    normalizedSamples[sampleX, sampleZ] = heightNormalized;

                    worldXMeters += metersPerSample;
                }

                worldZMeters += metersPerSample;
            }

            return(normalizedSamples);
        }
Beispiel #4
0
        public void GenerateHeightFieldMM(float xWorldLocationMeters, float zWorldLocationMeters, int metersPerSample, float[,] heightFieldMM, out float minHeightMM, out float maxHeightMM)
        {
            minHeightMM = float.MaxValue;
            maxHeightMM = float.MinValue;
            int sampleWidth  = heightFieldMM.GetLength(0);
            int sampleHeight = heightFieldMM.GetLength(1);

            int xWorldOffsetMeters = (int)xWorldLocationMeters;

            for (int x = 0; x < sampleWidth; x++)
            {
                int zWorldOffsetMeters = (int)zWorldLocationMeters;
                for (int z = 0; z < sampleHeight; z++)
                {
                    float heightMM = Mosaic.GetWorldHeightMM(xWorldOffsetMeters, zWorldOffsetMeters);
                    heightFieldMM[x, z] = heightMM;
                    minHeightMM         = Math.Min(minHeightMM, heightMM);
                    maxHeightMM         = Math.Max(minHeightMM, heightMM);

                    zWorldOffsetMeters += metersPerSample;
                }
                xWorldOffsetMeters += metersPerSample;
            }
        }
Beispiel #5
0
 public float GenerateHeightPointMM(float xWorldLocationMeters, float zWorldLocationMeters)
 {
     return(Mosaic.GetWorldHeightMM((int)xWorldLocationMeters, (int)zWorldLocationMeters));
 }