Example #1
0
        private void ReturnBuffers()
        {
            if (vertexList != null)
            {
                BufferPool11.ReturnPositionTextureList(vertexList);
                vertexList = null;
            }

            if (childTriangleList != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (childTriangleList[i] != null)
                    {
                        BufferPool11.ReturnTriangleList(childTriangleList[i]);
                        childTriangleList[i] = null;
                    }
                }
            }
        }
Example #2
0
        protected void ComputeBoundingSphere(Tile parent, double altitude)
        {
            InitializeGrids();

            Vector3d[] pointList   = BufferPool11.GetVector3dBuffer(vertexList.Count);
            double     scaleFactor = (1 + (altitude / DemScaleFactor));

            if (DemEnabled)
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    pointList[i] = Vector3d.Scale(vertexList[i].Position, scaleFactor);
                }
            }
            else
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    pointList[i] = vertexList[i].Position;
                }
            }

            TopLeft     = new Vector3d(Vector3d.Scale(bounds[0, 0].Position, scaleFactor));
            BottomRight = new Vector3d(Vector3d.Scale(bounds[2, 2].Position, scaleFactor));
            TopRight    = new Vector3d(Vector3d.Scale(bounds[2, 0].Position, scaleFactor));
            BottomLeft  = new Vector3d(Vector3d.Scale(bounds[0, 2].Position, scaleFactor));
            CalcSphere(pointList);

            BufferPool11.ReturnVector3dBuffer(pointList);

            if (Level == 5 || Level == 12)
            {
                localCenter = sphereCenter;
                localCenter.Round();
            }
            else if (Level > 5)
            {
                localCenter = parent.localCenter;
            }
            ReturnBuffers();
        }
Example #3
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null)
            {
                if (this.texture == null)
                {
                    if (TextureReady)
                    {
                        texture = BufferPool11.GetTexture(FileName);

                        double aspect = (double)texture.Width / (double)texture.Height;

                        if (aspect < 1.5)
                        {
                            domeMaster = true;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }


                iTileBuildCount++;

                if (vertexBuffer == null)
                {
                    vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), VertexCount, RenderContext11.PrepDevice);
                    indexBuffer  = new IndexBuffer11[4];

                    OnCreateVertexBuffer(vertexBuffer);
                    sphereRadius = 1;
                    sphereCenter = new Vector3d(0, 0, 0);
                }
            }
            ReadyToRender = true;
            return(true);
        }
Example #4
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            bool dem = DemEnabled;

            if (!subDivided)
            {
                if (vertexList == null)
                {
                    InitializeGrids();
                }


                for (int i = 0; i < 4; i++)
                {
                    int count = subDivisionLevel;
                    while (count-- > 1)
                    {
                        List <Triangle> newList = BufferPool11.GetTriagleList();
                        foreach (Triangle tri in childTriangleList[i])
                        {
                            tri.SubDivide(newList, vertexList);
                        }
                        BufferPool11.ReturnTriangleList(childTriangleList[i]);
                        childTriangleList[i] = newList;
                    }
                }
                subDivided = true;
            }

            //for (int i = 0; i < 4; i++)
            //{
            //    indexBuffer[i] = BufferPool11.GetShortIndexBuffer(childTriangleList[i].Count * 3);
            //}
            int indexCount = childTriangleList[0].Count * 3;


            demIndex = 0;
            try
            {
                // Create a vertex buffer
                PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs)

                int index = 0;
                if (dem && level > 1)
                {
                    demArray = new double[17 * 17];
                    if (backslash)
                    {
                        if (backslashYIndex == null)
                        {
                            tempBackslashYIndex = new byte[demSize];
                            tempBackslashXIndex = new byte[demSize];
                        }
                    }
                    else
                    {
                        if (slashYIndex == null)
                        {
                            tempSlashYIndex = new byte[demSize];
                            tempSlashXIndex = new byte[demSize];
                        }
                    }
                }

                foreach (PositionTexture vert in vertexList)
                {
                    if (dem)
                    {
                        // todo map this with backslash as well
                        verts[index++] = GetMappedVertex(vert);
                    }
                    else
                    {
                        verts[index++] = vert.PositionNormalTextured(localCenter, backslash);
                    }
                    demIndex++;
                }

                vb.Unlock();
                TriangleCount = childTriangleList[0].Count * 4;

                int quarterDivisions = SubDivisions / 2;
                int part             = 0;
                foreach (List <Triangle> triList in childTriangleList)
                {
                    if (GetIndexBuffer(part, 0) == null)
                    {
                        short[] indexArray = new short[indexCount];
                        int     indexer    = 0;
                        //dumpMutex.WaitOne();
                        //System.Diagnostics.Debug.WriteLine("start Index dump:" + part.ToString() + ";" + (backslash ? "Backslash" : "Slash"));
                        foreach (Triangle tri in triList)
                        {
                            indexArray[indexer++] = (short)tri.A;
                            indexArray[indexer++] = (short)tri.B;
                            indexArray[indexer++] = (short)tri.C;
                            //WriteDebugVertex(tri.A);
                            //WriteDebugVertex(tri.B);
                            //WriteDebugVertex(tri.C);
                        }
                        //System.Diagnostics.Debug.WriteLine("End Index dump");
                        //dumpMutex.ReleaseMutex();
                        ProcessIndexBuffer(indexArray, part);
                    }
                    part++;
                }

                if (backslash)
                {
                    if (tempBackslashXIndex != null)
                    {
                        backslashXIndex     = tempBackslashXIndex;
                        backslashYIndex     = tempBackslashYIndex;
                        tempBackslashXIndex = null;
                        tempBackslashYIndex = null;
                    }
                }
                else
                {
                    if (tempSlashYIndex != null)
                    {
                        slashXIndex     = tempSlashXIndex;
                        slashYIndex     = tempSlashYIndex;
                        tempSlashYIndex = null;
                        tempSlashXIndex = null;
                    }
                }
            }
            catch
            {
            }

            ReturnBuffers();
        }
Example #5
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;
        }