public void InsertVert(Vector2 Vert) { List <CNavEdge> polygon = new List <CNavEdge>(); // Go through all triangles and if this point falls within the circum circle, then remove the triangle, and store a list of edges. for (int i = 0; i < mTris.Count; ++i) { CNavTri t = mTris[i]; if (t.VertInCircumCircle(Vert)) { polygon.Add(t.mEdgeA); polygon.Add(t.mEdgeB); polygon.Add(t.mEdgeC); mTris.RemoveAt(i); --i; } } // Remove internally shared edges. // TODO: Does this have to be n^2? for (int i = 0; i < polygon.Count; ++i) { for (int j = 0; j < polygon.Count; ++j) { if (i == j) { continue; } if (polygon[i] == polygon[j]) { if (i < j) { polygon.RemoveAt(j); polygon.RemoveAt(i); } else { polygon.RemoveAt(i); polygon.RemoveAt(j); } --i; --j; break; } } } // Reconstruct triangles within polygon using new vert as centre. for (int i = 0; i < polygon.Count; ++i) { mTris.Add(new CNavTri(polygon[i].mVertA, polygon[i].mVertB, Vert)); } }
public void DebugDraw() { // How to draw wire of mesh? for (int i = 0; i < mTris.Count; ++i) { Color c = Color.green; CNavTri tri = mTris[i]; CDebug.DrawTri(tri.p1.ToWorldVec3(), tri.p2.ToWorldVec3(), tri.p3.ToWorldVec3(), new Color(c.r, c.g, c.b, 0.3f), false); CDebug.DrawLine(tri.p1.ToWorldVec3(), tri.p2.ToWorldVec3(), c, false); CDebug.DrawLine(tri.p2.ToWorldVec3(), tri.p3.ToWorldVec3(), c, false); CDebug.DrawLine(tri.p3.ToWorldVec3(), tri.p1.ToWorldVec3(), c, false); CDebug.DrawYRectQuad(tri.p1.ToWorldVec3(), 0.1f, 0.1f, Color.white, false); CDebug.DrawYRectQuad(tri.p2.ToWorldVec3(), 0.1f, 0.1f, Color.white, false); CDebug.DrawYRectQuad(tri.p3.ToWorldVec3(), 0.1f, 0.1f, Color.white, false); } }