Exemple #1
0
        public static DoublePoint ContinuousIsoStaggeredScreenToMapMapper(double screenX, double screenY)
        {
            // get the normalized grid coordinate as integer.
            // this roughly tells us the cell we are in.
            // Note: Grid coordinates are 1-unit based,
            //       as opposed to the 4-unit based view coordinates
            //
            // For Iso-Staggered maps the grid mapper already returns the (almost) correct
            // coordinates for the central tile.
            // We still have to check whether the coordinate given is
            // in one of the corner regions.
            var cgrid = ContinuousGridScreenToMapMapper(screenX, screenY);
            var ngrid = MapCoordinate.Normalize(cgrid);

            // offsets within the tile are not scaled.
            var dx = cgrid.X - ngrid.X;
            var dy = cgrid.Y - ngrid.Y;

            // In Staggered maps, the underlying map is stretched on the y-axis
            // compared to normal grids. On the y-axis one map-grid-cell of 1
            // moves the position by 2.
            ngrid = ngrid.WithY(ngrid.Y * 2);

            if (Math.Abs(dx) > 0.5 - Math.Abs(dy))
            {
                // This is one of the corner regions.
                var direction = Compute(dx, dy);
                staggeredNavigator.NavigateTo(direction, ngrid, out MapCoordinate result);
                var    d   = (0.5 - Math.Abs(dx));
                double rdx = -Math.Sign(dx) * d;
                double rdy = -Math.Sign(dy) * (0.5 - Math.Abs(dy));
                return(new DoublePoint(result.X + rdx, result.Y + rdy));
            }

            return(new DoublePoint(ngrid.X + dx, ngrid.Y + dy));
        }
Exemple #2
0
        public static MapCoordinate IsoStaggeredScreenToMapMapper(double screenX, double screenY)
        {
            var r = ContinuousIsoStaggeredScreenToMapMapper(screenX, screenY);

            return(MapCoordinate.Normalize(r));
        }