Пример #1
0
        public bool NeedsUpdateRecursive(IBoundedObject component)
        {
            lock (ObjectLock)
            {
                if (Objects.Contains(component))
                {
                    return(!component.GetBoundingBox().Intersects(Bounds));
                }
                else if (HasChildren())
                {
                    bool shouldUpdate = false;
                    for (int i = 0; i < 8; i++)
                    {
                        OctreeNode node = Children[i];
                        if (node == null)
                        {
                            continue;
                        }

                        if (node.NeedsUpdateRecursive(component))
                        {
                            shouldUpdate = true;
                        }
                    }


                    return(shouldUpdate);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #2
0
        public void AddObject(IBoundedObject bounded, CollisionType type)
        {
            if (type == CollisionType.None)
            {
                return;
            }

            Hashes[type].AddItem(bounded, bounded.GetBoundingBox());
        }
Пример #3
0
        public void AddObjectRecursive(IBoundedObject component)
        {
            if (Parent == null && !component.GetBoundingBox().Intersects(Bounds))
            {
                Tree.ExpandAndRebuild();
                return;
            }

            if (component.GetBoundingBox().Intersects(Bounds) && !HasChildren())
            {
                lock (ObjectLock)
                {
                    if (!Objects.Contains(component))
                    {
                        Objects.Add(component);
                    }

                    Tree.ObjectsToNodes[component] = this;

                    if (Objects.Count > Tree.MaxObjectsPerNode && Depth < Tree.MaxDepth)
                    {
                        Split();
                    }
                }
            }

            else
            {
                for (int i = 0; i < 8; i++)
                {
                    OctreeNode node = Children[i];
                    if (node != null)
                    {
                        node.AddObjectRecursive(component);
                    }
                }
            }
        }
Пример #4
0
        public void AddObject(IBoundedObject bounded, CollisionType type)
        {
            if (type == CollisionType.None)
            {
                return;
            }
            BoundingBox box      = bounded.GetBoundingBox();
            Point3      minPoint = new Point3(MathFunctions.FloorInt(box.Min.X), MathFunctions.FloorInt(box.Min.Y), MathFunctions.FloorInt(box.Min.Z));
            Point3      maxPoint = new Point3(MathFunctions.FloorInt(box.Max.X), MathFunctions.FloorInt(box.Max.Y), MathFunctions.FloorInt(box.Max.Z));
            Point3      iter     = new Point3();

            for (iter.X = minPoint.X; iter.X <= maxPoint.X; iter.X++)
            {
                for (iter.Y = minPoint.Y; iter.Y <= maxPoint.Y; iter.Y++)
                {
                    for (iter.Z = minPoint.Z; iter.Z <= maxPoint.Z; iter.Z++)
                    {
                        Hashes[type].AddItem(iter, bounded);
                    }
                }
            }
        }
Пример #5
0
        public bool NeedsUpdate(IBoundedObject component)
        {
            if (ObjectsToUpdate.ContainsKey(component))
            {
                return(false);
            }

            return(!ObjectsToNodes.ContainsKey(component) || ObjectsToNodes[component].Bounds.Intersects(component.GetBoundingBox()));
        }
Пример #6
0
        public bool NeedsUpdate(IBoundedObject component)
        {
            if(ObjectsToUpdate.ContainsKey(component))
            {
                return false;
            }

            return !ObjectsToNodes.ContainsKey(component) || ObjectsToNodes[component].Bounds.Intersects(component.GetBoundingBox());
        }