예제 #1
0
        override public FlatHexPoint RawWorldToGrid(Vector2 point)
        {
            int x = GLMathf.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x);
            int y = GLMathf.FloorToInt((point.y - x * cellDimensions.y / 2 + cellDimensions.y / 2) / cellDimensions.y);

            return(new FlatHexPoint(x, y));
        }
예제 #2
0
        public override LinePoint RawWorldToGrid(Vector2 worldPoint)
        {
            var point = (worldPoint + cellDimensions / 2);

            var m = GLMathf.FloorToInt(point.x / cellDimensions.x);

            return(m);
        }
예제 #3
0
        public override DiamondPoint RawWorldToGrid(Vector2 point)
        {
            int x =
                GLMathf.FloorToInt((point.x + 0 * cellDimensions.x / 2) / cellDimensions.x +
                                   /*GLMathf.FloorToInt(*/ (point.y + cellDimensions.y / 2) / cellDimensions.y);

            int y =
                GLMathf.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y -
                                   (point.x + 0 * cellDimensions.x / 2) / cellDimensions.x);

            return(new DiamondPoint(x, y));
        }
예제 #4
0
        /**
         *      Gives a coloring of the grid such that
         *      if a point p has color k, then all points
         *      p + m[ux, 0] + n[vx, vy] have the same color
         *      for any integers a and b.
         *
         *      More information anout grid colorings:
         *      http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/
         *
         *      @since 1.7
         */

        public int GetColor(int ux, int vx, int vy)
        {
            int colorCount = ux * vy;

            float a = (x * vy - y * vx) / (float)colorCount;
            float b = (y * ux) / (float)colorCount;

            int m = GLMathf.FloorToInt(a);
            int n = GLMathf.FloorToInt(b);

            int baseVectorX = m * ux + n * vx;
            int baseVectorY = n * vy;

            int offsetX = GLMathf.FloorMod(X - baseVectorX, ux);
            int offsetY = Y - baseVectorY;

            int colorIndex = GLMathf.FloorToInt(offsetX + offsetY * ux);

            return(colorIndex);
        }
예제 #5
0
        /**
         *      Gives a coloring of the grid such that
         *      if a point p has color k, then all points
         *      p + m[ux, 0] + n[vx, vy] have the same color
         *      for any integers a and b.
         *
         *      More information anout grid colorings:
         *      http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/
         *
         *      @since 1.7
         */
        public int __GetColor__ReferenceImplementation(int ux, int vx, int vy)
        {
            var u = new DiamondPoint(ux, 0);
            var v = new DiamondPoint(vx, vy);

            int colorCount = u.PerpDot(v);

            float a = PerpDot(v) / (float)colorCount;
            float b = -PerpDot(u) / (float)colorCount;

            int m = GLMathf.FloorToInt(a);
            int n = GLMathf.FloorToInt(b);

            int baseVectorX = m * u.X + n * v.X;
            int baseVectorY = n * u.Y + n * v.Y;

            int offsetX = GLMathf.Mod(X - baseVectorX, ux);
            int offsetY = Y - baseVectorY;

            int colorIndex = GLMathf.FloorToInt(offsetX + offsetY * ux);

            return(colorIndex);
        }
예제 #6
0
		public override RectPoint RawWorldToGrid(Vector2 point)
		{
			return new RectPoint(
				GLMathf.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x),
				GLMathf.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y));
		}