Пример #1
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);
                    }
                }
            }
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
0
        public bool RemoveObject(IBoundedObject component)
        {
            lock (ObjectLock)
            {
                Objects.Remove(component);

                if (Tree.ObjectsToNodes.ContainsKey(component) && Tree.ObjectsToNodes[component] == this)
                {
                    Tree.ObjectsToNodes.Remove(component);
                }

                if (CountObjectsRecursive() - 1 < Tree.MinObjectsPerNode && HasChildren())
                {
                    MergeRecursive();
                }
                else if (Parent != null && !HasChildren() && CountObjectsRecursive() < Tree.MinObjectsPerNode)
                {
                    Parent.MergeRecursive();
                }

                return(true);
            }
        }
Пример #4
0
 public void Remove(IBoundedObject obj)
 {
     _objects.Remove(obj);
 }
Пример #5
0
 public void Add(IBoundedObject obj)
 {
     _objects.Add(obj);
 }
Пример #6
0
        private static Rail.RailCombination FindPossibleCombination(Rail.JunctionPiece Piece, IBoundedObject Entity)
        {
            if (Entity is RailPiece)
            {
                var baseJunction        = (Entity as RailPiece).Piece;
                var basePiece           = Rail.RailLibrary.GetRailPiece(baseJunction.RailPiece);
                var relativeOrientation = Rail.OrientationHelper.Relative(baseJunction.Orientation, Piece.Orientation);
                var matchingCombination = basePiece.CombinationTable.FirstOrDefault(c => c.Overlay == Piece.RailPiece && c.OverlayRelativeOrientation == relativeOrientation);
                return(matchingCombination);
            }

            return(null);
        }
Пример #7
0
 public bool RemoveObject(IBoundedObject obj)
 {
     if(!ObjectsToNodes.ContainsKey(obj))
     {
         return false;
     }
     else
     {
         OctreeNode node = ObjectsToNodes[obj];
         return node.RemoveObject(obj);
     }
 }
Пример #8
0
        public bool NeedsUpdate(IBoundedObject component)
        {
            if(ObjectsToUpdate.ContainsKey(component))
            {
                return false;
            }

            return !ObjectsToNodes.ContainsKey(component) || ObjectsToNodes[component].Bounds.Intersects(component.GetBoundingBox());
        }
Пример #9
0
 public void AddUpdate(IBoundedObject obj)
 {
     lock(ObjectsToUpdate)
     {
         ObjectsToUpdate[obj] = true;
     }
 }
Пример #10
0
 public void AddObjectRecursive(IBoundedObject obj)
 {
     if(ObjectsToNodes.ContainsKey(obj))
     {
         return;
     }
     else
     {
         Root.AddObjectRecursive(obj);
     }
 }