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); } } } }
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); } } } }
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); } }
public void Remove(IBoundedObject obj) { _objects.Remove(obj); }
public void Add(IBoundedObject obj) { _objects.Add(obj); }
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); }
public bool RemoveObject(IBoundedObject obj) { if(!ObjectsToNodes.ContainsKey(obj)) { return false; } else { OctreeNode node = ObjectsToNodes[obj]; return node.RemoveObject(obj); } }
public bool NeedsUpdate(IBoundedObject component) { if(ObjectsToUpdate.ContainsKey(component)) { return false; } return !ObjectsToNodes.ContainsKey(component) || ObjectsToNodes[component].Bounds.Intersects(component.GetBoundingBox()); }
public void AddUpdate(IBoundedObject obj) { lock(ObjectsToUpdate) { ObjectsToUpdate[obj] = true; } }
public void AddObjectRecursive(IBoundedObject obj) { if(ObjectsToNodes.ContainsKey(obj)) { return; } else { Root.AddObjectRecursive(obj); } }