コード例 #1
0
        public void generateCollisionGrid(int cellSize)
        {
            //find the bounds of the entire map
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue),
                    max = -min;

            foreach (Brush brush in core.mapEngine.brushes)
            {
                BoundingBox b = brush.boundingBox;
                min.X = Math.Min(min.X, b.Min.X);
                min.Y = Math.Min(min.Y, b.Min.Y);
                min.Z = Math.Min(min.Z, b.Min.Z);
                max.X = Math.Max(max.X, b.Max.X);
                max.Y = Math.Max(max.Y, b.Max.Y);
                max.Z = Math.Max(max.Z, b.Max.Z);
            }
            min       -= new Vector3(1, 1, 1) * cellSize;
            max       += new Vector3(1, 1, 1) * cellSize;
            gridOffset = min;

            //now that we have the bounds, calculate the grid cell bounds
            grid = new CollisionGridCell[(int)Math.Max(1, Math.Ceiling((max.X - min.X) / cellSize)),
                                         (int)Math.Max(1, Math.Ceiling((max.Y - min.Y) / cellSize)),
                                         (int)Math.Max(1, Math.Ceiling((max.Z - min.Z) / cellSize))];
            for (int k = 0; k < grid.GetLength(2); ++k)
            {
                for (int j = 0; j < grid.GetLength(1); ++j)
                {
                    for (int i = 0; i < grid.GetLength(0); ++i)
                    {
                        grid[i, j, k] = new CollisionGridCell();
                    }
                }
            }
            this.cellSize = cellSize;
            foreach (ICollidable c in core.allCollidables())
            {
                updateCollisionCellsFor(c);
            }
        }
コード例 #2
0
        public void generateCollisionGrid(int cellSize)
        {
            //find the bounds of the entire map
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue),
                    max = -min;
            foreach (Brush brush in core.mapEngine.brushes) {
                BoundingBox b = brush.boundingBox;
                min.X = Math.Min(min.X, b.Min.X);
                min.Y = Math.Min(min.Y, b.Min.Y);
                min.Z = Math.Min(min.Z, b.Min.Z);
                max.X = Math.Max(max.X, b.Max.X);
                max.Y = Math.Max(max.Y, b.Max.Y);
                max.Z = Math.Max(max.Z, b.Max.Z);
            }
            min -= new Vector3(1, 1, 1) * cellSize;
            max += new Vector3(1, 1, 1) * cellSize;
            gridOffset = min;

            //now that we have the bounds, calculate the grid cell bounds
            grid = new CollisionGridCell[(int)Math.Max(1, Math.Ceiling((max.X - min.X) / cellSize)),
                                         (int)Math.Max(1, Math.Ceiling((max.Y - min.Y) / cellSize)),
                                         (int)Math.Max(1, Math.Ceiling((max.Z - min.Z) / cellSize))];
            for(int k = 0; k < grid.GetLength(2); ++k)
                for(int j = 0; j < grid.GetLength(1); ++j)
                    for (int i = 0; i < grid.GetLength(0); ++i)
                        grid[i, j, k] = new CollisionGridCell();
            this.cellSize = cellSize;
            foreach (ICollidable c in core.allCollidables())
                updateCollisionCellsFor(c);
        }