public IEnumerable <T> GetWorldObjects(ChunkCoordinate coord)
        {
            var index = coord.GetUnrolledIndex();
            var ret   = data[index];

            return(ret);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="size"></param>
 /// <param name="maxDepth">Root has 0 depth</param>
 public OptimizedWorldOctree(Vector3 size, int maxDepth)
 {
     this.size     = size;
     this.maxDepth = maxDepth;
     data          = new List <T> [ChunkCoordinate.GetCumulativeNbChunks(maxDepth + 1)];
     for (int i = 0; i < data.Length; i++)
     {
         data[i] = new List <T>();
     }
 }
Exemple #3
0
        /// <summary>
        /// Returns all chunks with depth maxdepth for which condition is true.
        /// The condition has as constraint:
        ///     condition(chunk) => condition(parent(chunk))
        /// </summary>
        /// <returns></returns>
        public static ChunkCoordinate FindChunkUp <T>(this IWorldOctree <T> tree, ChunkCoordinate start,
                                                      Func <ChunkCoordinate, bool> condition) where T : IWorldObject
        {
            if (start.IsEmtpy)
            {
                return(start);
            }
            if (condition(start))
            {
                return(start);
            }

            return(tree.FindChunkUp(start.GetParent(), condition));
        }
 public bool IsLeaf(ChunkCoordinate parent)
 {
     return(false); // Infinite tree!
 }
 public BoundingBox GetChunkBoundingBox(ChunkCoordinate chunk)
 {
     return(chunk.GetBoundingBox(new Vector3(), radius * 2));
 }
        public Vector3 GetChunkCenter(ChunkCoordinate parent)
        {
            var bb = parent.GetBoundingBox(new Vector3(), radius * 2);

            return((bb.Maximum + bb.Minimum) * 0.5f);
        }
 public Vector3 GetChunkRadius(ChunkCoordinate chunk)
 {
     return(chunk.GetChunkSize(radius * 2) * 0.5f);
 }
        /// <summary>
        /// Returns all physicals that are partially or completely inside this chunk
        /// </summary>
        /// <param name="coord"></param>
        /// <returns></returns>
        public IEnumerable <T> GetWorldObjects(ChunkCoordinate coord)
        {
            var bb = coord.GetBoundingBox(new Vector3(), radius * 2);

            return(getObjects.Where(p => bb.xna().Contains(p.BoundingBox.xna()) != ContainmentType.Disjoint));
        }
 public bool IsLeaf(ChunkCoordinate chunk)
 {
     return(chunk.Depth == maxDepth);
 }
        public Vector3 GetChunkCenter(ChunkCoordinate chunk)
        {
            var bb = chunk.GetBoundingBox(new Vector3(), size);

            return((bb.Minimum + bb.Maximum) * 0.5f);
        }
Exemple #11
0
        public static IEnumerable <ChunkCoordinate> FindChunksDown <T>(this IWorldOctree <T> tree, ChunkCoordinate parent, int maxDepth, Func <ChunkCoordinate, bool> condition) where T : IWorldObject
        {
            if (!condition(parent))
            {
                yield break;
            }

            if (tree.IsLeaf(parent) || parent.Depth == maxDepth)
            {
                yield return(parent);

                yield break;
            }

            foreach (var child in parent.GetChildren())
            {
                foreach (var res in FindChunksDown(tree, child, maxDepth, condition))
                {
                    yield return(res);
                }
            }
        }
 static ChunkCoordinate()
 {
     Root  = new ChunkCoordinate(0, new Point3());
     Empty = new ChunkCoordinate(-1, new Point3());
 }
 public bool Equals(ChunkCoordinate other)
 {
     return(Depth == other.Depth && Position.Equals(other.Position));
 }