Пример #1
0
        public GridWorld(BoundingBox boundingBox, Vector tileDimensions, ItemCache itemCache)
        {
            this.readWriteLock = new ReaderWriterLockSlim();

            this.rectangleArea = new BoundingBox
            {
                Min = new Vector {
                    X = boundingBox.Min.X, Y = boundingBox.Min.Y, Z = boundingBox.Min.Z
                },
                Max = new Vector {
                    X = boundingBox.Max.X, Y = boundingBox.Max.Y, Z = boundingBox.Max.Z
                }
            };
            var size = new Vector {
                X = boundingBox.Max.X - boundingBox.Min.X + 1, Y = boundingBox.Max.Y - boundingBox.Min.Y + 1, Z = boundingBox.Max.Z - boundingBox.Min.Z + 1
            };

            if (tileDimensions.X <= 0)
            {
                tileDimensions.X = size.X;
            }
            if (tileDimensions.Y <= 0)
            {
                tileDimensions.Y = size.Y;
            }
            if (tileDimensions.Z <= 0)
            {
                tileDimensions.Z = size.Z;
            }
            this.tileDimensions = tileDimensions;
            this.tileSize       = new Vector {
                X = tileDimensions.X - 1, Y = tileDimensions.Y - 1, Z = tileDimensions.Z - 1
            };
            this.itemCache = itemCache;

            var regionsX = (int)Math.Ceiling(size.X / (double)tileDimensions.X);
            var regionsY = (int)Math.Ceiling(size.Y / (double)tileDimensions.Y);
            var regionsZ = (int)Math.Ceiling(size.Z / (double)tileDimensions.Z);

            this.worldRegions = new Region[regionsX][][];
            Vector current = boundingBox.Min;

            for (int x = 0; x < regionsX; x++)
            {
                this.worldRegions[x] = new Region[regionsY][];
                for (int y = 0; y < regionsY; y++)
                {
                    this.worldRegions[x][y] = new Region[regionsZ];
                    for (int z = 0; z < regionsZ; z++)
                    {
                        this.worldRegions[x][y][z] = new Region(current);
                        current.Z += tileDimensions.Z;
                    }
                    current.Y += tileDimensions.Y;
                    current.Z  = boundingBox.Min.Z;
                }
                current.X += tileDimensions.X;
                current.Y  = boundingBox.Min.Y;
                current.Z  = boundingBox.Min.Z;
            }
            //PrintRegions(boundingBox);
        }
Пример #2
0
 public GridWorld(Vector corner1, Vector corner2, Vector tileDimensions, ItemCache itemCache)
     : this(BoundingBox.CreateFromPoints(corner1, corner2), tileDimensions, itemCache)
 {
 }