private void BuildArea(AreaAABB rNewAABB) { for (int i = 0; i < rNewAABB.Sides.Count; i++) { for (int k = 0; k < mCurrentAreas.Count; k++) { this.Intersect_Side_AreaAABB(rNewAABB.Sides[i], mCurrentAreas[k]); } } }
private void BuildAreas() { var rPrevAreas = new List <AreaAABB>(this.mCurrentAreas); this.mCurrentAreas.Clear(); // 找到所有的区域与区域之间线段的交点 for (int i = 0; i < rPrevAreas.Count; i++) { rPrevAreas[i].InitSides(); this.BuildArea(rPrevAreas[i]); mCurrentAreas.Add(rPrevAreas[i]); } // 根据线段的交点找到哪些线是需要隐藏的 for (int i = 1; i < mCurrentAreas.Count; i++) { for (int j = 0; j < i; j++) { for (int k = 0; k < mCurrentAreas[i].Sides.Count; k++) { AreaSide rSide = mCurrentAreas[i].Sides[k]; for (int p = 0; p < rSide.Lines.Count; p++) { if (mCurrentAreas[j].IsContainLine(rSide.Lines[p])) { rSide.Lines[p].State = 1; } } } } } for (int i = 0; i < mCurrentAreas.Count; i++) { // 找Area中的线所在的所有所属区域 for (int j = 0; j < mCurrentAreas[i].Sides.Count; j++) { for (int k = 0; k < mCurrentAreas[i].Sides[j].Lines.Count; k++) { Line rLine = mCurrentAreas[i].Sides[j].Lines[k]; AreaAABB rHighestOrderArea = GetHighestOrderArea(rLine, mCurrentAreas[i]); if (rHighestOrderArea != null) { if (rHighestOrderArea.UID == mCurrentAreas[i].UID) { rLine.State = 1; } } } } } }
public void AddArea(string rAreaID, int nUID, int nOrder, Vector3 rPos, Vector3 rSize) { int nFindIndex = mCurrentAreas.FindIndex((rItem) => { return(rItem.AreaID.Equals(rAreaID)); }); if (nFindIndex >= 0) { return; } var rNewArea = new AreaAABB(rAreaID, nUID, nOrder, rPos, rSize); mCurrentAreas.Add(rNewArea); mCurrentAreas.Sort((rItem1, rItem2) => { return(rItem1.Order.CompareTo(rItem2.Order)); }); this.BuildAreas(); }
/// <summary> /// 判断一个Side是否和一个Area相交,如果相交了,分别把Side和AABB的边裁减成多个线段 /// </summary> public void Intersect_Side_AreaAABB(AreaSide rSide, AreaAABB rArea) { List <Vector3> rTempPoints = new List <Vector3>(rSide.Points); Line rLine = rSide.EdgeLine; for (int j = 0; j < rArea.Sides.Count; j++) { List <Vector3> rTempAreaPoints = new List <Vector3>(rArea.Sides[j].Points); Line rAreaLine = rArea.Sides[j].EdgeLine; this.GetIntersectPoint_AABB(rLine, rAreaLine, rTempPoints, rTempAreaPoints); rArea.Sides[j].Points = rTempAreaPoints; rArea.Sides[j].SortPoints(); } rSide.Points = rTempPoints; rSide.SortPoints(); }
private AreaAABB GetHighestOrderArea(Line rLine, AreaAABB rSelfArea) { AreaAABB rArea = null; for (int i = 0; i < mCurrentAreas.Count; i++) { if (mCurrentAreas[i] == rSelfArea) { continue; } if (mCurrentAreas[i].IsContainLine_NoEdge(rLine)) { if (rArea == null || mCurrentAreas[i].Order < rArea.Order) { rArea = mCurrentAreas[i]; } } } return(rArea); }