예제 #1
0
        /// <summary>
        /// Converts a point in the Map coordinate system to one in the World coordinate system
        /// </summary>
        /// <param name="map">The map that the input is located in</param>
        /// <param name="input">The input point to convert, in Map coordinates</param>
        /// <returns>The input point converted to a World position</returns>
        public static Point ConvertToWorldPos(Map map, Point input)
        {
            double worldPosX = map.ContinentRectangle.X + (input.X - map.MapRectangle.X) * MapToWorldRatio;
            double worldPosY = map.ContinentRectangle.Y + ((map.MapRectangle.Y + map.MapRectangle.Height) - input.Y) * MapToWorldRatio;

            return new Point(worldPosX, worldPosY, input.Z);
        }
예제 #2
0
        /// <summary>
        /// Converts a point in the World coordinate system to one in the Maps coordinate system
        /// </summary>
        /// <param name="map">The map that the input is located in</param>
        /// <param name="input">The input point to convert, in World coordinates</param>
        /// <returns>The input point converted to a Map position</returns>
        public static Point ConvertToMapPos(Map map, Point input)
        {
            double mapPosX = (input.X - map.ContinentRectangle.X) * WorldToMapRatio + map.MapRectangle.X;
            double mapPosY = (map.MapRectangle.Y + map.MapRectangle.Height) - (input.Y - map.ContinentRectangle.Y) * WorldToMapRatio;

            return new Point(mapPosX, mapPosY, input.Z);
        }
예제 #3
0
        /// <summary>
        /// Converts a point in the Map coordinate system to one in the World coordinate system
        /// </summary>
        /// <param name="map">The map that the input is located in</param>
        /// <param name="input">The input point to convert, in Map coordinates</param>
        /// <param name="zoom">Zoom level to consider when calculating the World position</param>
        /// <returns>The input point converted to a World position</returns>
        public static Point ConvertToWorldPos(Map map, Point input, int zoom)
        {
            int factor = 1 << (map.Continent.MaximumZoom - zoom);

            double worldPosX = map.ContinentRectangle.X + (input.X - map.MapRectangle.X) * MapToWorldRatio;
            double worldPosY = map.ContinentRectangle.Y + ((map.MapRectangle.Y + map.MapRectangle.Height) - input.Y) * MapToWorldRatio;

            Point scaledOutput = new Point(worldPosX / factor, worldPosY / factor, input.Z);
            return scaledOutput;
        }
예제 #4
0
        /// <summary>
        /// Converts a point in the World coordinate system to one in the Maps coordinate system
        /// </summary>
        /// <param name="map">The map that the input is located in</param>
        /// <param name="input">The input point to convert, in World coordinates</param>
        /// <param name="zoom">Zoom level to consider when calculating the Map position</param>
        /// <returns>The input point converted to a Map position</returns>
        public static Point ConvertToMapPos(Map map, Point input, int zoom)
        {
            int factor = 1 << (map.Continent.MaximumZoom - zoom);
            Point scaledInput = new Point(input.X * factor, input.Y * factor);

            double mapPosX = (scaledInput.X - map.ContinentRectangle.X) * WorldToMapRatio + map.MapRectangle.X;
            double mapPosY = (map.MapRectangle.Y + map.MapRectangle.Height) - (scaledInput.Y - map.ContinentRectangle.Y) * WorldToMapRatio;

            return new Point(mapPosX, mapPosY, input.Z);
        }
예제 #5
0
        public void ConvertToMapPos_ConvertToWorldPos_Equals_OriginalInput_NoZoom()
        {
            Map testMap = new Map();
            int x = random.Next();
            int y = random.Next();
            testMap.MapRectangle = new Rectangle(new Vector2D(x, y), new Vector2D(random.Next(x, int.MaxValue), random.Next(y, int.MaxValue)));
            x = random.Next();
            y = random.Next();
            testMap.ContinentRectangle = new Rectangle(new Vector2D(x, y), new Vector2D(random.Next(x, int.MaxValue), random.Next(y, int.MaxValue)));
            testMap.Continent = new Continent();

            Point inputPoint = new Point(
                random.Next((int)testMap.ContinentRectangle.X, (int)(testMap.ContinentRectangle.X + testMap.ContinentRectangle.Width)),
                random.Next((int)testMap.ContinentRectangle.Y, (int)(testMap.ContinentRectangle.Y + testMap.ContinentRectangle.Height)));

            Point mapPos = MapsHelper.ConvertToMapPos(testMap, inputPoint);
            Point worldPos = MapsHelper.ConvertToWorldPos(testMap, mapPos);

            Assert.AreEqual(inputPoint.X, worldPos.X, 0.5);
            Assert.AreEqual(inputPoint.Y, worldPos.Y, 0.5);
            Assert.AreEqual(inputPoint.Z, worldPos.Z, 0.5);
        }