예제 #1
0
 public OCTree(int maxObjectPerNode, Vector3 center, Vector3 extents)
 {
     Root = new Node(this, null, center, extents, 0);
     Root.Divide();
     
     MaxObjectsPerNode = maxObjectPerNode;
 }
예제 #2
0
 internal Node(OCTree tree, Node parent, Vector3 center, Vector3 extents, int level)
 {
     Tree = tree;
     Center = center;
     Extents = extents;
     Objects = new List<Collidable>();
     Box = new BoundingBox(center - extents, center + extents);
     Level = level;
     Parent = parent;
 }
예제 #3
0
        internal void Remove()
        {
            if (Node == null)
                return;

            Node.Objects.Remove(this);

            while (Node != null)
            {
                Node.Count -= 1;
                Node = Node.Parent;
            }
        }
예제 #4
0
 public void Clear()
 {
     Root = new Node(this, null, Root.Center, Root.Extents, 0);
     Root.Divide();
 }
예제 #5
0
        internal void Divide()
        {
            var x2 = Extents.X / 2;
            var y2 = Extents.Y / 2;
            var z2 = Extents.Z / 2;

            var extents = new Vector3(x2, y2, z2);
            var right = Center.X + x2;
            var left = Center.X - x2;
            var top = Center.Y + y2;
            var bottom = Center.Y - y2;
            var front = Center.Z + z2;
            var back = Center.Z - z2;

            var l = Level+1;

            Children = new Node[8];
            Children[LEFT_TOP_FRONT] = new Node(Tree, this, new Vector3(left, top, front), extents, l);
            Children[RIGHT_TOP_FRONT] = new Node(Tree, this, new Vector3(right, top, front), extents, l);
            Children[LEFT_TOP_BACK] = new Node(Tree, this, new Vector3(left, top, back), extents, l);
            Children[RIGHT_TOP_BACK] = new Node(Tree, this, new Vector3(right, top, back), extents, l);
            Children[LEFT_BOTTOM_FRONT] = new Node(Tree, this, new Vector3(left, bottom, front), extents, l);
            Children[RIGHT_BOTTOM_FRONT] = new Node(Tree, this, new Vector3(right, bottom, front), extents, l);
            Children[LEFT_BOTTOM_BACK] = new Node(Tree, this, new Vector3(left, bottom, back), extents, l);
            Children[RIGHT_BOTTOM_BACK] = new Node(Tree, this, new Vector3(right, bottom, back), extents, l);
        }