public float CalculateTerrainHeight(float feetNorth, float feetEast, uint lod)
        {
            int col;
            int row;
            var feetAcross = _distanceBetweenElevationPostsCalculator.GetNumFeetBetweenElevationPosts(lod);

            //determine the column and row in the DTED matrix where the nearest elevation post can be found
            _nearestElevationPostColumnAndRowCalculator.GetNearestElevationPostColumnAndRowForNorthEastCoordinates(feetNorth, feetEast, lod, out col, out row);

            //retrieve the 4 elevation posts which form a box around our current position (origin point x=0,y=0 is in lower left)
            var Q11 = _columnAndRowElevationPostRecordRetriever.GetElevationPostRecordByColumnAndRow(col, row, lod);
            var Q21 = _columnAndRowElevationPostRecordRetriever.GetElevationPostRecordByColumnAndRow(col + 1, row, lod);
            var Q22 = _columnAndRowElevationPostRecordRetriever.GetElevationPostRecordByColumnAndRow(col + 1, row + 1, lod);
            var Q12 = _columnAndRowElevationPostRecordRetriever.GetElevationPostRecordByColumnAndRow(col, row + 1, lod);

            if (Q11 == null || Q21 == null || Q22 == null || Q12 == null)
            {
                return(0);
            }
            //determine the North/East coordinates of these 4 posts, respectively
            var   Q11North = row * feetAcross;
            var   Q11East  = col * feetAcross;
            float FQ11     = Q11.Elevation;

            var   Q21East = (col + 1) * feetAcross;
            float FQ21    = Q21.Elevation;

            float FQ22 = Q22.Elevation;

            var   Q12North = (row + 1) * feetAcross;
            float FQ12     = Q12.Elevation;

            //perform bilinear interpolation on the 4 outer elevation posts relative to our actual center post
            //see: http://en.wikipedia.org/wiki/Bilinear_interpolation

            var x = feetEast;
            var y = feetNorth;

            var x1 = Q11East;
            var x2 = Q21East;
            var y1 = Q11North;
            var y2 = Q12North;

            var result =
                (
                    ((FQ11 / ((x2 - x1) * (y2 - y1))) * (x2 - x) * (y2 - y))
                    +
                    ((FQ21 / ((x2 - x1) * (y2 - y1))) * (x - x1) * (y2 - y))
                    +
                    ((FQ12 / ((x2 - x1) * (y2 - y1))) * (x2 - x) * (y - y1))
                    +
                    ((FQ22 / ((x2 - x1) * (y2 - y1))) * (x - x1) * (y - y1))
                );

            return(result);
        }
        public Bitmap GetDetailTextureForElevationPost(int postCol, int postRow, uint lod)
        {
            var col = postCol;
            var row = postRow;

            _elevationPostCoordinateClamper.ClampElevationPostCoordinates(ref col, ref row, lod);
            if (postCol != col || postRow != row)
            {
                col = 0;
                row = 0;
            }


            var lRecord = _columnAndRowElevationPostRetriever.GetElevationPostRecordByColumnAndRow(col, row, lod);

            if (lRecord == null)
            {
                return(null);
            }

            var textureId  = lRecord.TextureId;
            var bigTexture = _terrainTextureByTextureIdRetriever.GetTerrainTextureByTextureId(textureId, lod);

            Bitmap toReturn;

            if (lod <= _terrainDB.TheaterDotMap.LastNearTiledLOD)
            {
                var chunksWide      = 4 >> (int)lod;
                var thisChunkXIndex = (uint)(col % chunksWide);
                var thisChunkYIndex = (uint)(row % chunksWide);

                var leftX   = (int)(thisChunkXIndex * (bigTexture.Width / chunksWide));
                var rightX  = (int)((thisChunkXIndex + 1) * (bigTexture.Width / chunksWide)) - 1;
                var topY    = (int)(bigTexture.Height - (thisChunkYIndex + 1) * (bigTexture.Height / chunksWide));
                var bottomY = (int)(bigTexture.Height - thisChunkYIndex * (bigTexture.Height / chunksWide)) - 1;

                var sourceRect = new Rectangle(leftX, topY, (rightX - leftX) + 1, (bottomY - topY) + 1);

                toReturn = (Bitmap)Util.CropBitmap(bigTexture, sourceRect);
                bigTexture.Dispose();
            }
            else
            {
                toReturn = bigTexture;
            }
            return(toReturn);
        }
Beispiel #3
0
 public TheaterDotLxFileRecord GetElevationPostRecordByColumnAndRow(int postColumn, int postRow, uint lod)
 {
     return(_columnAndRowElevationPostRecordRetriever.GetElevationPostRecordByColumnAndRow(postColumn, postRow, lod));
 }