public List <Grid> getGrids(GeomBase geom, List <Grid> grids = null)
    {
        if (null == grids)
        {
            this.helpGrids.Clear();
            grids = this.helpGrids;
        }
        if (geom.radius <= 0)
        {
            return(grids);
        }
        if (geom.applyEntity)
        {
            geom.position.copy(geom.entity.position);
            geom.angle = geom.entity.angle;
        }
        geom.updatePoints();
        Vector2D positon = geom.position;
        int      radius  = geom.radius;
        int      startX  = (int)((positon.x - radius) / this.size);
        int      endX    = (int)((positon.x + radius) / this.size);
        int      startY  = (int)Math.Max(0, (positon.y - radius) / this.size);
        int      endY    = (int)Math.Min((positon.y + radius) / this.size, this.rowNum - 1);

        for (int i = startX; i <= endX; i++)
        {
            for (int j = startY; j <= endY; j++)
            {
                Grid grid = this.getGrid(i, j);
                grids.Add(grid);
            }
        }
        return(grids);
    }
示例#2
0
    public static CollisionInfo checkCollision(GeomBase geom1, GeomBase geom2, MapData mapData)
    {
        //把大的放在前面!
        if (geom1.type > geom2.type)
        {
            GeomBase temp = geom1;
            geom1 = geom2;
            geom2 = temp;
        }

        if (geom1.applyEntity)
        {
            geom1.position.copy(geom1.entity.position);
            geom1.angle = geom1.entity.angle;
        }
        if (geom2.applyEntity)
        {
            geom2.position.copy(geom2.entity.position);
            geom2.angle = geom2.entity.angle;
        }

        CollisionInfo result = realPosition(geom1.position, geom2.position, mapData);

        geom1.position.copy(result.pos1);
        geom2.position.copy(result.pos2);
        geom1.updatePoints();
        geom2.updatePoints();

        int type = geom1.type | geom2.type;

        result = handlerMap[1](geom1, geom2);

        //非圆形 就再判断一次!
        if (result.isHit && type != 1)
        {
            result = handlerMap[type](geom1, geom2);
        }

        return(result);
    }