Beispiel #1
0
        public List<View> GetCollidedViews(View view)
        {
            Rectangle viewsBoundingBox = view.GetBoundingBox ();
            Dictionary<View, bool> collidedViews = new Dictionary<View, bool> ();

            foreach (PartitionCell cell in view.CollisionCells) {
                foreach (View otherView in cell.Views) {
                    if (otherView.Visible && !collidedViews.ContainsKey(otherView) && otherView != view) {
                        Rectangle otherViewsBoundingBox = otherView.GetBoundingBox ();
                        if (otherViewsBoundingBox.Intersects (viewsBoundingBox)) {
                            collidedViews.Add (otherView, true);
                        }
                    }
                }
            }

            List<View> result = new List<View> ();
            foreach (View collidedView in collidedViews.Keys) {
                result.Add (collidedView);
            }

            return result;
        }
Beispiel #2
0
        public void UpdatePartitionCells(View view, List<PartitionCell> cells)
        {
            // Potential improvement: get the firstRow, lastRow, firstCol, and lastCol from
            // cells, compare to the newly computed values, and only update the cells collection
            // if there is a difference

            foreach (PartitionCell cell in cells) {
                cell.RemoveView (view);
            }
            cells.Clear ();

            Rectangle boundingBox = view.GetBoundingBox ();
            int firstRow = GetCellRow (boundingBox.Y);
            int lastRow = GetCellRow (boundingBox.Bottom);
            int firstCol = GetCellCol (boundingBox.X);
            int lastCol = GetCellCol (boundingBox.Right);
            for (int row=firstRow; row <= lastRow; row++) {
                for (int col=firstCol; col <= lastCol; col++) {
                    PartitionCell cell = Cells [row, col];
                    cell.AddView (view);
                    cells.Add (cell);
                }
            }
        }