private Dodecant(int hexsideBase, IntMatrix2D matrix)
        {
            var sign = Math.Sign(matrix.Determinant);

            HexsideMap = hexside => Mod6[hexsideBase + sign * hexside];
            Matrix     = matrix;
        }
示例#2
0
    /// <summary></summary>
    /// <remarks>
    /// Takes a circle in the form of a center point and radius, and a function
    /// that can tell whether a given cell is opaque. Calls the setFoV action on
    /// every cell that is both within the radius and visible from the center. 
    /// </remarks>
    /// <param name="observerCoords">Cordinates of observer;s hex.</param>
    /// <param name="radius">Maximum radius for Field-of-View.</param>
    /// <param name="observerHeight">Height (ASL) of the observer's eyes.</param>
    /// <param name="isOnBoard">Is this hex on the baoard.</param>
    /// <param name="targetHeight">Returns ground level (ASL) of supplied hex.</param>
    /// <param name="terrainHeight">Returns height (ASL) of terrain in supplied hex.</param>
    /// <param name="setFoV">Sets a hex as visible in the Field-of-View.</param>
    public static void ComputeFieldOfView(
      ICoordsCanon            observerCoords, 
      int                     radius, 
      int                     observerHeight,
      Func<ICoordsCanon,bool> isOnBoard,
      Func<ICoordsCanon,int>  targetHeight, 
      Func<ICoordsCanon,int>  terrainHeight,
      Action<ICoordsCanon>    setFoV
    ) {
      #if TraceFOV
        TraceFlag.FieldOfView.Trace(true, " - Coords = " + observerCoords.User.ToString());
      #endif
      var matrixOrigin = new IntMatrix2D(observerCoords.Vector);

      setFoV(observerCoords);    // Always visible to self!
      #if TraceFoV
        for (int dodecant = 3; dodecant < 4; dodecant++) {
          TraceFlag.FieldOfView.Trace(true," - Dodecant: {0}", dodecant);
      #else
        Parallel.For (0, matrices.Count, dodecant => {
      #endif
          var matrix = matrices[dodecant] * matrixOrigin;
          ComputeFieldOfViewInDodecantZero(
            radius,
            observerHeight,
            TranslateDodecant(matrix, isOnBoard),
            TranslateDodecant(matrix, targetHeight),
            TranslateDodecant(matrix, terrainHeight),
            TranslateDodecant(matrix, setFoV));
        }
      #if !TraceFoV
        );
      #endif
    }
示例#3
0
    /// <summary></summary>
    /// <remarks>
    /// Takes a circle in the form of a center point and radius, and a function
    /// that can tell whether a given cell is opaque. Calls the setFoV action on
    /// every cell that is both within the radius and visible from the center. 
    /// </remarks>
    /// <param name="observerCoords">Cordinates of observer;s hex.</param>
    /// <param name="radius">Maximum radius for Field-of-View.</param>
    /// <param name="observerHeight">Height (ASL) of the observer's eyes.</param>
    /// <param name="isOnBoard">Is this hex on the baoard.</param>
    /// <param name="targetHeight">Returns ground level (ASL) of supplied hex.</param>
    /// <param name="terrainHeight">Returns height (ASL) of terrain in supplied hex.</param>
    /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
    public static void ComputeFieldOfView(
      HexCoords            observerCoords, 
      int                  radius, 
      int                  observerHeight,
      Func<HexCoords,bool> isOnBoard,
      Func<HexCoords,int>  targetHeight, 
      Func<HexCoords,int>  terrainHeight,
      Action<HexCoords>    setFieldOfView
    ) {
      #if TraceFOV
        TraceFlag.FieldOfView.Trace(true, " - Coords = " + observerCoords.User.ToString());
      #endif
      var matrixOrigin = new IntMatrix2D(observerCoords.Canon);

      setFieldOfView(observerCoords);    // Always visible to self!
      #if TraceFoV
        int dodecant = 0;
        foreach (var matrix in matrices.Select(m => m*matrixOrigin)) {
          TraceFlags.FieldOfView.Trace(true," - Dodecant: {0}", dodecant++);
      #else
        Parallel.ForEach(_dodecantMatrices.Select(m => m*matrixOrigin), matrix => {
      #endif
          ComputeFieldOfViewInDodecantZero(
            radius,
            observerHeight,
            TranslateDodecant(matrix, isOnBoard),
            TranslateDodecant(matrix, targetHeight),
            TranslateDodecant(matrix, terrainHeight),
            TranslateDodecant(matrix, setFieldOfView));
        }
      #if !TraceFoV
        );
      #endif
    }
示例#4
0
 protected HexBoard(HexSize sizeHexes, HexSize gridSize, BoardStorage <Maybe <THex> > boardHexes)
 {
     BoardHexes      = boardHexes;
     MapScale        = 1.00F;
     IsTransposed    = false;
     MapSizeHexes    = sizeHexes;
     GridSize        = gridSize;
     HexCentreOffset = new HexSize(GridSize.Width * 2 / 3, GridSize.Height / 2);
     GridSizePixels  = new IntMatrix2D(GridSize.Width, 0,
                                       0, GridSize.Height,
                                       GridSize.Width / 3, GridSize.Height / 2);
 }
示例#5
0
        /// <summary>Build dodecant matrices from sextant matrices and reflection about theta=30.</summary>
        static ShadowCasting()
        {
            var matrixRotate  = new IntMatrix2D(0, -1, 1, 1);
            var matrixReflect = new IntMatrix2D(-1, 0, 1, 1);

            matrices = new List <IntMatrix2D>(12);
            matrices.Add(IntMatrix2D.Identity);
            matrices.Add(matrixReflect);
            for (int i = 2; i < 12; i += 2)
            {
                matrices.Add(matrixRotate * matrices[i - 2]);
                matrices.Add(matrixReflect * matrices[i]);
            }
        }
        /// <summary>Build dodecant matrices from sextant matrices and reflection about theta=30.</summary>
        static List <IntMatrix2D> BuildDodecantMatrices()
        {
            var matrixRotate  = new IntMatrix2D(0, -1, 1, 1);
            var matrixReflect = new IntMatrix2D(-1, 0, 1, 1);
            var matrices      = new List <IntMatrix2D>(12);

            matrices.Add(IntMatrix2D.Identity);
            matrices.Add(matrixReflect);
            for (int i = 2; i < 12; i += 2)
            {
                matrices.Add(matrixRotate * matrices[i - 2]);
                matrices.Add(matrixReflect * matrices[i]);
            }
            return(matrices);
        }
示例#7
0
        public HexGridExampleForm()
        {
            InitializeComponent();

            hexgridPanel.Host                      =
                MapBoard                           = new TerrainMap();
            MapBoard.ShowFov                       = buttonFieldOfView.Checked
                                                   = true;
            toolStripComboBox1.SelectedIndex       = 0;
            var matrix = new IntMatrix2D(2, 0, 0, -2, 0, 2 * MapBoard.SizeHexes.Height - 1, 2);

            HexCoords.SetCustomMatrices(matrix, matrix);

            Application.AddMessageFilter(this);
        }
        /// <summary>Calculate Field-of-View from a detailed prescription.</summary>
        /// <param name="coordsObserver">Cordinates of observer;s hex.</param>
        /// <param name="radius">Maximum radius for Field-of-View.</param>
        /// <param name="heightObserver">Height (ASL) of the observer's eyes.</param>
        /// <param name="isOnboard">Returns whether this hex on the baoard.</param>
        /// <param name="heightTarget">Returns ground level (ASL) of supplied hex.</param>
        /// <param name="heightTerrain">Returns height (ASL) of terrain in supplied hex.</param>
        /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
        private static void ComputeFieldOfView(
            HexCoords coordsObserver,
            int radius,
            int heightObserver,
            Func <HexCoords, bool> isOnboard,
            Func <HexCoords, int> heightTarget,
            Func <HexCoords, Hexside, int> heightTerrain,
            Action <HexCoords> setFieldOfView
            )
        {
            if (setFieldOfView == null)
            {
                throw new ArgumentNullException("setFieldOfView");
            }
            FieldOfViewTrace(true, " - Coords = " + coordsObserver.User.ToString());
            var matrixOrigin = new IntMatrix2D(coordsObserver.Canon);

            if (radius >= 0)
            {
                setFieldOfView(coordsObserver);           // Always visible to self!
            }
            Action <Dodecant> dodecantFov = d => {
                var dodecant = new Dodecant(d, matrixOrigin);
                _mapCoordsDodecant = hex => dodecant.TranslateDodecant <HexCoords>(v => v)(hex);

                ComputeFieldOfViewInDodecantZero(
                    radius,
                    heightObserver,
                    dodecant.TranslateDodecant(isOnboard),
                    dodecant.TranslateDodecant(heightTarget),
                    dodecant.TranslateDodecant(heightTerrain),
                    dodecant.TranslateDodecant(setFieldOfView)
                    );
            };

      #if DEBUG
            InSerial = true;
      #endif
            if (InSerial)
            {
                Dodecant.Dodecants.ForEach(dodecantFov);
            }
            else
            {
                Parallel.ForEach(Dodecant.Dodecants, dodecantFov);
            }
        }
示例#9
0
        protected HexBoard(HexSize sizeHexes, HexSize gridSize, BoardStorage <Maybe <THex> > boardHexes)
        {
            BoardHexes      = boardHexes;
            MapScale        = 1.00F;
            IsTransposed    = false;
            MapSizeHexes    = sizeHexes;
            GridSize        = gridSize;
            HexCentreOffset = new HexSize(GridSize.Width * 2 / 3, GridSize.Height / 2);
            GridSizePixels  = new IntMatrix2D(GridSize.Width, 0,
                                              0, GridSize.Height,
                                              GridSize.Width / 3, GridSize.Height / 2);

            EntryCosts = new BlockedBoardStorage32x32 <Maybe <HexsideCosts> >(sizeHexes,
                                                                              hexCoords => HexsideCosts.EntryCosts(boardHexes, hexCoords), 1);
            ExitCosts = new BlockedBoardStorage32x32 <Maybe <HexsideCosts> >(sizeHexes,
                                                                             hexCoords => HexsideCosts.ExitCosts(boardHexes, hexCoords), 1);
        }
        public MapDisplay() : base()
        {
            GridSize = new Size(27, 30);
            StartHex = GoalHex = HotSpotHex = HexCoords.EmptyUser;

            HexgridPath = new GraphicsPath();
            HexgridPath.AddLines(new Point[] {
                new Point(GridSize.Width * 1 / 3, 0),
                new Point(GridSize.Width * 3 / 3, 0),
                new Point(GridSize.Width * 4 / 3, GridSize.Height / 2),
                new Point(GridSize.Width * 3 / 3, GridSize.Height),
                new Point(GridSize.Width * 1 / 3, GridSize.Height),
                new Point(0, GridSize.Height / 2),
                new Point(GridSize.Width * 1 / 3, 0)
            });
            MapSizeMatrix = new IntMatrix2D(GridSize.Width, 0,
                                            0, GridSize.Height,
                                            GridSize.Width / 3, GridSize.Height / 2);
        }
        /// <summary></summary>
        /// <remarks>
        /// Takes a circle in the form of a center point and radius, and a function
        /// that can tell whether a given cell is opaque. Calls the setFoV action on
        /// every cell that is both within the radius and visible from the center. 
        /// </remarks>
        /// <param name="observerCoords">Cordinates of observer;s hex.</param>
        /// <param name="radius">Maximum radius for Field-of-View.</param>
        /// <param name="observerHeight">Height (ASL) of the observer's eyes.</param>
        /// <param name="isOnBoard">Is this hex on the baoard.</param>
        /// <param name="targetHeight">Returns ground level (ASL) of supplied hex.</param>
        /// <param name="terrainHeight">Returns height (ASL) of terrain in supplied hex.</param>
        /// <param name="setFieldOfView">Sets a hex as visible in the Field-of-View.</param>
        public static void ComputeFieldOfView(
          HexCoords observerCoords,
          int radius,
          int observerHeight,
          Func<HexCoords, bool> isOnBoard,
          Func<HexCoords, int> targetHeight,
          Func<HexCoords, int> terrainHeight,
          Action<HexCoords> setFieldOfView
        )
        {
#if TraceFOV
        TraceFlag.FieldOfView.Trace(true, " - Coords = " + observerCoords.User.ToString());
#endif
            var matrixOrigin = new IntMatrix2D(observerCoords.Canon);

            setFieldOfView(observerCoords);    // Always visible to self!
#if TraceFoV
        int dodecant = 0;
        foreach (var matrix in matrices.Select(m => m*matrixOrigin)) {
          TraceFlags.FieldOfView.Trace(true," - Dodecant: {0}", dodecant++);
#else
            Parallel.ForEach(_dodecantMatrices.Select(m => m * matrixOrigin), matrix =>
            {
#endif
                ComputeFieldOfViewInDodecantZero(
                  radius,
                  observerHeight,
                  TranslateDodecant(matrix, isOnBoard),
                  TranslateDodecant(matrix, targetHeight),
                  TranslateDodecant(matrix, terrainHeight),
                  TranslateDodecant(matrix, setFieldOfView));
            }
#if !TraceFoV
);
#endif
        }
 public Dodecant(Dodecant dodecant, IntMatrix2D matrixOrigin)
 {
     HexsideMap = dodecant.HexsideMap;
     Matrix     = dodecant.Matrix * matrixOrigin;
 }
 private static Func <HexCoords, T> TranslateDodecant <T>(IntMatrix2D matrix, Func <HexCoords, T> func)
 {
     return((v) => func(HexCoords.NewCanonCoords(v.Canon * matrix)));
 }
 private static Action <HexCoords> TranslateDodecant(IntMatrix2D matrix, Action <HexCoords> action)
 {
     return((v) => action(HexCoords.NewCanonCoords(v.Canon * matrix)));
 }
示例#15
0
 private static Action <ICoordsCanon> TranslateDodecant(IntMatrix2D matrix, Action <ICoordsCanon> action)
 {
     return((v) => action(HexCoords.NewCanonCoords(v.Vector * matrix)));
 }