Exemplo n.º 1
0
        public static HashSet<Body> GetBodies(Body mCBody)
        {
            var result = new HashSet<Body>();

            foreach (var cell in mCBody.Cells)
                foreach (var group in mCBody.GroupsToCheck)
                    foreach (var body in cell.GroupedBodies[group])
                        result.Add(body);

            return result;
        }
Exemplo n.º 2
0
        private HashSet<Cell> CalculateCells(Body mBody)
        {
            var startX = mBody.Left/_cellSize + _offset;
            var startY = mBody.Top/_cellSize + _offset;
            var endX = mBody.Right/_cellSize + _offset;
            var endY = mBody.Bottom/_cellSize + _offset;

            var result = new HashSet<Cell>();

            if (startX < 0 || endX >= _columns || startY < 0 || endY >= _rows)
            {
                mBody.OnOutOfBounds.SafeInvoke();
                return result;
            }

            for (var iY = startY; iY <= endY; iY++)
                for (var iX = startX; iX <= endX; iX++)
                    result.Add(_cells[iX, iY]);

            return result;
        }
Exemplo n.º 3
0
 public void UpdateBody(Body mCBody)
 {
     RemoveBody(mCBody);
     AddBody(mCBody);
 }
Exemplo n.º 4
0
 public void RemoveBody(Body mCBody)
 {
     foreach (var cell in mCBody.Cells) cell.RemoveBody(mCBody);
 }
Exemplo n.º 5
0
 public void AddBody(Body mCBody)
 {
     mCBody.Cells = CalculateCells(mCBody);
     foreach (var cell in mCBody.Cells) cell.AddBody(mCBody);
 }
Exemplo n.º 6
0
 private bool IsOverlapping(Body mBody)
 {
     return Right > mBody.Left && Left < mBody.Right && (Bottom > mBody.Top && Top < mBody.Bottom);
 }
Exemplo n.º 7
0
 public CBody(Body mBody)
 {
     Body = mBody;
 }
Exemplo n.º 8
0
 public void RemoveBody(Body mBody)
 {
     foreach (var group in mBody.Groups) GroupedBodies[group].Remove(mBody);
 }
Exemplo n.º 9
0
 public void AddBody(Body mBody)
 {
     foreach (var group in mBody.Groups) GroupedBodies[group].Add(mBody);
 }