Ejemplo n.º 1
0
        public PotentialMap(NavigationManager navManager, PotentialMapType type = PotentialMapType.Exponential)
        {
            m_navManager = navManager;

            m_type = type;

            m_grid    = new Grid <PotentielMapCell>(navManager.NavigationGrid.Width, navManager.NavigationGrid.Height);
            m_sources = new List <PotentialMapInfluence>();
            m_costs   = new List <PotentialMapInfluence>();

            m_linearParameters              = new PotentialMapLinearParameters();
            m_linearParameters.MinValue     = 0;
            m_linearParameters.SpatialDecay = Engine.Debug.EditSingle("LinearDecay", 0.1f);

            //Initialise data points
            for (int i = 0; i < m_grid.Width; i++)
            {
                for (int j = 0; j < m_grid.Height; j++)
                {
                    Point index = new Point(i, j);
                    m_grid[index]         = new PotentielMapCell();
                    m_grid[index].NavCell = navManager.NavigationGrid[index];
                }
            }
        }
Ejemplo n.º 2
0
        private void ExponentialInfluence(PotentielMapCell cell, NavigationCell navCell)
        {
            float influence = 0;

            for (int iNeighbour = 0; iNeighbour < navCell.Neighbours.Length; iNeighbour++)
            {
                var nextNavCell = navCell.Neighbours[iNeighbour];
                if (navCell.Neighbours[iNeighbour] == null || !navCell.CanNavigateToNeighbour[iNeighbour])
                {
                    continue;
                }
                var nextCell = m_grid[nextNavCell.Index];

                float dist          = Vector2.Distance(nextNavCell.Position, navCell.Position) / m_navManager.Parameters.GridSpacing;
                float costFactor    = 1 / (1 + cell.CostValue); costFactor = LBE.MathHelper.Clamp(0, 1, costFactor);
                float cellInfluence = nextCell.Value * (float)Math.Exp(-dist * m_influenceDecay * (1 + cell.CostValue));
                if (cellInfluence > Math.Abs(influence))
                {
                    influence = cellInfluence;
                }
            }
            cell.Influence = LBE.MathHelper.Clamp(-1, 1, influence);
        }
Ejemplo n.º 3
0
        private void LinearInfluence(float linearDecay, PotentielMapCell cell, NavigationCell navCell)
        {
            float influence = float.NegativeInfinity;

            for (int iNeighbour = 0; iNeighbour < navCell.Neighbours.Length; iNeighbour++)
            {
                var nextNavCell = navCell.Neighbours[iNeighbour];
                if (navCell.Neighbours[iNeighbour] == null || !navCell.CanNavigateToNeighbour[iNeighbour])
                {
                    continue;
                }

                var nextCell = m_grid[nextNavCell.Index];

                //Linear approx. of distance, that is exact for distSq = 1 or distSq = 2
                float distSq      = Vector2.DistanceSquared(nextNavCell.Position, navCell.Position) / (m_navManager.Parameters.GridSpacing * m_navManager.Parameters.GridSpacing);
                float sq2minusOne = 1.414213f - 1;
                float fastDist    = (1 - sq2minusOne) + sq2minusOne * distSq;

                float cellInfluence = nextCell.Value - linearDecay * (1 + cell.CostValue) * fastDist * fastDist;
                influence = Math.Max(influence, cellInfluence);
            }
            cell.Influence = LBE.MathHelper.Clamp(m_linearParameters.MinValue, 1, influence);
        }