Ejemplo n.º 1
0
        public override void IntersectBF(BoundingSphere ball, List <DirectDetectData> res)
        {
            Queue <BBTreeNode> q = new Queue <BBTreeNode>();

            q.Enqueue(this);
            while (q.Count > 0)
            {
                BBTreeNode node = q.Dequeue();
                if (MathEx.BoundingSphereIntersects(ref ball, ref node.ball))// ball.Intersect(ref node.bBall.vCentre, ref node.bBall.dRange))
                {
                    if (node.children != null)
                    {
                        for (int i = 0; i < node.children.Length; i++)
                        {
                            q.Enqueue((BBTreeNode)node.children[i]);
                        }
                    }
                    else
                    {
                        DirectDetectData data;
                        Triangle         face = (Triangle)node.faceData;
                        //if (ball.Intersect(ref face, out data.vPos, out data.vNormal, out data.dDepth))
                        if (MathEx.BoundingSphereIntersects(ref ball, ref face, out data.Position, out data.Normal, out data.Depth))
                        {
                            res.Add(data);
                        }
                    }
                }
            }
            q.Clear();
        }
Ejemplo n.º 2
0
        //[Obsolete()]
        public override void IntersectBF(BBTreeNode cdTree, List <DirectDetectData> res)
        {
            Queue <AABBTreeNode> a = new Queue <AABBTreeNode>();
            Queue <BBTreeNode>   b = new Queue <BBTreeNode>();

            a.Enqueue(this);
            b.Enqueue(cdTree);

            while (a.Count > 0)
            {
                AABBTreeNode nodea = a.Dequeue();
                //AABBTreeNode nodeb = b.Dequeue();

                // a/b anainst each b/a , if overlaps add a/b
                // a or b depends on Queue.Count
            }

            throw new Exception("The method or operation is not implemented.");
        }
Ejemplo n.º 3
0
 public override void IntersectDF(BBTreeNode cdTree, List <DirectDetectData> res)
 {
     //if (aAABB.Intersect(cdTree.bBall.vCentre, cdTree.bBall.dRange))
     if (children != null)
     {
         for (int i = 0; i < children.Length; i++)
         {
             AABBTreeNode ch = (AABBTreeNode)children[i];
             if (MathEx.BoundingSphereIntersects(ref cdTree.ball, ref ch.aabb)) //(cdTree.bBall.Intersect(ref ch.aAABB))
             {
                 cdTree.IntersectDF(ch, res);                                   //相互遍历
             }
         }
     }
     else
     {
         Triangle t = (Triangle)faceData;
         cdTree.IntersectDF(ref t, res);
     }
 }
Ejemplo n.º 4
0
 public override void IntersectDF(BBTreeNode cdTree, List <DirectDetectData> res)
 {
     //if ((cdTree.bBall.vCentre ^ bBall.vCentre) <= r * r)
     if (children != null)
     {
         for (int i = 0; i < children.Length; i++)
         {
             BBTreeNode ch = (BBTreeNode)children[i];
             float      r  = (cdTree.ball.Radius + ch.ball.Radius);
             if (MathEx.DistanceSquared(ref cdTree.ball.Center, ref ch.ball.Center) <= r * r)
             {
                 cdTree.IntersectDF(ch, res); //相互遍历
             }
         }
     }
     else
     {
         // 有一个到了根节点
         // 那就就让另一个直接到根节点判断,就是
         Triangle t = (Triangle)faceData;
         cdTree.IntersectDF(ref t, res);
     }
 }
Ejemplo n.º 5
0
        public BBTreeNode(List <TreeFace> remains)
        {
            int i;
            int rcount = remains.Count;

            for (i = 0; i < rcount; i++)
            {
                ball.Center += remains[i].centre;
            }
            //for (i = 0; i < rcount; i++)
            //    bBall.vCentre += remains[i].vA;

            ball.Center *= (1f / (float)i);// /= (float)i;

            ball.Radius = 0;
            for (i = 0; i < rcount; i++)
            {
                float dist = MathEx.Distance(ref ball.Center, ref remains[i].a); // bBall.vCentre & remains[i].vA;
                if (dist > ball.Radius)
                {
                    ball.Radius = dist;
                }

                dist = MathEx.Distance(ref ball.Center, ref remains[i].b); // bBall.vCentre & remains[i].vB;
                if (dist > ball.Radius)
                {
                    ball.Radius = dist;
                }

                dist = MathEx.Distance(ref ball.Center, ref remains[i].c); // bBall.vCentre & remains[i].vC;
                if (dist > ball.Radius)
                {
                    ball.Radius = dist;
                }
            }

            if (rcount > 1)
            {
                float xoy = ball.Center.Z;
                float yoz = ball.Center.X;
                float xoz = ball.Center.Y;


                List <TreeFace>[] lim = new List <TreeFace>[8]
                {
                    new List <TreeFace>(), new List <TreeFace>(),
                    new List <TreeFace>(), new List <TreeFace>(),
                    new List <TreeFace>(), new List <TreeFace>(),
                    new List <TreeFace>(), new List <TreeFace>()
                };


                for (i = 0; i < rcount; i++)
                {
                    float fxy = remains[i].centre.Z - xoy; // xoy[remains[i].mCentre];
                    float fyz = remains[i].centre.X - yoz; //yoz[remains[i].mCentre];
                    float fxz = remains[i].centre.Y - xoz; //xoz[remains[i].mCentre];

                    if (fxz > 0)                           // y>0
                    //1-4卦限
                    {
                        if (fyz > 0)     // x>0
                        {
                            if (fxy > 0) // z>0
                            {
                                lim[0].Add(remains[i]);
                            }
                            else
                            {
                                lim[3].Add(remains[i]);
                            }
                        }
                        else
                        if (fxy > 0)     // z>0
                        {
                            lim[1].Add(remains[i]);
                        }
                        else
                        {
                            lim[2].Add(remains[i]);
                        }
                    }
                    else

                    //5-8卦限
                    if (fyz > 0)     // x>0
                    {
                        if (fxy > 0) // z>0
                        {
                            lim[4].Add(remains[i]);
                        }
                        else
                        {
                            lim[7].Add(remains[i]);
                        }
                    }

                    else
                    if (fxy > 0)         // z>0
                    {
                        lim[5].Add(remains[i]);
                    }
                    else
                    {
                        lim[6].Add(remains[i]);
                    }
                }
                //remains.Clear();

                int    childrenUBound = -1;
                bool[] usestat        = new bool[8];
                for (i = 0; i < 8; i++)
                {
                    if (lim[i].Count > 0)
                    {
                        childrenUBound++;
                        usestat[i] = true;
                    }
                    else
                    {
                        usestat[i] = false;
                    }
                }


                children = new BaseTreeNode[childrenUBound + 1];

                int k = 0;
                for (i = 0; i < 8; i++)
                {
                    if (usestat[i])
                    {
                        children[k] = new BBTreeNode(lim[i]);
                        k++;
                    }
                }
            }
            else
            {
                //childrenUBound = -1;
                faceData = remains[0];
                remains.Clear();
            }
        }
Ejemplo n.º 6
0
 //[Obsolete()]
 public override void IntersectBF(BBTreeNode cdTree, List <DirectDetectData> res)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Ejemplo n.º 7
0
 public abstract void IntersectBF(BBTreeNode cdTree, List <DirectDetectData> res);