Пример #1
0
        public static List <Chunk> chunksIntersecting(World world, Vector3 sphereCenter, float radius)
        {
            List <Chunk> ret = new List <Chunk>();

            //sphere is smaller than a chunk
            if (radius < (WorldParameters.theChunkSize / 2))
            {
                Chunk chunk = chunkIntersecting(world, sphereCenter);

                if (chunk != null)
                {
                    ret.Add(chunk);
                    //no need to check all the sides if the aabb totally contains the sphere
                    AABox bounds = chunk.bounds();

                    if (Intersections.AABBContainsSphere(sphereCenter, radius, bounds) == true)
                    {
                        return(ret);
                    }

                    ChunkKey.Neighbor getNeighbors = ChunkKey.Neighbor.NONE;
                    if ((sphereCenter.X - radius) < bounds.myMin.X)
                    {
                        getNeighbors |= ChunkKey.Neighbor.LEFT;
                    }
                    if ((sphereCenter.X + radius) > bounds.myMax.X)
                    {
                        getNeighbors |= ChunkKey.Neighbor.RIGHT;
                    }
                    if ((sphereCenter.Y - radius) < bounds.myMin.Y)
                    {
                        getNeighbors |= ChunkKey.Neighbor.BOTTOM;
                    }
                    if ((sphereCenter.Y + radius) > bounds.myMax.Y)
                    {
                        getNeighbors |= ChunkKey.Neighbor.TOP;
                    }
                    if ((sphereCenter.Z - radius) < bounds.myMin.Z)
                    {
                        getNeighbors |= ChunkKey.Neighbor.FRONT;
                    }
                    if ((sphereCenter.Z + radius) > bounds.myMax.Z)
                    {
                        getNeighbors |= ChunkKey.Neighbor.BACK;
                    }
                    ret.AddRange(world.findNeighbors(chunk, getNeighbors));
                }
            }
            else //sphere could cover several chunks
            {
                foreach (Chunk chunk in world.chunks.Values)
                {
                    if (Intersections.AABoxSphereIntersection(chunk.bounds(), sphereCenter, radius) == true)
                    {
                        ret.Add(chunk);
                    }
                }
            }

            return(ret);
        }