Esempio n. 1
0
        public bool TestIntersection(GeoAABB2 aabb)
        {
            if (mFlatTreeList == null || mFlatTreeList.Count == 0)
            {
                return(false);
            }
            int closer, other;

            BVHTraversal[] todo = new BVHTraversal[64];
            todo[0] = new BVHTraversal();
            int stackptr = 0;

            todo[stackptr].mIndex  = 0;
            todo[stackptr].mLength = -9999999.0f;
            while (stackptr >= 0)
            {
                int   ni   = todo[stackptr].mIndex;
                float near = todo[stackptr].mLength;
                stackptr--;
                BVHFlatNode2 node = mFlatTreeList[ni];
                // 对叶节点做相交测试
                if (node.mRightOffset == 0)
                {
                    bool hit = false;
                    for (int o = 0; o < node.mLeafCount; ++o)
                    {
                        BVHObject2 obj = mBuildPrims[(int)node.mStartIndex + o];
                        hit = obj.TestAABBIntersect(aabb);
                        if (hit)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    closer = ni + 1;
                    other  = ni + (int)node.mRightOffset;
                    // 对父结点做测试
                    bool hitc0 = GeoAABBUtils.IsAABBInsectAABB2(aabb.mMin, aabb.mMax, mFlatTreeList[closer].mBox.mMin, mFlatTreeList[closer].mBox.mMax);
                    bool hitc1 = GeoAABBUtils.IsAABBInsectAABB2(aabb.mMin, aabb.mMax, mFlatTreeList[other].mBox.mMin, mFlatTreeList[other].mBox.mMax);
                    if (hitc0 && hitc1)
                    {
                        todo[++stackptr] = new BVHTraversal(other, -9999);
                        todo[++stackptr] = new BVHTraversal(closer, -9999);
                    }
                    else if (hitc0)
                    {
                        todo[++stackptr] = new BVHTraversal(closer, -9999);
                    }
                    else if (hitc1)
                    {
                        todo[++stackptr] = new BVHTraversal(other, -9999);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
 private bool IsIntersectOtherAABB(Vector2 v, Vector2 vm)
 {
     foreach (GeoAABB2 aabb in mLeftRectangle)
     {
         if (GeoAABBUtils.IsAABBInsectAABB2(v, vm, aabb.mMin, aabb.mMax))
         {
             return(true);
         }
     }
     return(mBvh.TestIntersection(new GeoAABB2(v, vm)));
 }
Esempio n. 3
0
 public bool TestAABBIntersect(GeoAABB2 aabb)
 {
     return(GeoAABBUtils.IsAABBInsectAABB2(aabb.mMin, aabb.mMax, mAABB2.mMin, mAABB2.mMax));
 }