Beispiel #1
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));
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
        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);
        }
Beispiel #7
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);
        }
        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);
        }