コード例 #1
0
        //---------------------------------------------------------------------
        public void entityMove(Entity entity, EbVector3 pos_world)
        {
            EbVector2    pos_grid = _world2gird(pos_world);
            EbGridRegion region   = mGridRegions[(int)pos_grid.x, (int)pos_grid.y];

            if (region == null)
            {
                return;
            }

            EbGridRegion region_last = entity.getUserData <EbGridRegion>();

            if (region.Equals(region_last))
            {
                region.entityMove(entity);
            }
            else
            {
                if (region_last != null)
                {
                    region_last.entityLeaveRegion(entity);
                }
                region.entityEnterRegion(entity);
            }
        }
コード例 #2
0
        //---------------------------------------------------------------------
        public List <EbVector3> navigate(EbVector3 from_world, EbVector3 to_world, uint max_step)
        {
            EbVector2 from_grid = _world2gird(from_world);
            EbVector2 to_grid   = _world2gird(to_world);

            List <EbVector3> route_points = new List <EbVector3>();

            if (_isInGrid(from_grid) && _isInGrid(to_grid))
            {
                if (mPixelNav.search((int)from_grid.x, (int)from_grid.y, (int)to_grid.x, (int)to_grid.y, max_step))
                {
                    for (int i = 1; i < mPixelNav.Route.Count - 1; ++i)
                    {
                        route_points.Add(_grid2world(mPixelNav.Route[i]));
                    }
                    route_points.Add(to_world);
                }
                else
                {
                    for (int i = 1; i < mPixelNav.Route.Count; ++i)
                    {
                        route_points.Add(_grid2world(mPixelNav.Route[i]));
                    }
                }
            }

            return(route_points);
        }
コード例 #3
0
        //---------------------------------------------------------------------
        EbVector3 _grid2world(EbVector2 pos_grid)
        {
            EbVector3 v = new EbVector3(pos_grid.x, 0, pos_grid.y);

            v.x = (v.x / (float)WidthGrid) * WidthWorld;
            v.z = (v.z / (float)HeightGrid) * HeightWorld;

            v.x += XMinWorld;
            v.z  = ZMinWorld - v.z;

            return(v);
        }
コード例 #4
0
        //---------------------------------------------------------------------
        EbVector2 _world2gird(EbVector3 pos_world)
        {
            EbVector2 v = new EbVector2(pos_world.x, pos_world.z);

            v.x -= XMinWorld;
            v.y  = ZMinWorld - v.y;

            v.x = (v.x / WidthWorld) * (float)WidthGrid;
            v.y = (v.y / HeightWorld) * (float)HeightGrid;

            return(v);
        }
コード例 #5
0
        //---------------------------------------------------------------------
        public void entityLeaveRegion(Entity entity, EbVector3 pos_world)
        {
            EbVector2    pos_grid = _world2gird(pos_world);
            EbGridRegion region   = mGridRegions[(int)pos_grid.x, (int)pos_grid.y];

            if (region == null)
            {
                return;
            }

            region.entityLeaveRegion(entity);
        }
コード例 #6
0
        //---------------------------------------------------------------------
        public HashSet <EbGridRegion> getGridRegions(EbVector3 min_world, EbVector3 max_world)
        {
            EbVector2 min_gird = _world2gird(min_world);
            EbVector2 max_gird = _world2gird(max_world);

            HashSet <EbGridRegion> regions = new HashSet <EbGridRegion>();

            for (int h = (int)min_gird.y; h <= (int)max_gird.y; h++)
            {
                for (int w = (int)min_gird.x; w < (int)max_gird.x; w++)
                {
                    regions.Add(mGridRegions[w, h]);
                }
            }
            return(regions);
        }
コード例 #7
0
 //---------------------------------------------------------------------
 bool _isInGrid(EbVector2 pos_grid)
 {
     return((0 <= pos_grid.x && pos_grid.x < mPixelNav.SizeX) &&
            (0 <= pos_grid.y && pos_grid.y < mPixelNav.SizeY));
 }