예제 #1
0
 static IEnumerable <GridVector> ScanArea(GridVector start)
 {
     for (int i = -1; i <= 1; ++i)
     {
         for (int j = -1; j <= 1; ++j)
         {
             yield return(new GridVector(i, j));
         }
     }
 }
예제 #2
0
        public static IEnumerable <GridVector> ScaDir(Vector2 start, Vector2 dir, float dist)
        {
            GridVector startGrid = new GridVector(start);

            if (Mathf.Abs(dir.x) >= Mathf.Abs(dir.y))
            {
                foreach (GridVector point in scanX(startGrid, dir, dist))
                {
                    yield return(point);
                }
            }
            else
            {
                foreach (GridVector point in scanY(startGrid, dir, dist))
                {
                    yield return(point);
                }
            }
        }
예제 #3
0
        public static IEnumerable <ushort> ScanSegmentsInArea(Vector2 point)
        {
            GridVector start = new GridVector(point);

            foreach (GridVector grid in ScanArea(start))
            {
                int index = grid.Index;
                //Log.Debug($"grid={grid} dist={dist}");
                ushort segmentID = 0;
                if (index >= 0 && index < netMan.m_segmentGrid.Length)
                {
                    segmentID = netMan.m_segmentGrid[index];
                }
                while (segmentID != 0)
                {
                    yield return(segmentID);

                    segmentID = segmentID.ToSegment().m_nextGridSegment;
                }
            }
        }
예제 #4
0
        static IEnumerable <GridVector> scanY(GridVector start, Vector2 dir, float dist)
        {
            float ratioXY = Mathf.Abs(dir.x / dir.y);

            dist /= GRID_SIZE;
            int disty = Mathf.CeilToInt(dist / Mathf.Sqrt(1 + ratioXY * ratioXY));
            int signx = (int)Mathf.Sign(dir.x);
            int signy = (int)Mathf.Sign(dir.y);

            for (int y = 0; y <= disty; ++y)
            {
                int x = Mathf.RoundToInt(y * ratioXY);

                GridVector grid = new GridVector(start.x + x * signx, start.y + y * signy);
                yield return(grid);

                yield return(grid + GridVector.left);

                yield return(grid + GridVector.right);
            }
        }
예제 #5
0
        static IEnumerable <GridVector> scanX(GridVector start, Vector2 dir, float dist)
        {
            float ratioYX = Mathf.Abs(dir.y / dir.x);

            dist /= GRID_SIZE;
            int distx = Mathf.CeilToInt(dist / Mathf.Sqrt(1 + ratioYX * ratioYX)); // dist = sqrt(distx^2 + (distx*ratioYX)^2)
            int signx = (int)Mathf.Sign(dir.x);
            int signy = (int)Mathf.Sign(dir.y);

            for (int x = 0; x <= distx; ++x)
            {
                int y = Mathf.RoundToInt(x * ratioYX);

                GridVector grid = new GridVector(start.x + x * signx, start.y + y * signy);
                yield return(grid);

                yield return(grid + GridVector.up);

                yield return(grid + GridVector.down);
            }
        }