Exemple #1
0
        void InitGrid()
        {
            List<PositionTexture> vertexList = null;
            List<Triangle> triangleList = null;
            vertexList = new List<PositionTexture>();
            triangleList = new List<Triangle>();

            vertexList.Add(new PositionTexture(Bounds[0, 0], 0, 0));
            vertexList.Add(new PositionTexture(Bounds[1, 0], .5f, 0));
            vertexList.Add(new PositionTexture(Bounds[2, 0], 1, 0));
            vertexList.Add(new PositionTexture(Bounds[0, 1], 0, .5f));
            vertexList.Add(new PositionTexture(Bounds[1, 1], .5f, .5f));
            vertexList.Add(new PositionTexture(Bounds[2, 1], 1, .5f));
            vertexList.Add(new PositionTexture(Bounds[0, 2], 0, 1));
            vertexList.Add(new PositionTexture(Bounds[1, 2], .5f, 1));
            vertexList.Add(new PositionTexture(Bounds[2, 2], 1, 1));

            if (Level == 0)
            {
                triangleList.Add(new Triangle(3, 7, 4));
                triangleList.Add(new Triangle(3, 6, 7));
                triangleList.Add(new Triangle(7, 5, 4));
                triangleList.Add(new Triangle(7, 8, 5));
                triangleList.Add(new Triangle(5, 1, 4));
                triangleList.Add(new Triangle(5, 2, 1));
                triangleList.Add(new Triangle(1, 3, 4));
                triangleList.Add(new Triangle(1, 0, 3));
            }
            else
            {
                if (backslash)
                {
                    triangleList.Add(new Triangle(4, 0, 3));
                    triangleList.Add(new Triangle(4, 1, 0));
                    triangleList.Add(new Triangle(5, 1, 4));
                    triangleList.Add(new Triangle(5, 2, 1));
                    triangleList.Add(new Triangle(3, 7, 4));
                    triangleList.Add(new Triangle(3, 6, 7));
                    triangleList.Add(new Triangle(7, 4, 8));
                    triangleList.Add(new Triangle(4, 7, 8));
                    triangleList.Add(new Triangle(8, 5, 4));


                }
                else
                {

                    triangleList.Add(new Triangle(1, 0, 3));
                    triangleList.Add(new Triangle(1, 3, 4));
                    triangleList.Add(new Triangle(2, 1, 4));
                    triangleList.Add(new Triangle(2, 4, 5));
                    triangleList.Add(new Triangle(6, 4, 3));
                    triangleList.Add(new Triangle(6, 7, 4));
                    triangleList.Add(new Triangle(7, 5, 4));
                    triangleList.Add(new Triangle(8, 5, 7));
                }

            }

            int count = subDivisions;
            subDivSize = 1.0f / (float)Math.Pow(2, subDivisions);
            while (count-- > 1)
            {
                List<Triangle> newList = new List<Triangle>();
                foreach (Triangle tri in triangleList)
                {
                    tri.SubDivide(newList, vertexList);
                }
                triangleList = newList;

            }

            int xCount = 1 + (int)Math.Pow(2, subDivisions);
            int yCount = 1 + (int)Math.Pow(2, subDivisions);

            PositionTexture[,] points = new PositionTexture[xCount, yCount];
            raDecMap = new Vector2d[xCount, yCount];
            foreach (PositionTexture vertex in vertexList)
            {
                int indexX = (int)((vertex.Tu / subDivSize) + .1);
                int indexY = (int)((vertex.Tv / subDivSize) + .1);

                points[indexX, indexY] = vertex;
            }
            for (int y = 0; y < yCount; y++)
            {
                for (int x = 0; x < xCount; x++)
                {
                    raDecMap[x, y] = points[x, y].Position.ToRaDec((y == 0 || x == 32) & !backslash);
                }
            }

            if (Level == 0)
            {
                raMin = 0;
                raMax = 360;
                decMin = -90;
                decMax = 90;
            }
            else
            {
                raMin = Math.Min(Math.Min((double)raDecMap[0, 0].X, raDecMap[0, yCount - 1].X), Math.Min((double)raDecMap[xCount - 1, 0].X, raDecMap[xCount - 1, yCount - 1].X));
                raMax = Math.Max(Math.Max((double)raDecMap[0, 0].X, raDecMap[0, yCount - 1].X), Math.Max((double)raDecMap[xCount - 1, 0].X, raDecMap[xCount - 1, yCount - 1].X));
                decMin = Math.Min(Math.Min((double)raDecMap[0, 0].Y, raDecMap[0, yCount - 1].Y), Math.Min((double)raDecMap[xCount - 1, 0].Y, raDecMap[xCount - 1, yCount - 1].Y));
                decMax = Math.Max(Math.Max((double)raDecMap[0, 0].Y, raDecMap[0, yCount - 1].Y), Math.Max((double)raDecMap[xCount - 1, 0].Y, raDecMap[xCount - 1, yCount - 1].Y));
                if (Math.Abs((double)(this.raMax - this.raMin)) > 180.0)
                {
                    this.raMin = this.raMax;
                    this.raMax = 360.0;
                }

            }
        }
Exemple #2
0
        void InitGrid()
        {
            List <PositionTexture> vertexList   = null;
            List <Triangle>        triangleList = null;

            vertexList   = new List <PositionTexture>();
            triangleList = new List <Triangle>();

            vertexList.Add(new PositionTexture(Bounds[0, 0], 0, 0));
            vertexList.Add(new PositionTexture(Bounds[1, 0], .5f, 0));
            vertexList.Add(new PositionTexture(Bounds[2, 0], 1, 0));
            vertexList.Add(new PositionTexture(Bounds[0, 1], 0, .5f));
            vertexList.Add(new PositionTexture(Bounds[1, 1], .5f, .5f));
            vertexList.Add(new PositionTexture(Bounds[2, 1], 1, .5f));
            vertexList.Add(new PositionTexture(Bounds[0, 2], 0, 1));
            vertexList.Add(new PositionTexture(Bounds[1, 2], .5f, 1));
            vertexList.Add(new PositionTexture(Bounds[2, 2], 1, 1));

            if (Level == 0)
            {
                triangleList.Add(new Triangle(3, 7, 4));
                triangleList.Add(new Triangle(3, 6, 7));
                triangleList.Add(new Triangle(7, 5, 4));
                triangleList.Add(new Triangle(7, 8, 5));
                triangleList.Add(new Triangle(5, 1, 4));
                triangleList.Add(new Triangle(5, 2, 1));
                triangleList.Add(new Triangle(1, 3, 4));
                triangleList.Add(new Triangle(1, 0, 3));
            }
            else
            {
                if (backslash)
                {
                    triangleList.Add(new Triangle(4, 0, 3));
                    triangleList.Add(new Triangle(4, 1, 0));
                    triangleList.Add(new Triangle(5, 1, 4));
                    triangleList.Add(new Triangle(5, 2, 1));
                    triangleList.Add(new Triangle(3, 7, 4));
                    triangleList.Add(new Triangle(3, 6, 7));
                    triangleList.Add(new Triangle(7, 4, 8));
                    triangleList.Add(new Triangle(4, 7, 8));
                    triangleList.Add(new Triangle(8, 5, 4));
                }
                else
                {
                    triangleList.Add(new Triangle(1, 0, 3));
                    triangleList.Add(new Triangle(1, 3, 4));
                    triangleList.Add(new Triangle(2, 1, 4));
                    triangleList.Add(new Triangle(2, 4, 5));
                    triangleList.Add(new Triangle(6, 4, 3));
                    triangleList.Add(new Triangle(6, 7, 4));
                    triangleList.Add(new Triangle(7, 5, 4));
                    triangleList.Add(new Triangle(8, 5, 7));
                }
            }

            int count = subDivisions;

            subDivSize = 1.0f / (float)Math.Pow(2, subDivisions);
            while (count-- > 1)
            {
                List <Triangle> newList = new List <Triangle>();
                foreach (Triangle tri in triangleList)
                {
                    tri.SubDivide(newList, vertexList);
                }
                triangleList = newList;
            }

            int xCount = 1 + (int)Math.Pow(2, subDivisions);
            int yCount = 1 + (int)Math.Pow(2, subDivisions);

            PositionTexture[,] points = new PositionTexture[xCount, yCount];
            raDecMap = new Vector2d[xCount, yCount];
            foreach (PositionTexture vertex in vertexList)
            {
                int indexX = (int)((vertex.Tu / subDivSize) + .1);
                int indexY = (int)((vertex.Tv / subDivSize) + .1);

                points[indexX, indexY] = vertex;
            }
            for (int y = 0; y < yCount; y++)
            {
                for (int x = 0; x < xCount; x++)
                {
                    raDecMap[x, y] = points[x, y].Position.ToRaDec((y == 0 || x == 32) & !backslash);
                }
            }

            if (Level == 0)
            {
                raMin  = 0;
                raMax  = 360;
                decMin = -90;
                decMax = 90;
            }
            else
            {
                raMin  = Math.Min(Math.Min((double)raDecMap[0, 0].X, raDecMap[0, yCount - 1].X), Math.Min((double)raDecMap[xCount - 1, 0].X, raDecMap[xCount - 1, yCount - 1].X));
                raMax  = Math.Max(Math.Max((double)raDecMap[0, 0].X, raDecMap[0, yCount - 1].X), Math.Max((double)raDecMap[xCount - 1, 0].X, raDecMap[xCount - 1, yCount - 1].X));
                decMin = Math.Min(Math.Min((double)raDecMap[0, 0].Y, raDecMap[0, yCount - 1].Y), Math.Min((double)raDecMap[xCount - 1, 0].Y, raDecMap[xCount - 1, yCount - 1].Y));
                decMax = Math.Max(Math.Max((double)raDecMap[0, 0].Y, raDecMap[0, yCount - 1].Y), Math.Max((double)raDecMap[xCount - 1, 0].Y, raDecMap[xCount - 1, yCount - 1].Y));
                if (Math.Abs((double)(this.raMax - this.raMin)) > 180.0)
                {
                    this.raMin = this.raMax;
                    this.raMax = 360.0;
                }
            }
        }