Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the OctTileMap class.
        /// </summary>
        /// <param name="level">
        /// Zoom level.
        /// </param>
        /// <param name="pixelX">
        /// X coordinate.
        /// </param>
        /// <param name="pixelY">
        /// Y coordinate.
        /// </param>
        public OctTileMap(int level, int pixelX, int pixelY)
        {
            this.subDivisions = 5;
            this.subDivSize = 1.0f / (float)Math.Pow(2, 5);

            this.Level = level;
            this.Y = pixelY;
            this.X = pixelX;

            int levels = 0;
            Vector3d[,] oldBounds = null;
            this.backslash = false;
            while (levels <= level)
            {
                if (levels == 0)
                {
                    oldBounds = OctTileMap.masterBounds;
                }
                else
                {
                    Vector3d[,] newBounds = new Vector3d[3, 3];
                    int tempX = (int)(pixelX / Math.Pow(2, level - levels));
                    int tempY = (int)(pixelY / Math.Pow(2, level - levels));
                    int indexX = tempX % 2;
                    int indexY = tempY % 2;
                    if (levels == 1)
                    {
                        this.backslash = indexX == 1 ^ indexY == 1;
                    }

                    newBounds[0, 0] = oldBounds[indexX, indexY];
                    newBounds[1, 0] = Vector3d.MidPoint(oldBounds[indexX, indexY], oldBounds[indexX + 1, indexY]);
                    newBounds[2, 0] = oldBounds[indexX + 1, indexY];
                    newBounds[0, 1] = Vector3d.MidPoint(oldBounds[indexX, indexY], oldBounds[indexX, indexY + 1]);

                    if (this.backslash)
                    {
                        newBounds[1, 1] = Vector3d.MidPoint(oldBounds[indexX, indexY], oldBounds[indexX + 1, indexY + 1]);
                    }
                    else
                    {
                        newBounds[1, 1] = Vector3d.MidPoint(oldBounds[indexX + 1, indexY], oldBounds[indexX, indexY + 1]);
                    }

                    newBounds[2, 1] = Vector3d.MidPoint(oldBounds[indexX + 1, indexY], oldBounds[indexX + 1, indexY + 1]);
                    newBounds[0, 2] = oldBounds[indexX, indexY + 1];
                    newBounds[1, 2] = Vector3d.MidPoint(oldBounds[indexX, indexY + 1], oldBounds[indexX + 1, indexY + 1]);
                    newBounds[2, 2] = oldBounds[indexX + 1, indexY + 1];
                    oldBounds = newBounds;
                }

                levels++;
            }

            this.bounds = oldBounds;

            // Initialize the map.
            this.InitGrid();
        }
Beispiel #2
0
 /// <summary>
 /// Performs a linear interpolation between two 3-D vectors.
 /// </summary>
 /// <param name="left">
 /// First vector.
 /// </param>
 /// <param name="right">
 /// Second vector.
 /// </param>
 /// <param name="interpolater">
 /// Parameter that linearly interpolates between the vectors.
 /// </param>
 /// <returns>
 /// A Microsoft.DirectX.Vector3d structure that is the result of the linear interpolation.
 /// </returns>
 public static Vector3d Lerp(Vector3d left, Vector3d right, double interpolater)
 {
     return new Vector3d(
         left.X * (1.0 - interpolater) + right.X * interpolater,
         left.Y * (1.0 - interpolater) + right.Y * interpolater,
         left.Z * (1.0 - interpolater) + right.Z * interpolater);
 }
Beispiel #3
0
 /// <summary>
 /// Computes midpoint of two given vectors.
 /// </summary>
 /// <param name="first">
 /// First Microsoft.DirectX.Vector3d structure.
 /// </param>
 /// <param name="second">
 /// Second Microsoft.DirectX.Vector3d structure.
 /// </param>
 /// <returns>
 /// Midpoint of the two vectors.
 /// </returns>
 public static Vector3d MidPoint(Vector3d first, Vector3d second)
 {
     Vector3d result = new Vector3d((first.X + second.X) / 2, (first.Y + second.Y) / 2, (first.Z + second.Z) / 2);
     result.Normalize();
     return result;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the PositionTexture struct.
 /// </summary>
 /// <param name="pos">
 /// A Microsoft.DirectX.Vector3d object that contains the vertex position.
 /// </param>
 /// <param name="u">
 /// U coordinate.
 /// </param>
 /// <param name="v">
 /// V coordinate.
 /// </param>
 public PositionTexture(Vector3d pos, double u, double v)
     : this(pos.X, pos.Y, pos.Z, u, v)
 {
 }