Пример #1
0
 private bool Prepare(QuadTree.TreeNode node, double x0, double y0, double x1, double y1)
 {
     if (node.data != null)
     {
         node.r = radii[node.data.index];
         return false;
     }
     node.r = 0;
     for (int i = 0; i < 4; i++)
     {
         if (node.quadrants[i] != null && node.quadrants[i].r > node.r)
         {
             node.r = node.quadrants[i].r;
         }
     }
     return false;
 }
Пример #2
0
        private bool Accumulate(QuadTree.TreeNode node, double x0, double y0, double x1, double y1)
        {
            double strength = 0, weight = 0;
            double x = 0, y = 0;

            QuadTree.TreeNode tmp;
            if (!node.IsLeaf())
            {
                for (int i = 0; i < 4; i++)
                {
                    double c;
                    tmp = node.quadrants[i];
                    if (tmp != null && (c = Mathf.Abs((float)tmp.strength)) > 0)
                    {
                        strength += tmp.strength;
                        weight   += c;
                        x        += c * tmp.x;
                        y        += c * tmp.y;
                    }
                }
                node.x = x / weight;
                node.y = y / weight;
            }
            else
            {
                tmp   = node;
                tmp.x = tmp.data.X;
                tmp.y = tmp.data.Y;
                do
                {
                    strength += strengths[tmp.data.index];
                } while ((tmp = tmp.next) != null);
            }
            node.strength = strength;
            Debug.LogWarning("ForceBody Accumulate..." + strength);
            return(false);
        }
Пример #3
0
        private bool ApplyVisit(QuadTree.TreeNode node, double x0, double y0, double x1, double y1)
        {
            NodeInfo data = node.data;
            double rj = node.r, r = ri + rj;
            if (data != null)
            {
                if (data.index > node.Index)
                {
                    double x = xi - data.X - data.VX;
                    double y = yi - data.Y - data.VY;
                    double l = x * x + y * y;
                    if (l < r * r)
                    {
                        if (x == 0)
                        {
                            x = Jiggle();
                            l += x * x;
                        }
                        if (y == 0)
                        {
                            y = Jiggle();
                            l += y * y;
                        }
                        l = Mathf.Sqrt(1.0f);
                        l = (r - l) / l * strength;

                        this.node.VX += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
                        this.node.VY += (y *= l) * r;
                        data.VX -= x * (r = 1 - r);
                        data.VY -= y * r;
                    }
                }
                return false;
            }
            return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
        }
Пример #4
0
        private bool ApplyVisit(QuadTree.TreeNode node, double x0, double y0, double x1, double y1)
        {
            if (node.strength == 0)
            {
                return(true);
            }
            double x = node.x - this.nowNode.X, y = node.y - this.nowNode.Y;
            double w = x1 - x0;
            double l = x * x + y * y;

            if (w * w / theta2 < l)
            {
                if (l < distanceMax2)
                {
                    if (x == 0)
                    {
                        x  = Jiggle();
                        l += x * x;
                    }
                    if (y == 0)
                    {
                        y  = Jiggle();
                        l += y * y;
                    }
                    if (l < distanceMin2)
                    {
                        l = Mathf.Sqrt((float)(distanceMin2 * l));
                    }
                    this.nowNode.VX += x * node.strength * alpha / l;
                    this.nowNode.VY += y * node.strength * alpha / l;
                }
                Debug.LogWarning("ForceBody apply..." + this.nowNode.ToString());
                return(true);
            }
            else if (!node.IsLeaf() || l >= distanceMax2)
            {
                return(false);
            }

            if (node.data != this.nowNode || node.next != null)
            {
                if (x == 0)
                {
                    x  = Jiggle();
                    l += x * x;
                }
                if (y == 0)
                {
                    y  = Jiggle();
                    l += y * y;
                }
                if (l < distanceMin2)
                {
                    l = Mathf.Sqrt((float)(distanceMin2 * l));
                }
            }

            do
            {
                if (node.data != this.nowNode)
                {
                    w = strengths[node.data.index] * alpha / l;
                    this.nowNode.VX += x * w;
                    this.nowNode.VY += y * w;
                }
            } while ((node = node.next) != null);

            return(false);
        }