예제 #1
0
        public static BarnesHutTree CreateTree(List <Rigidbody> bodies, Vector3 position, int size)
        {
            var tree = new BarnesHutTree(position, size);

            foreach (var body in bodies)
            {
                tree.AddBody(body);
            }
            return(tree);
        }
예제 #2
0
        public BarnesHutTree CreateChildrens()
        {
            var childSize = this.RegionSize / 2f;
            var NWpos     = (this.Position + new Vector3(this.Position.x - childSize, this.Position.y + childSize, 0)) / 2f;
            var NEpos     = (this.Position + new Vector3(this.Position.x + childSize, this.Position.y + childSize, 0)) / 2f;
            var SWpos     = (this.Position + new Vector3(this.Position.x - childSize, this.Position.y - childSize, 0)) / 2f;
            var SEpos     = (this.Position + new Vector3(this.Position.x + childSize, this.Position.y - childSize, 0)) / 2f;

            NW = new BarnesHutTree(NWpos, childSize);
            NE = new BarnesHutTree(NEpos, childSize);
            SW = new BarnesHutTree(SWpos, childSize);
            SE = new BarnesHutTree(SEpos, childSize);
            return(this);
        }