Example #1
0
        public override bool CreateDemFromParent()
        {
            ToastTile parent = Parent as ToastTile;

            if (parent == null)
            {
                return(false);
            }

            int offsetX = ((X % 2) == 1 ? 8 : 0);
            int offsetY = ((Y % 2) == 0 ? 8 : 0);


            demArray = new double[17 * 17];
            // Interpolate accross
            for (int y = 0; y < 17; y += 2)
            {
                bool copy = true;
                for (int x = 0; x < 17; x++)
                {
                    if (copy)
                    {
                        demArray[(16 - y) * 17 + x] = parent.GetDemSample((x / 2) + offsetX, (y / 2) + offsetY);
                    }
                    else
                    {
                        demArray[(16 - y) * 17 + x] =
                            (
                                (
                                    parent.GetDemSample((x / 2) + offsetX, (y / 2) + offsetY) +
                                    parent.GetDemSample(((x / 2) + offsetX) + 1, (y / 2) + offsetY)
                                ) / 2);
                    }
                    copy = !copy;
                }
            }
            // Interpolate down
            for (int y = 1; y < 17; y += 2)
            {
                for (int x = 0; x < 17; x++)
                {
                    demArray[(16 - y) * 17 + x] =
                        (
                            (
                                GetDemSample(x, y - 1) +
                                GetDemSample(x, y + 1)
                            ) / 2);
                }
            }

            // Convert the dem array back to the arranged DEM list thu slash/backslash mapping tables


            DemData = new double[demSize];
            for (int i = 0; i < demSize; i++)
            {
                if (backslash)
                {
                    DemData[i] = demArray[backslashXIndex[i] + backslashYIndex[i] * 17];
                }
                else
                {
                    DemData[i] = demArray[slashXIndex[i] + slashYIndex[i] * 17];
                }
                demAverage += DemData[i];
            }

            // WriteDemIndexArrays();

            // Get Average value for new DemData table

            demAverage /= DemData.Length;

            DemReady = true;
            return(true);
        }
Example #2
0
        private void InitializeGrids()
        {
            vertexList = BufferPool11.GetPositionTextureList();

            for (int i = 0; i < 4; i++)
            {
                if (childTriangleList[i] != null)
                {
                    childTriangleList[i].Clear();
                }
                else
                {
                    childTriangleList[i] = BufferPool11.GetTriagleList();
                }
            }

            bounds = new PositionTexture[3, 3];

            if (level > 0)
            {
                ToastTile parent = Parent as ToastTile;
                if (parent == null)
                {
                    return;
                }

                int xIndex = x % 2;
                int yIndex = y % 2;

                if (level > 1)
                {
                    backslash = parent.backslash;
                }
                else
                {
                    backslash = xIndex == 1 ^ yIndex == 1;
                }


                bounds[0, 0] = parent.bounds[xIndex, yIndex];
                bounds[1, 0] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex + 1, yIndex]);
                bounds[2, 0] = parent.bounds[xIndex + 1, yIndex];
                bounds[0, 1] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex, yIndex + 1]);

                if (backslash)
                {
                    bounds[1, 1] = Midpoint(parent.bounds[xIndex, yIndex], parent.bounds[xIndex + 1, yIndex + 1]);
                }
                else
                {
                    bounds[1, 1] = Midpoint(parent.bounds[xIndex + 1, yIndex], parent.bounds[xIndex, yIndex + 1]);
                }

                bounds[2, 1] = Midpoint(parent.bounds[xIndex + 1, yIndex], parent.bounds[xIndex + 1, yIndex + 1]);
                bounds[0, 2] = parent.bounds[xIndex, yIndex + 1];
                bounds[1, 2] = Midpoint(parent.bounds[xIndex, yIndex + 1], parent.bounds[xIndex + 1, yIndex + 1]);
                bounds[2, 2] = parent.bounds[xIndex + 1, yIndex + 1];

                if (Properties.Settings.Default.ShowElevationModel)
                {
                    bounds[0, 0].Tu = 0;
                    bounds[0, 0].Tv = 0;
                    bounds[1, 0].Tu = .5f;
                    bounds[1, 0].Tv = 0;
                    bounds[2, 0].Tu = 1;
                    bounds[2, 0].Tv = 0;

                    bounds[0, 1].Tu = 0;
                    bounds[0, 1].Tv = .5f;
                    bounds[1, 1].Tu = .5f;
                    bounds[1, 1].Tv = .5f;
                    bounds[2, 1].Tu = 1;
                    bounds[2, 1].Tv = .5f;

                    bounds[0, 2].Tu = 0;
                    bounds[0, 2].Tv = 1;
                    bounds[1, 2].Tu = .5f;
                    bounds[1, 2].Tv = 1;
                    bounds[2, 2].Tu = 1;
                    bounds[2, 2].Tv = 1;
                }
                else
                {
                    bounds[0, 0].Tu = 0 + .002f;
                    bounds[0, 0].Tv = 0 + .002f;
                    bounds[1, 0].Tu = .5f + .002f;
                    bounds[1, 0].Tv = 0 + .002f;
                    bounds[2, 0].Tu = 1 + .002f;
                    bounds[2, 0].Tv = 0 + .002f;

                    bounds[0, 1].Tu = 0 + .002f;
                    bounds[0, 1].Tv = .5f + .002f;
                    bounds[1, 1].Tu = .5f + .002f;
                    bounds[1, 1].Tv = .5f + .002f;
                    bounds[2, 1].Tu = 1 + .002f;
                    bounds[2, 1].Tv = .5f + .002f;

                    bounds[0, 2].Tu = 0 + .002f;
                    bounds[0, 2].Tv = 1 + .002f;
                    bounds[1, 2].Tu = .5f + .002f;
                    bounds[1, 2].Tv = 1 + .002f;
                    bounds[2, 2].Tu = 1 + .002f;
                    bounds[2, 2].Tv = 1 + .002f;
                }

                vertexList.Add(bounds[0, 0]);
                vertexList.Add(bounds[1, 0]);
                vertexList.Add(bounds[2, 0]);
                vertexList.Add(bounds[0, 1]);
                vertexList.Add(bounds[1, 1]);
                vertexList.Add(bounds[2, 1]);
                vertexList.Add(bounds[0, 2]);
                vertexList.Add(bounds[1, 2]);
                vertexList.Add(bounds[2, 2]);



                if (backslash)
                {
                    childTriangleList[0].Add(new Triangle(4, 1, 0));
                    childTriangleList[0].Add(new Triangle(3, 4, 0));
                    childTriangleList[1].Add(new Triangle(5, 2, 1));
                    childTriangleList[1].Add(new Triangle(4, 5, 1));
                    childTriangleList[2].Add(new Triangle(7, 4, 3));
                    childTriangleList[2].Add(new Triangle(6, 7, 3));
                    childTriangleList[3].Add(new Triangle(8, 5, 4));
                    childTriangleList[3].Add(new Triangle(7, 8, 4));
                }
                else
                {
                    childTriangleList[0].Add(new Triangle(3, 1, 0));
                    childTriangleList[0].Add(new Triangle(4, 1, 3));
                    childTriangleList[1].Add(new Triangle(4, 2, 1));
                    childTriangleList[1].Add(new Triangle(5, 2, 4));
                    childTriangleList[2].Add(new Triangle(6, 4, 3));
                    childTriangleList[2].Add(new Triangle(7, 4, 6));
                    childTriangleList[3].Add(new Triangle(7, 5, 4));
                    childTriangleList[3].Add(new Triangle(8, 5, 7));
                }
            }
            else
            {
                if (Properties.Settings.Default.ShowElevationModel)
                {
                    bounds[0, 0] = new PositionTexture(0, -1, 0, 0, 0);
                    bounds[1, 0] = new PositionTexture(0, 0, -1, .5f, 0);
                    bounds[2, 0] = new PositionTexture(0, -1, 0, 1, 0);
                    bounds[0, 1] = new PositionTexture(1, 0, 0, 0, .5f);
                    bounds[1, 1] = new PositionTexture(0, 1, 0, .5f, .5f);
                    bounds[2, 1] = new PositionTexture(-1, 0, 0, 1, .5f);
                    bounds[0, 2] = new PositionTexture(0, -1, 0, 0, 1);
                    bounds[1, 2] = new PositionTexture(0, 0, 1, .5f, 1);
                    bounds[2, 2] = new PositionTexture(0, -1, 0, 1, 1);
                }
                else
                {
                    bounds[0, 0] = new PositionTexture(0, -1, 0, 0 + .002f, 0 + .002f);
                    bounds[1, 0] = new PositionTexture(0, 0, -1, .5f + .002f, 0 + .002f);
                    bounds[2, 0] = new PositionTexture(0, -1, 0, 1 + .002f, 0 + .002f);
                    bounds[0, 1] = new PositionTexture(1, 0, 0, 0 + .002f, .5f + .002f);
                    bounds[1, 1] = new PositionTexture(0, 1, 0, .5f + .002f, .5f + .002f);
                    bounds[2, 1] = new PositionTexture(-1, 0, 0, 1 + .002f, .5f + .002f);
                    bounds[0, 2] = new PositionTexture(0, -1, 0, 0 + .002f, 1 + .002f);
                    bounds[1, 2] = new PositionTexture(0, 0, 1, .5f + .002f, 1 + .002f);
                    bounds[2, 2] = new PositionTexture(0, -1, 0, 1 + .002f, 1 + .002f);
                }
                vertexList.Add(bounds[0, 0]);
                vertexList.Add(bounds[1, 0]);
                vertexList.Add(bounds[2, 0]);
                vertexList.Add(bounds[0, 1]);
                vertexList.Add(bounds[1, 1]);
                vertexList.Add(bounds[2, 1]);
                vertexList.Add(bounds[0, 2]);
                vertexList.Add(bounds[1, 2]);
                vertexList.Add(bounds[2, 2]);

                childTriangleList[0].Add(new Triangle(3, 1, 0));
                childTriangleList[0].Add(new Triangle(4, 1, 3));
                childTriangleList[1].Add(new Triangle(5, 2, 1));
                childTriangleList[1].Add(new Triangle(4, 5, 1));
                childTriangleList[2].Add(new Triangle(7, 4, 3));
                childTriangleList[2].Add(new Triangle(6, 7, 3));
                childTriangleList[3].Add(new Triangle(7, 5, 4));
                childTriangleList[3].Add(new Triangle(8, 5, 7));
                // Setup default matrix of points.
            }
            VertexCount = (int)Math.Pow(4, subDivisionLevel) * 2 + 1;
        }