Exemple #1
0
        public void SubDivideNoNormalize(List <Triangle> triList, List <PositionTexture> vertexList)
        {
            Vector3d a1 = Vector3d.Lerp(vertexList[B].Position, vertexList[C].Position, .5f);
            Vector3d b1 = Vector3d.Lerp(vertexList[C].Position, vertexList[A].Position, .5f);
            Vector3d c1 = Vector3d.Lerp(vertexList[A].Position, vertexList[B].Position, .5f);

            Vector2d a1uv = Vector2d.Lerp(Vector2d.Create(vertexList[B].Tu, vertexList[B].Tv), Vector2d.Create(vertexList[C].Tu, vertexList[C].Tv), .5f);
            Vector2d b1uv = Vector2d.Lerp(Vector2d.Create(vertexList[C].Tu, vertexList[C].Tv), Vector2d.Create(vertexList[A].Tu, vertexList[A].Tv), .5f);
            Vector2d c1uv = Vector2d.Lerp(Vector2d.Create(vertexList[A].Tu, vertexList[A].Tv), Vector2d.Create(vertexList[B].Tu, vertexList[B].Tv), .5f);

            //a1.Normalize();
            //b1.Normalize();
            //c1.Normalize();

            int aIndex = vertexList.Count;
            int bIndex = vertexList.Count + 1;
            int cIndex = vertexList.Count + 2;

            vertexList.Add(PositionTexture.CreatePosRaw(a1, a1uv.X, a1uv.Y));
            vertexList.Add(PositionTexture.CreatePosRaw(b1, b1uv.X, b1uv.Y));
            vertexList.Add(PositionTexture.CreatePosRaw(c1, c1uv.X, c1uv.Y));

            triList.Add(Triangle.Create(A, cIndex, bIndex));
            triList.Add(Triangle.Create(B, aIndex, cIndex));
            triList.Add(Triangle.Create(C, bIndex, aIndex));
            triList.Add(Triangle.Create(aIndex, bIndex, cIndex));
        }
Exemple #2
0
        /*
         * Vertices distributed in a grid pattern like the example below
         * Example for pattern with step set to 4
         *            24
         *          19  23
         *       14   18  22
         *      9   13  17  21
         *    4   8   12  16  20
         *      3   7   11  15
         *        2   6   10
         *          1   5
         *            0
         *
         */
        private void PopulateVertexList(PositionTexture[] vertexList, int step)
        {
            for (int i = 0; i < step; i += 2)
            {
                for (int j = 0; j < step; j += 2)
                {
                    Vector3d[] points = this.Boundaries(j, i, step);

                    vertexList[i * (step + 1) + j]           = PositionTexture.CreatePos(points[2], (1 / step) * i, (1 / step) * j);
                    vertexList[i * (step + 1) + j + 1]       = PositionTexture.CreatePos(points[3], (1 / step) * i, (1 / step) + (1 / step) * j);
                    vertexList[(i + 1) * (step + 1) + j]     = PositionTexture.CreatePos(points[1], (1 / step) + (1 / step) * i, (1 / step) * j);
                    vertexList[(i + 1) * (step + 1) + j + 1] = PositionTexture.CreatePos(points[0], (1 / step) + (1 / step) * i, (1 / step) + (1 / step) * j);
                    if (j + 2 >= step && step > 1)
                    {
                        j      = step - 1;
                        points = this.Boundaries(j, i, step);
                        vertexList[i * (step + 1) + step]       = PositionTexture.CreatePos(points[3], (1 / step) * i, (1 / step) + (1 / step) * j);
                        vertexList[(i + 1) * (step + 1) + step] = PositionTexture.CreatePos(points[0], (1 / step) + (1 / step) * i, (1 / step) + (1 / step) * j);
                    }
                }
            }
            if (step > 1)
            {
                VertexOfLastRow(vertexList, step);
            }
        }
        private PositionTexture Midpoint(PositionTexture positionNormalTextured, PositionTexture positionNormalTextured_2)
        {
            Vector3d a1   = Vector3d.Lerp(positionNormalTextured.Position, positionNormalTextured_2.Position, .5f);
            Vector2d a1uv = Vector2d.Lerp(Vector2d.Create(positionNormalTextured.Tu, positionNormalTextured.Tv), Vector2d.Create(positionNormalTextured_2.Tu, positionNormalTextured_2.Tv), .5f);

            a1.Normalize();
            return(PositionTexture.CreatePos(a1, a1uv.X, a1uv.Y));
        }
        public Position4Texture2 VS(PositionTexture input)
        {
            Position4Texture2 output;

            output.Position     = new System.Numerics.Vector4(input.Position, 1);
            output.TextureCoord = input.TextureCoord;
            return(output);
        }
Exemple #5
0
        public int AddVertex(float[] buffer, int index, PositionTexture p)
        {
            buffer[index++] = (float)p.Position.X;
            buffer[index++] = (float)p.Position.Y;
            buffer[index++] = (float)p.Position.Z;
            buffer[index++] = (float)p.Tu;
            buffer[index++] = (float)p.Tv;

            return(index);
        }
        internal PositionNormalTexturedX2 GetMappedVertex(PositionTexture vert)
        {
            PositionNormalTexturedX2 vertOut = new PositionNormalTexturedX2();
            Coordinates latLng = Coordinates.CartesianToSpherical2(vert.Position);

            //      latLng.Lng += 90;
            if (latLng.Lng < -180)
            {
                latLng.Lng += 360;
            }
            if (latLng.Lng > 180)
            {
                latLng.Lng -= 360;
            }
            //if (false)
            //{
            ////    System.Diagnostics.Debug.WriteLine(String.Format("{0},{1}", (int)(vert.Tu * 16 + .5), (int)(vert.Tv * 16 + .5)));
            //}

            if (level > 1)
            {
                byte arrayX = (byte)(int)(vert.Tu * 16 + .5);
                byte arrayY = (byte)(int)(vert.Tv * 16 + .5);
                demArray[arrayX + arrayY * 17] = DemData[demIndex];

                if (backslash)
                {
                    if (tempBackslashYIndex != null)
                    {
                        tempBackslashXIndex[demIndex] = arrayX;
                        tempBackslashYIndex[demIndex] = arrayY;
                    }
                }
                else
                {
                    if (tempSlashYIndex != null)
                    {
                        tempSlashXIndex[demIndex] = arrayX;
                        tempSlashYIndex[demIndex] = arrayY;
                    }
                }
            }

            Vector3d pos = GeoTo3dWithAltitude(latLng.Lat, latLng.Lng, false);

            vertOut.Tu = (float)vert.Tu;
            vertOut.Tv = (float)vert.Tv;

            vertOut.Lat      = latLng.Lat;
            vertOut.Lng      = latLng.Lng;
            vertOut.Normal   = pos;
            pos              = pos - localCenter;
            vertOut.Position = pos;
            return(vertOut);
        }
        internal PositionTexture GetMappedVertex(PositionTexture vert)
        {
            PositionTexture vertOut = new PositionTexture();
            Coordinates     latLng  = Coordinates.CartesianToSpherical2(vert.Position);

            //      latLng.Lng += 90;
            if (latLng.Lng < -180)
            {
                latLng.Lng += 360;
            }
            if (latLng.Lng > 180)
            {
                latLng.Lng -= 360;
            }


            if (Level > 1)
            {
                byte arrayX = (byte)(int)(vert.Tu * 16 + .5);
                byte arrayY = (byte)(int)(vert.Tv * 16 + .5);
                demArray[arrayX + arrayY * 17] = DemData[demIndex];

                if (backslash)
                {
                    if (tempBackslashYIndex != null)
                    {
                        tempBackslashXIndex[demIndex] = arrayX;
                        tempBackslashYIndex[demIndex] = arrayY;
                    }
                }
                else
                {
                    if (tempSlashYIndex != null)
                    {
                        tempSlashXIndex[demIndex] = arrayX;
                        tempSlashYIndex[demIndex] = arrayY;
                    }
                }
            }

            Vector3d pos = GeoTo3dWithAlt(latLng.Lat, latLng.Lng, false, false);

            vertOut.Tu = (float)vert.Tu;
            vertOut.Tv = (float)vert.Tv;

            //vertOut.Lat = latLng.Lat;
            //vertOut.Lng = latLng.Lng;
            //vertOut.Normal = pos;
            pos.Subtract(localCenter);
            vertOut.Position = pos;


            return(vertOut);
        }
        public static RenderTriangle Create(PositionTexture a, PositionTexture b, PositionTexture c, ImageElement img, int level)
        {
            RenderTriangle temp = new RenderTriangle();

            temp.A         = a.Copy();
            temp.B         = b.Copy();
            temp.C         = c.Copy();
            temp.texture   = img;
            temp.TileLevel = level;
            return(temp);
        }
        public void WriteDebugVertex(int index)
        {
            PositionTexture vert   = vertexList[index];
            byte            arrayX = (byte)(int)(vert.Tu * 16 + .5);
            byte            arrayY = (byte)(int)(vert.Tv * 16 + .5);

            System.Diagnostics.Debug.Write(index);
            System.Diagnostics.Debug.Write("\t");
            System.Diagnostics.Debug.Write(arrayX);
            System.Diagnostics.Debug.Write("\t");
            System.Diagnostics.Debug.WriteLine(arrayY);
        }
        public static RenderTriangle CreateWithMiter(PositionTexture a, PositionTexture b, PositionTexture c, ImageElement img, int level, double expansion)
        {
            RenderTriangle temp = new RenderTriangle();

            temp.ExpansionInPixels = expansion;
            temp.A         = a.Copy();
            temp.B         = b.Copy();
            temp.C         = c.Copy();
            temp.texture   = img;
            temp.TileLevel = level;
            temp.MakeNormal();
            return(temp);
        }
Exemple #11
0
        private void VertexOfLastRow(PositionTexture[] vertexList, int step)
        {
            int i = step - 1;

            for (int j = 0; j < step; j += 2)
            {
                Vector3d[] points = this.Boundaries(j, i, step);
                vertexList[(i + 1) * (step + 1) + j]     = PositionTexture.CreatePos(points[1], (1 / step) + (1 / step) * i, (1 / step) * j);
                vertexList[(i + 1) * (step + 1) + j + 1] = PositionTexture.CreatePos(points[0], (1 / step) + (1 / step) * i, (1 / step) + (1 / step) * j);
                if (j + 2 >= step)
                {
                    j      = step - 1;
                    points = this.Boundaries(j, i, step);
                    vertexList[(i + 1) * (step + 1) + step] = PositionTexture.CreatePos(points[0], (1 / step) + (1 / step) * i, (1 / step) + (1 / step) * j);
                }
            }
        }
Exemple #12
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }

            if (dataset.WcsImage is FitsImage && RenderContext.UseGlVersion2)
            {
                FitsImage fitsImage = dataset.WcsImage as FitsImage;
                texture2d = PrepDevice.createTexture();
                PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);

                PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);

                Width  = fitsImage.SizeX;
                Height = fitsImage.SizeY;
            }
            else
            {
                WcsImage wcsImage = dataset.WcsImage as WcsImage;
                if (wcsImage != null)
                {
                    Bitmap bmp = wcsImage.GetBitmap();
                    texture2d = bmp.GetTexture();
                    if (bmp.Height != wcsImage.SizeY)
                    {
                        PixelCenterY += bmp.Height - wcsImage.SizeY;
                    }
                    if (renderContext.gl != null)
                    {
                        Height = bmp.Height;
                        Width  = bmp.Width;
                    }
                }
                else
                {
                    Height = texture.NaturalHeight;
                    Width  = texture.NaturalWidth;
                }
            }

            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }


            ComputeMatrix();

            double latMin = 0 + (ScaleY * (Height - PixelCenterY));
            double latMax = 0 - (ScaleY * PixelCenterY);
            double lngMin = 0 + (ScaleX * PixelCenterX);
            double lngMax = 0 - (ScaleX * (Width - PixelCenterX));


            TopLeft     = GeoTo3dTan(latMin, lngMin);
            BottomRight = GeoTo3dTan(latMax, lngMax);
            TopRight    = GeoTo3dTan(latMin, lngMax);
            BottomLeft  = GeoTo3dTan(latMax, lngMin);



            Vector3d topCenter    = Vector3d.Lerp(TopLeft, TopRight, .5f);
            Vector3d bottomCenter = Vector3d.Lerp(BottomLeft, BottomRight, .5f);
            Vector3d center       = Vector3d.Lerp(topCenter, bottomCenter, .5f);
            Vector3d rightCenter  = Vector3d.Lerp(TopRight, BottomRight, .5f);
            Vector3d leftCenter   = Vector3d.Lerp(TopLeft, BottomLeft, .5f);


            if (renderContext.gl == null)
            {
                vertexList = new List <PositionTexture>();

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                childTriangleList = new List <Triangle>();

                if (dataset.BottomsUp)
                {
                    childTriangleList.Add(Triangle.Create(0, 1, 2));
                    childTriangleList.Add(Triangle.Create(2, 1, 3));
                }
                else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));
                }

                int count = 3;
                while (count-- > 1)
                {
                    List <Triangle> newList = new List <Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivide(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];


                    RenderTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, texture, Level, miter));
                }
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
        private static void CreateGalaxyImage(RenderContext renderContext)
        {
            if (milkyWayImage == null)
            {
                milkyWayImage = Planets.LoadPlanetTexture("http://cdn.worldwidetelescope.org/webclient/images/milkywaybar.jpg");
            }


            int subdivs = 50;

            double lat, lng;

            int    index  = 0;
            double latMin = 64;
            double latMax = -64;
            double lngMin = -64;
            double lngMax = 64;

            //// Create a vertex buffer
            galaxyImageVertexBuffer = new PositionTextureVertexBuffer((subdivs + 1) * (subdivs + 1));
            PositionTexture[] verts = (PositionTexture[])galaxyImageVertexBuffer.Lock();

            int      x1, y1;
            double   latDegrees  = latMax - latMin;
            double   lngDegrees  = lngMax - lngMin;
            double   scaleFactor = 60800000.0;
            double   ecliptic    = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
            Vector3d point;

            double textureStepX = 1.0f / subdivs;
            double textureStepY = 1.0f / subdivs;

            for (y1 = 0; y1 <= subdivs; y1++)
            {
                if (y1 != subdivs)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subdivs; x1++)
                {
                    if (x1 != subdivs)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = y1 * (subdivs + 1) + x1;
                    point = Vector3d.Create(lng * scaleFactor, 0, (lat - 28) * scaleFactor);
                    point.RotateY(213.0 / 180 * Math.PI);
                    point.RotateZ((-62.87175) / 180 * Math.PI);
                    point.RotateY((-192.8595083) / 180 * Math.PI);
                    point.RotateX(ecliptic);
                    verts[index] = PositionTexture.CreatePosRaw(point, (float)(1f - x1 * textureStepX), (float)(/*1f - */ (y1 * textureStepY)));
                    //verts[index].Position = point;
                    //verts[index].Tu = (float)(1f - x1 * textureStepX);
                    //verts[index].Tv = (float)(/*1f - */(y1 * textureStepY));
                }
            }
            galaxyImageVertexBuffer.Unlock();
            galaxyImageTriangleCount = (subdivs) * (subdivs) * 2;
            Uint16Array ui16array = new Uint16Array(subdivs * subdivs * 6);

            UInt16[] indexArray = (UInt16[])(object)ui16array;

            for (y1 = 0; y1 < subdivs; y1++)
            {
                for (x1 = 0; x1 < subdivs; x1++)
                {
                    index = (y1 * subdivs * 6) + 6 * x1;
                    // First triangle in quad
                    indexArray[index]     = (ushort)(y1 * (subdivs + 1) + x1);
                    indexArray[index + 2] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 1] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexArray[index + 3] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));
                    indexArray[index + 5] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 4] = (ushort)((y1 + 1) * (subdivs + 1) + (x1 + 1));
                }
            }
            galaxyImageIndexBuffer = Tile.PrepDevice.createBuffer();
            Tile.PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, galaxyImageIndexBuffer);
            Tile.PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
        }
        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;
        }
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }
            GeometryCreated = true;

            if (uvMultiple == 256)
            {
                if (dataset.DataSetType == ImageSetType.Earth || dataset.DataSetType == ImageSetType.Planet)
                {
                    subDivisionLevel = Math.Max(2, (6 - Level) * 2);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }

            //    try
            {
                double lat, lng;

                int    index       = 0;
                double tileDegrees = 360 / (Math.Pow(2, this.Level));

                latMin = AbsoluteMetersToLatAtZoom(tileY * 256, Level);
                latMax = AbsoluteMetersToLatAtZoom((tileY + 1) * 256, Level);
                lngMin = (((double)this.tileX * tileDegrees) - 180.0);
                lngMax = ((((double)(this.tileX + 1)) * tileDegrees) - 180.0);

                double latCenter = AbsoluteMetersToLatAtZoom(((tileY * 2) + 1) * 256, Level + 1);

                TopLeft     = (Vector3d)GeoTo3d(latMin, lngMin, false);
                BottomRight = (Vector3d)GeoTo3d(latMax, lngMax, false);
                TopRight    = (Vector3d)GeoTo3d(latMin, lngMax, false);
                BottomLeft  = (Vector3d)GeoTo3d(latMax, lngMin, false);

                PositionTexture[] verts = new PositionTexture[(subDivisionLevel + 1) * (subDivisionLevel + 1)];


                tileDegrees = lngMax - lngMin;
                double dGrid = (tileDegrees / subDivisionLevel);
                int    x1, y1;
                double textureStep = 1.0f / subDivisionLevel;

                double latDegrees = latMax - latCenter;

                for (y1 = 0; y1 < subDivisionLevel / 2; y1++)
                {
                    if (y1 != subDivisionLevel / 2)
                    {
                        lat = latMax - (2 * textureStep * latDegrees * (double)y1);
                    }
                    else
                    {
                        lat = latCenter;
                    }

                    for (x1 = 0; x1 <= subDivisionLevel; x1++)
                    {
                        if (x1 != subDivisionLevel)
                        {
                            lng = lngMin + (textureStep * tileDegrees * (double)x1);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index                 = y1 * (subDivisionLevel + 1) + x1;
                        verts[index]          = new PositionTexture();
                        verts[index].Position = (Vector3d)GeoTo3dWithAlt(lat, lng, false, true);// Add Altitude mapping here
                        verts[index].Tu       = (x1 * textureStep) * Tile.uvMultiple;
                        verts[index].Tv       = ((AbsoluteLatToMetersAtZoom(lat, Level) - (tileY * 256)) / 256f) * Tile.uvMultiple;
                        demIndex++;
                    }
                }
                latDegrees = latMin - latCenter;

                for (y1 = subDivisionLevel / 2; y1 <= subDivisionLevel; y1++)
                {
                    if (y1 != subDivisionLevel)
                    {
                        lat = latCenter + (2 * textureStep * latDegrees * (double)(y1 - (subDivisionLevel / 2)));
                    }
                    else
                    {
                        lat = latMin;
                    }

                    for (x1 = 0; x1 <= subDivisionLevel; x1++)
                    {
                        if (x1 != subDivisionLevel)
                        {
                            lng = lngMin + (textureStep * tileDegrees * (double)x1);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index                 = y1 * (subDivisionLevel + 1) + x1;
                        verts[index]          = new PositionTexture();
                        verts[index].Position = (Vector3d)GeoTo3dWithAlt(lat, lng, false, true);// Add Altitude mapping here
                        verts[index].Tu       = (x1 * textureStep) * Tile.uvMultiple;
                        verts[index].Tv       = ((AbsoluteLatToMetersAtZoom(lat, Level) - (tileY * 256)) / 256f) * Tile.uvMultiple;
                        demIndex++;
                    }
                }
                if (tileY == 0)
                {
                    // Send the tops to the pole to fill in the Bing Hole
                    y1 = subDivisionLevel;
                    for (x1 = 0; x1 <= subDivisionLevel; x1++)
                    {
                        index = y1 * (subDivisionLevel + 1) + x1;
                        verts[index].Position = Vector3d.Create(0, 1, 0);
                    }
                }

                if (tileY == Math.Pow(2, Level) - 1)
                {
                    // Send the tops to the pole to fill in the Bing Hole
                    y1 = 0;
                    for (x1 = 0; x1 <= subDivisionLevel; x1++)
                    {
                        index = y1 * (subDivisionLevel + 1) + x1;
                        verts[index].Position = Vector3d.Create(0, -1, 0);
                    }
                }


                TriangleCount = (subDivisionLevel) * (subDivisionLevel) * 2;

                int quarterDivisions = subDivisionLevel / 2;
                int part             = 0;

                if (renderContext.gl == null)
                {
                    for (int y2 = 0; y2 < 2; y2++)
                    {
                        for (int x2 = 0; x2 < 2; x2++)
                        {
                            index = 0;
                            for (y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                            {
                                for (x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad

                                    PositionTexture p1;
                                    PositionTexture p2;
                                    PositionTexture p3;

                                    p1 = verts[(y1 * (subDivisionLevel + 1) + x1)];
                                    p2 = verts[((y1 + 1) * (subDivisionLevel + 1) + x1)];
                                    p3 = verts[(y1 * (subDivisionLevel + 1) + (x1 + 1))];
                                    RenderTriangle tri = RenderTriangle.Create(p1, p2, p3, texture, Level);
                                    RenderTriangleLists[part].Add(tri);

                                    // Second triangle in quad
                                    p1  = verts[(y1 * (subDivisionLevel + 1) + (x1 + 1))];
                                    p2  = verts[((y1 + 1) * (subDivisionLevel + 1) + x1)];
                                    p3  = verts[((y1 + 1) * (subDivisionLevel + 1) + (x1 + 1))];
                                    tri = RenderTriangle.Create(p1, p2, p3, texture, Level);
                                    RenderTriangleLists[part].Add(tri);
                                }
                            }

                            part++;
                        }
                    }
                }
                else
                {
                    //process vertex list
                    VertexBuffer = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                    Float32Array f32array = new Float32Array(verts.Length * 5);
                    float[]      buffer   = (float[])(object)f32array;
                    index = 0;
                    foreach (PositionTexture pt in verts)
                    {
                        index = AddVertex(buffer, index, pt);
                    }

                    PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                    for (int y2 = 0; y2 < 2; y2++)
                    {
                        for (int x2 = 0; x2 < 2; x2++)
                        {
                            Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                            UInt16[] indexArray = (UInt16[])(object)ui16array;

                            index = 0;
                            for (y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                            {
                                for (x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                                {
                                    // First triangle in quad
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + (x1 + 1)));

                                    // Second triangle in quad
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + (x1 + 1)));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + (x1 + 1)));
                                }
                            }

                            IndexBuffers[part] = PrepDevice.createBuffer();
                            PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[part]);
                            PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);

                            part++;
                        }
                    }
                }
            }
            //       catch
            {
            }

            return(true);
        }
Exemple #16
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            if (vertexList != null)
            {
                return(true);
            }
            vertexList = new List <PositionTexture>();

            PopulateVertexList(vertexList, step);

            if (dataset.HipsProperties.Properties.ContainsKey("hips_frame") &&
                dataset.HipsProperties.Properties["hips_frame"] == "galactic")
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    PositionTexture vert = vertexList[i];
                    galacticMatrix.MultiplyVector(vert.Position);
                }
            }


            TriangleCount = step * step / 2;
            Uint16Array ui16array = new Uint16Array(3 * TriangleCount);

            UInt16[] indexArray = (UInt16[])(object)ui16array;

            if (!subDivided)
            {
                //if (vertexList == null)
                //{
                //    createGeometry();
                //}

                try
                {
                    //process vertex list
                    VertexBuffer = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                    Float32Array f32array = new Float32Array(vertexList.Count * 5);
                    float[]      buffer   = (float[])(object)f32array;
                    int          index    = 0;

                    foreach (PositionTexture vert in vertexList)
                    {
                        index = AddVertex(buffer, index, vert);
                    }
                    PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);



                    index = 0;
                    int offset = vertexList.Count / (4 * step);

                    //0 0 = left
                    //1 0 = top
                    //1 1 = right
                    SetIndexBufferForQuadrant(indexArray, 0, 1);
                    if (step > 1)
                    {
                        SetIndexBufferForQuadrant(indexArray, 0, 0);
                        SetIndexBufferForQuadrant(indexArray, 1, 1);
                        SetIndexBufferForQuadrant(indexArray, 1, 0);
                    }
                }
                catch (Exception exception)
                {
                }

                //ReturnBuffers();
            }

            return(true);
        }
Exemple #17
0
        private void InitializeGrids()
        {
            bounds = new PositionTexture[3, 3];

            if (Level > 0)
            {
                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;
                }
            }
            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);
                }
            }
        }
        private void InitializeGrids()
        {
            bounds = new PositionTexture[3, 3];

            if (Level > 0)
            {
                if (Parent == null)
                {
                    return;
                }

                var xIndex = X % 2;
                var 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;
                }
            }
            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);
                }
            }
        }
        public override bool CreateGeometry(RenderContext renderContext)
        {
            if (GeometryCreated)
            {
                return(true);
            }

            GeometryCreated = true;
            base.CreateGeometry(renderContext);
            if (!subDivided)
            {
                if (vertexList == null)
                {
                    InitializeGrids();
                }

                if (uvMultiple == 256)
                {
                    if (dataset.DataSetType == ImageSetType.Earth || dataset.DataSetType == ImageSetType.Planet)
                    {
                        subDivisionLevel = Math.Min(5, Math.Max(0, 5 - Level));
                    }
                    else
                    {
                        subDivisionLevel = Math.Min(5, Math.Max(0, 5 - Level));
                    }
                }
                else
                {
                    if (demTile && Level > 1)
                    {
                        demArray = new float[17 * 17];
                        demSize  = 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];
                            }
                        }
                    }
                }

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

                if (renderContext.gl == null)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        RenderTriangleLists[i] = new List <RenderTriangle>();
                        foreach (Triangle tri in childTriangleList[i])
                        {
                            PositionTexture p1 = vertexList[tri.C];
                            PositionTexture p2 = vertexList[tri.B];
                            PositionTexture p3 = vertexList[tri.A];


                            RenderTriangleLists[i].Add(RenderTriangle.Create(p1, p2, p3, texture, Level));
                        }
                    }
                }
                else
                {
                    //process vertex list
                    VertexBuffer = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                    Float32Array f32array = new Float32Array(vertexList.Count * 5);
                    float[]      buffer   = (float[])(object)f32array;
                    int          index    = 0;
                    foreach (PositionTexture pt in vertexList)
                    {
                        if (demTile)
                        {
                            index = AddVertex(buffer, index, GetMappedVertex(pt));
                            demIndex++;
                        }
                        else
                        {
                            index = AddVertex(buffer, index, pt);
                        }
                    }
                    if (demTile)
                    {
                        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;
                            }
                        }
                    }


                    PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                    //process index list
                    for (int i = 0; i < 4; i++)
                    {
                        TriangleCount = childTriangleList[i].Count;
                        if (GetIndexBuffer(i, 0) == null)
                        {
                            Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                            UInt16[] indexArray = (UInt16[])(object)ui16array;

                            index = 0;
                            foreach (Triangle tri in childTriangleList[i])
                            {
                                indexArray[index++] = (UInt16)tri.C;
                                indexArray[index++] = (UInt16)tri.B;
                                indexArray[index++] = (UInt16)tri.A;
                            }
                            ProcessIndexBuffer(indexArray, i);
                        }
                        //IndexBuffers[i] = PrepDevice.createBuffer();
                        //PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                        //PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                    }
                }

                subDivided = true;
            }

            return(true);
        }
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);
            if (renderContext.gl == null)
            {
                if (dataset.DataSetType == ImageSetType.Earth || dataset.DataSetType == ImageSetType.Planet)
                {
                    subDivisionLevel = Math.Max(2, (4 - Level) * 2);
                }
            }
            else
            {
                subDivisionLevel = 32;
            }

            try
            {
                for (int i = 0; i < 4; i++)
                {
                    RenderTriangleLists[i] = new List <RenderTriangle>();
                }

                if (!topDown)
                {
                    return(CreateGeometryBottomsUp(renderContext));
                }
                double lat, lng;

                int    index       = 0;
                double tileDegrees = this.dataset.BaseTileDegrees / (Math.Pow(2, this.Level));

                double latMin       = (90 - (((double)this.tileY) * tileDegrees));
                double latMax       = (90 - (((double)(this.tileY + 1)) * tileDegrees));
                double lngMin       = (((double)this.tileX * tileDegrees) - 180.0);
                double lngMax       = ((((double)(this.tileX + 1)) * tileDegrees) - 180.0);
                double tileDegreesX = lngMax - lngMin;
                double tileDegreesY = latMax - latMin;


                TopLeft     = (Vector3d)GeoTo3d(latMin, lngMin, false);
                BottomRight = (Vector3d)GeoTo3d(latMax, lngMax, false);
                TopRight    = (Vector3d)GeoTo3d(latMin, lngMax, false);
                BottomLeft  = (Vector3d)GeoTo3d(latMax, lngMin, false);


                // Create a vertex buffer
                PositionTexture[] verts = new PositionTexture[(subDivisionLevel + 1) * (subDivisionLevel + 1)]; // Lock the buffer (which will return our structs)
                int x, y;

                double textureStep = 1.0f / subDivisionLevel;
                for (y = 0; y <= subDivisionLevel; y++)
                {
                    if (y != subDivisionLevel)
                    {
                        lat = latMin + (textureStep * tileDegreesY * y);
                    }
                    else
                    {
                        lat = latMax;
                    }
                    for (x = 0; x <= subDivisionLevel; x++)
                    {
                        if (x != subDivisionLevel)
                        {
                            lng = lngMin + (textureStep * tileDegreesX * x);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index        = y * (subDivisionLevel + 1) + x;
                        verts[index] = PositionTexture.CreatePos(GeoTo3d(lat, lng, false), x * textureStep, y * textureStep);
                    }
                }
                TriangleCount = (subDivisionLevel) * (subDivisionLevel) * 2;

                int quarterDivisions = subDivisionLevel / 2;
                int part             = 0;

                if (renderContext.gl == null)
                {
                    for (int y2 = 0; y2 < 2; y2++)
                    {
                        for (int x2 = 0; x2 < 2; x2++)
                        {
                            index = 0;
                            for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                            {
                                for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad

                                    PositionTexture p1;
                                    PositionTexture p2;
                                    PositionTexture p3;

                                    p1 = verts[(y1 * (subDivisionLevel + 1) + x1)];
                                    p2 = verts[((y1 + 1) * (subDivisionLevel + 1) + x1)];
                                    p3 = verts[(y1 * (subDivisionLevel + 1) + (x1 + 1))];
                                    RenderTriangleLists[part].Add(RenderTriangle.Create(p1, p3, p2, texture, Level));

                                    // Second triangle in quad
                                    p1 = verts[(y1 * (subDivisionLevel + 1) + (x1 + 1))];
                                    p2 = verts[((y1 + 1) * (subDivisionLevel + 1) + x1)];
                                    p3 = verts[((y1 + 1) * (subDivisionLevel + 1) + (x1 + 1))];
                                    RenderTriangleLists[part].Add(RenderTriangle.Create(p1, p3, p2, texture, Level));
                                }
                            }
                            part++;
                        }
                    }
                }
                else
                {
                    //process vertex list
                    VertexBuffer = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                    Float32Array f32array = new Float32Array(verts.Length * 5);
                    float[]      buffer   = (float[])(object)f32array;
                    index = 0;
                    foreach (PositionTexture pt in verts)
                    {
                        index = AddVertex(buffer, index, pt);
                    }

                    PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);
                    for (int y2 = 0; y2 < 2; y2++)
                    {
                        for (int x2 = 0; x2 < 2; x2++)
                        {
                            Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                            UInt16[] indexArray = (UInt16[])(object)ui16array;

                            index = 0;
                            for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                            {
                                for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                                {
                                    // First triangle in quad
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + (x1 + 1)));

                                    // Second triangle in quad
                                    indexArray[index++] = (UInt16)((y1 * (subDivisionLevel + 1) + (x1 + 1)));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + x1));
                                    indexArray[index++] = (UInt16)(((y1 + 1) * (subDivisionLevel + 1) + (x1 + 1)));
                                }
                            }

                            IndexBuffers[part] = PrepDevice.createBuffer();
                            PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[part]);
                            PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);

                            part++;
                        }
                    }
                }
            }
            catch
            {
            }
            return(true);
        }
        private void InitializeGrids()
        {
            vertexList           = new List <PositionTexture>();
            childTriangleList    = new List <Triangle> [4];
            childTriangleList[0] = new List <Triangle>();
            childTriangleList[1] = new List <Triangle>();
            childTriangleList[2] = new List <Triangle>();
            childTriangleList[3] = new List <Triangle>();

            bounds = new PositionTexture[9];

            if (Level > 0)
            {
                // Set in constuctor now
                //ToastTile parent = (ToastTile)TileCache.GetTile(level - 1, x / 2, y / 2, dataset, null);
                if (Parent == null)
                {
                    Parent = TileCache.GetTile(Level - 1, tileX / 2, tileY / 2, dataset, null);
                }

                ToastTile parent = (ToastTile)Parent;

                int xIndex = tileX % 2;
                int yIndex = tileY % 2;

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


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

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

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

                bounds[0 + 3 * 0].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 0].Tv = 0 * uvMultiple;
                bounds[1 + 3 * 0].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 0].Tv = 0 * uvMultiple;
                bounds[2 + 3 * 0].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 0].Tv = 0 * uvMultiple;

                bounds[0 + 3 * 1].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 1].Tv = .5f * uvMultiple;
                bounds[1 + 3 * 1].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 1].Tv = .5f * uvMultiple;
                bounds[2 + 3 * 1].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 1].Tv = .5f * uvMultiple;

                bounds[0 + 3 * 2].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 2].Tv = 1 * uvMultiple;
                bounds[1 + 3 * 2].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 2].Tv = 1 * uvMultiple;
                bounds[2 + 3 * 2].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 2].Tv = 1 * uvMultiple;

                vertexList.Add(bounds[0 + 3 * 0]);
                vertexList.Add(bounds[1 + 3 * 0]);
                vertexList.Add(bounds[2 + 3 * 0]);
                vertexList.Add(bounds[0 + 3 * 1]);
                vertexList.Add(bounds[1 + 3 * 1]);
                vertexList.Add(bounds[2 + 3 * 1]);
                vertexList.Add(bounds[0 + 3 * 2]);
                vertexList.Add(bounds[1 + 3 * 2]);
                vertexList.Add(bounds[2 + 3 * 2]);



                if (backslash)
                {
                    childTriangleList[0].Add(Triangle.Create(4, 1, 0));
                    childTriangleList[0].Add(Triangle.Create(3, 4, 0));
                    childTriangleList[1].Add(Triangle.Create(5, 2, 1));
                    childTriangleList[1].Add(Triangle.Create(4, 5, 1));
                    childTriangleList[2].Add(Triangle.Create(7, 4, 3));
                    childTriangleList[2].Add(Triangle.Create(6, 7, 3));
                    childTriangleList[3].Add(Triangle.Create(8, 5, 4));
                    childTriangleList[3].Add(Triangle.Create(7, 8, 4));
                }
                else
                {
                    childTriangleList[0].Add(Triangle.Create(3, 1, 0));
                    childTriangleList[0].Add(Triangle.Create(4, 1, 3));
                    childTriangleList[1].Add(Triangle.Create(4, 2, 1));
                    childTriangleList[1].Add(Triangle.Create(5, 2, 4));
                    childTriangleList[2].Add(Triangle.Create(6, 4, 3));
                    childTriangleList[2].Add(Triangle.Create(7, 4, 6));
                    childTriangleList[3].Add(Triangle.Create(7, 5, 4));
                    childTriangleList[3].Add(Triangle.Create(8, 5, 7));
                }
            }
            else
            {
                bounds[0 + 3 * 0] = PositionTexture.Create(0, -1, 0, 0, 0);
                bounds[1 + 3 * 0] = PositionTexture.Create(0, 0, 1, .5f, 0);
                bounds[2 + 3 * 0] = PositionTexture.Create(0, -1, 0, 1, 0);
                bounds[0 + 3 * 1] = PositionTexture.Create(-1, 0, 0, 0, .5f);
                bounds[1 + 3 * 1] = PositionTexture.Create(0, 1, 0, .5f, .5f);
                bounds[2 + 3 * 1] = PositionTexture.Create(1, 0, 0, 1, .5f);
                bounds[0 + 3 * 2] = PositionTexture.Create(0, -1, 0, 0, 1);
                bounds[1 + 3 * 2] = PositionTexture.Create(0, 0, -1, .5f, 1);
                bounds[2 + 3 * 2] = PositionTexture.Create(0, -1, 0, 1, 1);

                vertexList.Add(bounds[0 + 3 * 0]);
                vertexList.Add(bounds[1 + 3 * 0]);
                vertexList.Add(bounds[2 + 3 * 0]);
                vertexList.Add(bounds[0 + 3 * 1]);
                vertexList.Add(bounds[1 + 3 * 1]);
                vertexList.Add(bounds[2 + 3 * 1]);
                vertexList.Add(bounds[0 + 3 * 2]);
                vertexList.Add(bounds[1 + 3 * 2]);
                vertexList.Add(bounds[2 + 3 * 2]);

                childTriangleList[0].Add(Triangle.Create(3, 1, 0));
                childTriangleList[0].Add(Triangle.Create(4, 1, 3));
                childTriangleList[1].Add(Triangle.Create(5, 2, 1));
                childTriangleList[1].Add(Triangle.Create(4, 5, 1));
                childTriangleList[2].Add(Triangle.Create(7, 4, 3));
                childTriangleList[2].Add(Triangle.Create(6, 7, 3));
                childTriangleList[3].Add(Triangle.Create(7, 5, 4));
                childTriangleList[3].Add(Triangle.Create(8, 5, 7));
                // Setup default matrix of points.
            }
        }
Exemple #22
0
        private void InitGrid()
        {
            List <PositionTexture> vertexList = null;
            List <Triangle>        list2      = null;

            vertexList = new List <PositionTexture>();
            list2      = new List <Triangle>();
            vertexList.Add(new PositionTexture(Bounds[0, 0], 0.0, 0.0));
            vertexList.Add(new PositionTexture(Bounds[1, 0], 0.5, 0.0));
            vertexList.Add(new PositionTexture(Bounds[2, 0], 1.0, 0.0));
            vertexList.Add(new PositionTexture(Bounds[0, 1], 0.0, 0.5));
            vertexList.Add(new PositionTexture(Bounds[1, 1], 0.5, 0.5));
            vertexList.Add(new PositionTexture(Bounds[2, 1], 1.0, 0.5));
            vertexList.Add(new PositionTexture(Bounds[0, 2], 0.0, 1.0));
            vertexList.Add(new PositionTexture(Bounds[1, 2], 0.5, 1.0));
            vertexList.Add(new PositionTexture(Bounds[2, 2], 1.0, 1.0));
            if (Level == 0)
            {
                list2.Add(new Triangle(3, 7, 4));
                list2.Add(new Triangle(3, 6, 7));
                list2.Add(new Triangle(7, 5, 4));
                list2.Add(new Triangle(7, 8, 5));
                list2.Add(new Triangle(5, 1, 4));
                list2.Add(new Triangle(5, 2, 1));
                list2.Add(new Triangle(1, 3, 4));
                list2.Add(new Triangle(1, 0, 3));
            }
            else if (backslash)
            {
                list2.Add(new Triangle(4, 0, 3));
                list2.Add(new Triangle(4, 1, 0));
                list2.Add(new Triangle(5, 1, 4));
                list2.Add(new Triangle(5, 2, 1));
                list2.Add(new Triangle(3, 7, 4));
                list2.Add(new Triangle(3, 6, 7));
                list2.Add(new Triangle(8, 4, 7));
                list2.Add(new Triangle(8, 5, 4));
            }
            else
            {
                list2.Add(new Triangle(1, 0, 3));
                list2.Add(new Triangle(1, 3, 4));
                list2.Add(new Triangle(2, 1, 4));
                list2.Add(new Triangle(2, 4, 5));
                list2.Add(new Triangle(6, 4, 3));
                list2.Add(new Triangle(6, 7, 4));
                list2.Add(new Triangle(7, 5, 4));
                list2.Add(new Triangle(8, 5, 7));
            }
            int subDivisions = this.subDivisions;

            subDivSize = 1f / (float)Math.Pow(2.0, this.subDivisions);
            while (subDivisions-- > 1)
            {
                List <Triangle> triList = new List <Triangle>();
                foreach (Triangle item in list2)
                {
                    item.SubDivide(triList, vertexList);
                }
                list2 = triList;
            }
            int num2 = 1 + (int)Math.Pow(2.0, this.subDivisions);
            int num3 = 1 + (int)Math.Pow(2.0, this.subDivisions);

            PositionTexture[,] textureArray = new PositionTexture[num2, num3];
            raDecMap = new Vector2d[num2, num3];
            foreach (PositionTexture texture in vertexList)
            {
                int num4 = (int)(texture.Tu / (double)subDivSize + 0.1);
                int num5 = (int)(texture.Tv / (double)subDivSize + 0.1);
                textureArray[num4, num5] = texture;
            }
            for (int i = 0; i < num3; i++)
            {
                for (int j = 0; j < num2; j++)
                {
                    raDecMap[j, i] = textureArray[j, i].Position.ToRaDec();
                }
            }
            if (Level == 0)
            {
                raMin  = 0.0;
                raMax  = 360.0;
                decMin = -90.0;
                decMax = 90.0;
                return;
            }
            raMin  = Math.Min(Math.Min(raDecMap[0, 0].X, raDecMap[0, num3 - 1].X), Math.Min(raDecMap[num2 - 1, 0].X, raDecMap[num2 - 1, num3 - 1].X));
            raMax  = Math.Max(Math.Max(raDecMap[0, 0].X, raDecMap[0, num3 - 1].X), Math.Max(raDecMap[num2 - 1, 0].X, raDecMap[num2 - 1, num3 - 1].X));
            decMin = Math.Min(Math.Min(raDecMap[0, 0].Y, raDecMap[0, num3 - 1].Y), Math.Min(raDecMap[num2 - 1, 0].Y, raDecMap[num2 - 1, num3 - 1].Y));
            decMax = Math.Max(Math.Max(raDecMap[0, 0].Y, raDecMap[0, num3 - 1].Y), Math.Max(raDecMap[num2 - 1, 0].Y, raDecMap[num2 - 1, num3 - 1].Y));
            if (Math.Abs(raMax - raMin) > 180.0)
            {
                raMin = raMax;
                raMax = 360.0;
            }
        }
        private PositionTexture Midpoint(PositionTexture positionNormalTextured, PositionTexture positionNormalTextured_2)
        {
            var a1 = Vector3d.Lerp(positionNormalTextured.Position, positionNormalTextured_2.Position, .5f);
            var a1uv = Vector2d.Lerp(new Vector2d(positionNormalTextured.Tu, positionNormalTextured.Tv), new Vector2d(positionNormalTextured_2.Tu, positionNormalTextured_2.Tv), .5f);

            a1.Normalize();
            return new PositionTexture(a1, a1uv.X, a1uv.Y);
        }
Exemple #24
0
        public void AddGlyphPoints(List <PositionTexture> pointList, Vector2d size, Rectangle position, Rectangle uv)
        {
            PositionTexture[] points = new PositionTexture[6];

            for (int i = 0; i < 6; i++)
            {
                points[i] = new PositionTexture();
            }



            Vector3d left  = Vector3d.Cross(center, up);
            Vector3d right = Vector3d.Cross(up, center);

            left.Normalize();
            right.Normalize();
            up.Normalize();

            Vector3d upTan = Vector3d.Cross(center, right);

            upTan.Normalize();

            if (alignment == Alignment.Center)
            {
                left.Multiply(width - position.Left * 2);
                right.Multiply(width - ((width * 2) - position.Right * 2));
            }
            else if (alignment == Alignment.Left)
            {
                left.Multiply(-position.Left * 2);
                right.Multiply(position.Right * 2);
            }

            Vector3d top    = upTan.Copy();
            Vector3d bottom = Vector3d.SubtractVectors(Vector3d.Empty, upTan);

            top.Multiply(height - position.Top * 2);
            bottom.Multiply(height - ((height * 2) - position.Bottom * 2));
            Vector3d ul = center.Copy();

            ul.Add(top);
            if (sky)
            {
                ul.Add(left);
            }
            else
            {
                ul.Subtract(left);
            }
            Vector3d ur = center.Copy();

            ur.Add(top);
            if (sky)
            {
                ur.Add(right);
            }
            else
            {
                ur.Subtract(right);
            }
            Vector3d ll = center.Copy();

            if (sky)
            {
                ll.Add(left);
            }
            else
            {
                ll.Subtract(left);
            }

            ll.Add(bottom);

            Vector3d lr = center.Copy();

            if (sky)
            {
                lr.Add(right);
            }
            else
            {
                lr.Subtract(right);
            }
            lr.Add(bottom);

            points[0].Position = ul.Copy();
            points[0].Tu       = uv.Left;
            points[0].Tv       = uv.Top;
            //     points[0].Color = Color;

            points[2].Tu       = uv.Left;
            points[2].Tv       = uv.Bottom;
            points[2].Position = ll.Copy();
            //      points[2].Color = Color;

            points[1].Tu       = uv.Right;
            points[1].Tv       = uv.Top;
            points[1].Position = ur.Copy();
            //      points[1].Color = Color;

            points[3].Tu       = uv.Right;
            points[3].Tv       = uv.Bottom;
            points[3].Position = lr.Copy();
            //      points[3].Color = Color;

            points[5].Tu       = uv.Right;
            points[5].Tv       = uv.Top;
            points[5].Position = ur.Copy();
            //     points[5].Color = Color;

            points[4].Tu       = uv.Left;
            points[4].Tv       = uv.Bottom;
            points[4].Position = ll.Copy();
            //     points[4].Color = Color;

            if (Rotation != 0 || Tilt != 0 || Bank != 0)
            {
                if (!matInit)
                {
                    Matrix3d lookAt    = Matrix3d.LookAtLH(center, new Vector3d(), up);
                    Matrix3d lookAtInv = lookAt.Clone();
                    lookAtInv.Invert();

                    rtbMat = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(lookAt, Matrix3d.RotationZ(-Rotation / 180 * Math.PI)), Matrix3d.RotationX(-Tilt / 180 * Math.PI)), Matrix3d.RotationY(-Bank / 180 * Math.PI)), lookAtInv);
                    //todo make this true after debug
                    matInit = true;
                }
                for (int i = 0; i < 6; i++)
                {
                    points[i].Position = Vector3d.TransformCoordinate(points[i].Position, rtbMat);
                }
            }

            foreach (PositionTexture pnt in points)
            {
                pointList.Add(pnt);
            }
        }
        private void ProcessAccomindations(UInt16[] indexArray, int a)
        {
            Dictionary <UInt16, UInt16> map     = new Dictionary <UInt16, UInt16>();
            Dictionary <int, UInt16>    gridMap = new Dictionary <int, UInt16>();

            foreach (UInt16 index in indexArray)
            {
                PositionTexture vert   = vertexList[index];
                int             arrayX = (int)(vert.Tu * 16 + .5);
                int             arrayY = (int)(vert.Tv * 16 + .5);
                int             ii     = (arrayY << 8) + arrayX;

                if (!gridMap.ContainsKey(ii))
                {
                    gridMap[ii] = index;
                }
            }


            int sections = 16;

            if ((a & 1) == 1)
            {
                for (int x = 1; x < sections; x += 2)
                {
                    int y   = sections;
                    int key = (y << 8) + x;
                    int val = (y << 8) + x + 1;
                    if (gridMap.ContainsKey(key))
                    {
                        map[gridMap[key]] = (gridMap[val]);
                    }
                }
            }

            if ((a & 2) == 2)
            {
                for (int y = 1; y < sections; y += 2)
                {
                    int x   = sections;
                    int key = (y << 8) + x;
                    int val = ((y + 1) << 8) + x;
                    if (gridMap.ContainsKey(key))
                    {
                        map[gridMap[key]] = (gridMap[val]);
                    }
                }
            }

            if ((a & 4) == 4)
            {
                for (int x = 1; x < sections; x += 2)
                {
                    int y   = 0;
                    int key = (y << 8) + x;
                    int val = (y << 8) + x + 1;
                    if (gridMap.ContainsKey(key))
                    {
                        map[gridMap[key]] = (gridMap[val]);
                    }
                }
            }

            if ((a & 8) == 8)
            {
                for (int y = 1; y < sections; y += 2)
                {
                    int x   = 0;
                    int key = (y << 8) + x;
                    int val = ((y + 1) << 8) + x;
                    if (gridMap.ContainsKey(key))
                    {
                        map[gridMap[key]] = (gridMap[val]);
                    }
                }
            }

            if (map.Count == 0)
            {
                //nothing to process
                return;
            }

            for (int i = 0; i < indexArray.Length; i++)
            {
                if (map.ContainsKey(indexArray[i]))
                {
                    indexArray[i] = map[indexArray[i]];
                }
            }
        }
Exemple #26
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            if (GeometryCreated)
            {
                return(true);
            }
            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }

            LatLngEdges edges = GetLatLngEdges();

            TopLeft     = GeoTo3dTan(edges.latMin, edges.lngMin);
            BottomRight = GeoTo3dTan(edges.latMax, edges.lngMax);
            TopRight    = GeoTo3dTan(edges.latMin, edges.lngMax);
            BottomLeft  = GeoTo3dTan(edges.latMax, edges.lngMin);

            Vector3d center       = Vector3d.MidPoint(TopLeft, BottomRight);
            Vector3d leftCenter   = Vector3d.MidPoint(TopLeft, BottomLeft);
            Vector3d rightCenter  = Vector3d.MidPoint(TopRight, BottomRight);
            Vector3d topCenter    = Vector3d.MidPoint(TopLeft, TopRight);
            Vector3d bottomCenter = Vector3d.MidPoint(BottomLeft, BottomRight);

            if (renderContext.gl == null)
            {
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(TopLeft, 0, 0), PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, 0.5), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(rightCenter, 1, .5), PositionTexture.CreatePos(TopRight, 1, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(center, .5, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(BottomLeft, 0, 1), PositionTexture.CreatePos(bottomCenter, .5, 1), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(BottomRight, 1, 1), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(BottomRight, 1, 1), texture, Level));
                ReadyToRender = true;
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
Exemple #27
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }
            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }


            ComputeMatrix();
            Height = texture.NaturalHeight;
            Width  = texture.NaturalWidth;

            double latMin = 0 + (ScaleY * (Height - PixelCenterY));
            double latMax = 0 - (ScaleY * PixelCenterY);
            double lngMin = 0 + (ScaleX * PixelCenterX);
            double lngMax = 0 - (ScaleX * (Width - PixelCenterX));


            TopLeft     = GeoTo3dTan(latMin, lngMin);
            BottomRight = GeoTo3dTan(latMax, lngMax);
            TopRight    = GeoTo3dTan(latMin, lngMax);
            BottomLeft  = GeoTo3dTan(latMax, lngMin);



            Vector3d topCenter    = Vector3d.Lerp(TopLeft, TopRight, .5f);
            Vector3d bottomCenter = Vector3d.Lerp(BottomLeft, BottomRight, .5f);
            Vector3d center       = Vector3d.Lerp(topCenter, bottomCenter, .5f);
            Vector3d rightCenter  = Vector3d.Lerp(TopRight, BottomRight, .5f);
            Vector3d leftCenter   = Vector3d.Lerp(TopLeft, BottomLeft, .5f);

            //Vector3d center = Vector3d.MidPoint(TopLeft, BottomRight);
            //Vector3d leftCenter = Vector3d.MidPoint(TopLeft, BottomLeft);
            //Vector3d rightCenter = Vector3d.MidPoint(TopRight, BottomRight);
            //Vector3d topCenter = Vector3d.MidPoint(TopLeft, TopRight);
            //Vector3d bottomCenter = Vector3d.MidPoint(BottomLeft, BottomRight);



            //verts[0].Position = TopLeft;
            //verts[0].Normal = TopLeft;
            //verts[0].Tu = 0;
            //verts[0].Tv = 0;
            //verts[1].Position = TopRight;
            //verts[1].Normal = TopRight;
            //verts[1].Tu = 1;
            //verts[1].Tv = 0;
            //verts[2].Position = BottomRight;
            //verts[2].Normal = BottomRight;
            //verts[2].Tu = 1;
            //verts[2].Tv = 1;
            //verts[3].Position = BottomLeft;
            //verts[3].Normal = BottomLeft;
            //verts[3].Tu = 0;
            //verts[3].Tv = 1;


            if (renderContext.gl == null)
            {
                //RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height), PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height), PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height), texture, Level));
                //RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height), PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height), PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height), texture, Level));
                vertexList = new List <PositionTexture>();

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                childTriangleList = new List <Triangle>();

                if (dataset.BottomsUp)
                {
                    childTriangleList.Add(Triangle.Create(0, 1, 2));
                    childTriangleList.Add(Triangle.Create(2, 1, 3));
                }
                else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));
                }

                int count = 3;
                while (count-- > 1)
                {
                    List <Triangle> newList = new List <Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivide(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];


                    RenderTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, texture, Level, miter));
                }
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }
            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }


            double tileDegrees = this.dataset.BaseTileDegrees / (Math.Pow(2, this.Level));

            double latMin       = (((double)this.dataset.BaseTileDegrees / 2.0 - (((double)this.tileY) * tileDegrees)) + this.dataset.OffsetY);
            double latMax       = (((double)this.dataset.BaseTileDegrees / 2.0 - (((double)(this.tileY + 1)) * tileDegrees)) + this.dataset.OffsetY);
            double lngMin       = ((((double)this.tileX * tileDegrees) - (double)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX);
            double lngMax       = (((((double)(this.tileX + 1)) * tileDegrees) - (double)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX);
            double tileDegreesX = lngMax - lngMin;
            double tileDegreesY = latMax - latMin;



            TopLeft     = GeoTo3dTan(latMin, lngMin);
            BottomRight = GeoTo3dTan(latMax, lngMax);
            TopRight    = GeoTo3dTan(latMin, lngMax);
            BottomLeft  = GeoTo3dTan(latMax, lngMin);

            double latCenter = (latMin + latMax) / 2.0;
            double lngCenter = (lngMin + lngMax) / 2.0;

            Vector3d center       = Vector3d.MidPoint(TopLeft, BottomRight);
            Vector3d leftCenter   = Vector3d.MidPoint(TopLeft, BottomLeft);
            Vector3d rightCenter  = Vector3d.MidPoint(TopRight, BottomRight);
            Vector3d topCenter    = Vector3d.MidPoint(TopLeft, TopRight);
            Vector3d bottomCenter = Vector3d.MidPoint(BottomLeft, BottomRight);

            if (renderContext.gl == null)
            {
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(TopLeft, 0, 0), PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, 0.5), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(rightCenter, 1, .5), PositionTexture.CreatePos(TopRight, 1, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(center, .5, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(BottomLeft, 0, 1), PositionTexture.CreatePos(bottomCenter, .5, 1), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(BottomRight, 1, 1), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(BottomRight, 1, 1), texture, Level));
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }