Beispiel #1
0
        /// <summary>
        /// Subdivides the given list of triangles with the given list of vertices.
        /// </summary>
        /// <param name="triList">
        /// List of triangles.
        /// </param>
        /// <param name="vertexList">
        /// List of vertices.
        /// </param>
        public void SubDivide(Collection <Triangle> triList, Collection <PositionTexture> vertexList)
        {
            if (triList == null)
            {
                throw new ArgumentNullException("triList");
            }

            if (vertexList == null)
            {
                throw new ArgumentNullException("vertexList");
            }

            Vector3d first  = Vector3d.Lerp(vertexList[this.B].Position, vertexList[this.C].Position, .5f);
            Vector3d second = Vector3d.Lerp(vertexList[this.C].Position, vertexList[this.A].Position, .5f);
            Vector3d third  = Vector3d.Lerp(vertexList[this.A].Position, vertexList[this.B].Position, .5f);

            Vector2d firstUV  = Vector2d.Lerp(new Vector2d(vertexList[this.B].Tu, vertexList[this.B].Tv), new Vector2d(vertexList[this.C].Tu, vertexList[this.C].Tv), .5);
            Vector2d secondUV = Vector2d.Lerp(new Vector2d(vertexList[this.C].Tu, vertexList[this.C].Tv), new Vector2d(vertexList[this.A].Tu, vertexList[this.A].Tv), .5);
            Vector2d thirdUV  = Vector2d.Lerp(new Vector2d(vertexList[this.A].Tu, vertexList[this.A].Tv), new Vector2d(vertexList[this.B].Tu, vertexList[this.B].Tv), .5);

            first.Normalize();
            second.Normalize();
            third.Normalize();

            int firstIndex  = vertexList.Count;
            int secondIndex = vertexList.Count + 1;
            int thirdIndex  = vertexList.Count + 2;

            vertexList.Add(new PositionTexture(first, firstUV.X, firstUV.Y));
            vertexList.Add(new PositionTexture(second, secondUV.X, secondUV.Y));
            vertexList.Add(new PositionTexture(third, thirdUV.X, thirdUV.Y));

            triList.Add(new Triangle(this.A, thirdIndex, secondIndex));
            triList.Add(new Triangle(this.B, firstIndex, thirdIndex));
            triList.Add(new Triangle(this.C, secondIndex, firstIndex));
            triList.Add(new Triangle(firstIndex, secondIndex, thirdIndex));
        }
Beispiel #2
0
        /// <summary>
        /// Converts a given point to RA-Dec coordinate space.
        /// </summary>
        /// <param name="point">
        /// Point between 1 and 0 inclusive.
        /// </param>
        /// <returns>
        /// Point in RA-Dec coordinates.
        /// </returns>
        public Vector2d PointToRaDec(Vector2d point)
        {
            int indexX = (int)(point.X / this.subDivSize);
            int indexY = (int)(point.Y / this.subDivSize);

            if (indexX > ((int)Math.Pow(2, this.subDivisions) - 1))
            {
                indexX = ((int)Math.Pow(2, this.subDivisions) - 1);
            }

            if (indexY > ((int)Math.Pow(2, this.subDivisions) - 1))
            {
                indexY = ((int)Math.Pow(2, this.subDivisions) - 1);
            }

            double distX = (point.X - ((double)indexX * this.subDivSize)) / this.subDivSize;
            double distY = (point.Y - ((double)indexY * this.subDivSize)) / this.subDivSize;

            Vector2d interpolatedTop    = Vector2d.Lerp(this.mapRaDec[indexX, indexY], this.mapRaDec[indexX + 1, indexY], distX);
            Vector2d interpolatedBottom = Vector2d.Lerp(this.mapRaDec[indexX, indexY + 1], this.mapRaDec[indexX + 1, indexY + 1], distX);
            Vector2d result             = Vector2d.Lerp(interpolatedTop, interpolatedBottom, distY);

            return(result);
        }