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; 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); }
public static bool IsAABBInsectCircle3(Vector3 min, Vector3 max, GeoPlane plane1, Vector3 center, float r, GeoPlane plane2, ref GeoInsectPointArrayInfo insect) { float dot = Vector3.Dot(plane1.mNormal, plane2.mNormal); if (1 - Mathf.Abs(dot) < 1e-5f) { if (GeoPlaneUtils.IsPointOnPlane(plane2.mNormal, plane2.mD, min)) { return(IsAABBInsectCirclePlane2(min, max, center, r, plane1, ref insect)); // should use plane1 } return(false); } GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = GeoPlaneUtils.IsPlaneInsectCircle(plane1.mNormal, plane1.mD, center, r, plane2, ref tmp); if (isInsect) { if (tmp.mHitGlobalPoint.mPointArray.Count == 1) { Vector3 line1 = tmp.mHitGlobalPoint.mPointArray[0]; if (GeoAABBUtils.IsPointInAABB2Plane(min, max, plane1, ref line1)) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(line1); return(true); } } else { Vector3 seg1 = tmp.mHitGlobalPoint.mPointArray[0]; Vector3 seg2 = seg1 + tmp.mHitGlobalPoint.mPointArray[1]; return(GeoSegmentUtils.IsSegmentInsectAABB2Plane(seg1, seg2, min, max, plane1, ref insect)); } } return(false); }
public bool TestAABBIntersect(GeoAABB2 aabb) { return(GeoAABBUtils.IsAABBInsectAABB2(aabb.mMin, aabb.mMax, mAABB2.mMin, mAABB2.mMax)); }
public static bool IsTriangleInsectAABB3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 min, Vector2 max, ref GeoInsectPointArrayInfo insect) { return(GeoAABBUtils.IsAABBInsectTriangle3(min, max, p1, p2, p3, ref insect)); }