public BVHAABB2Object(Vector2 min, Vector2 max) : base(GeoShape.GeoAABB2) { mAABB2 = new GeoAABB2(min, max); mCenter = (min + max) * 0.5f; mExtent = max - min; }
public BVHSegment2Object(Vector2 p1, Vector2 p2) : base(GeoShape.GeoSegment2) { mSeg = new GeoSegment2(p1, p2); mCenter = (p1 + p2) * 0.5f; mAABB = new GeoAABB2(Vector2.Min(p1, p2), Vector2.Max(p1, p2)); }
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 BVHTriangle2Object(Vector2 p1, Vector2 p2, Vector2 p3) : base(GeoShape.GeoTriangle2) { mP1 = p1; mP2 = p2; mP3 = p3; mCenter = (mP1 + mP2 + mP3) * 0.333333f; mAABB = new GeoAABB2(Vector2.Min(Vector2.Min(mP1, mP2), mP3), Vector2.Max(Vector2.Max(mP1, mP2), mP3)); }
public static void DrawAABB(GeoAABB2 aabb, Color clr) { Vector2 min = aabb.mMin; Vector2 max = aabb.mMax; Vector2 p2 = new Vector2(max[0], min[1]); Vector2 p4 = new Vector2(min[0], max[1]); Debug.DrawLine(min, p2, clr); Debug.DrawLine(max, p2, clr); Debug.DrawLine(max, p4, clr); Debug.DrawLine(min, p4, clr); }
public static GeoAABB2 GetAABB(List <Vector2> points) { GeoAABB2 aabb = new GeoAABB2(); if (points.Count > 0) { aabb.mMin = points[0]; aabb.mMax = points[0]; for (int i = 1; i < points.Count; ++i) { aabb.mMax = Vector2.Max(aabb.mMax, points[i]); aabb.mMin = Vector2.Min(aabb.mMin, points[i]); } aabb.mSize = aabb.mMax - aabb.mMin; } return(aabb); }
public virtual bool TestAABBIntersect(GeoAABB2 aabb) { return(false); }
public bool TestAABBIntersect(GeoAABB2 aabb) { return(GeoAABBUtils.IsAABBInsectAABB2(aabb.mMin, aabb.mMax, mAABB2.mMin, mAABB2.mMax)); }
public void ExpandToInclude(GeoAABB2 b) { mMin = Vector2.Min(mMin, b.mMin); mMax = Vector2.Max(mMax, b.mMax); mExtent = mMax - mMin; }
public bool TestAABBIntersect(GeoAABB2 aabb) { GeoInsectPointArrayInfo insect = new GeoInsectPointArrayInfo(); return(GeoSegmentUtils.IsSegmentInsectAABB2(mSeg.mP1, mSeg.mP2, aabb.mMin, aabb.mMax, ref insect)); }