public static void Split2d(Convex convex, Point3D point0, int edge0, Point3D point1, int edge1, ref Convex newcvxa, ref Convex newcvxb) { newcvxa = new Convex(); newcvxb = new Convex(); Face facea = new Face(newcvxa); Face faceb = new Face(newcvxb); newcvxa.Faces.Add(facea); newcvxb.Faces.Add(faceb); int edgecount = convex.Edges.Count; List <int> usedindicesa = new List <int>(); List <int> usedindicesb = new List <int>(); newcvxa.Vertices.Add(new Vertex(newcvxa, point0)); for (int i = edge0; i != edge1; i = (i + 1) % edgecount) { usedindicesa.Add(convex.Edges[i].VertIndices[1]); newcvxa.Vertices.Add(new Vertex(newcvxa, convex.GetEdgeVert(i, 1))); } newcvxa.Vertices.Add(new Vertex(newcvxa, point1)); newcvxb.Vertices.Add(new Vertex(newcvxb, point1)); for (int i = edge1; i != edge0; i = (i + 1) % edgecount) { usedindicesb.Add(convex.Edges[i].VertIndices[1]); newcvxb.Vertices.Add(new Vertex(newcvxb, convex.GetEdgeVert(i, 1))); } newcvxb.Vertices.Add(new Vertex(newcvxb, point0)); facea.VertIndices = new int[newcvxa.Vertices.Count]; faceb.VertIndices = new int[newcvxb.Vertices.Count]; for (int i = 0; i < facea.VertIndices.Length; i++) { facea.VertIndices[i] = i; } for (int i = 0; i < faceb.VertIndices.Length; i++) { faceb.VertIndices[i] = i; } newcvxa.BuildFromVertsAndFaces(); newcvxb.BuildFromVertsAndFaces(); }
public override void Create() { Convex cvx = new Convex(); cvx.Is3d = false; cvx.Vertices.Add(new Vertex(cvx, -Size.X * 0.5, -Size.Y * 0.5)); cvx.Vertices.Add(new Vertex(cvx, -Size.X * 0.5, Size.Y * 0.5)); cvx.Vertices.Add(new Vertex(cvx, Size.X * 0.5, Size.Y * 0.5)); cvx.Vertices.Add(new Vertex(cvx, Size.X * 0.5, -Size.Y * 0.5)); cvx.Faces.Add(new Face(cvx, 0, 1, 2, 3)); cvx.BuildFromVertsAndFaces(); Convexes.Add(cvx); }
public static void Split2d(Convex convex, Point3D point0, int edge0, Point3D point1, int edge1, ref Convex newcvxa, ref Convex newcvxb) { newcvxa = new Convex(); newcvxb = new Convex(); Face facea = new Face(newcvxa); Face faceb = new Face(newcvxb); newcvxa.Faces.Add(facea); newcvxb.Faces.Add(faceb); int edgecount = convex.Edges.Count; List<int> usedindicesa = new List<int>(); List<int> usedindicesb = new List<int>(); newcvxa.Vertices.Add(new Vertex(newcvxa,point0)); for (int i = edge0; i != edge1; i = (i + 1) % edgecount) { usedindicesa.Add(convex.Edges[i].VertIndices[1]); newcvxa.Vertices.Add(new Vertex(newcvxa,convex.GetEdgeVert(i, 1))); } newcvxa.Vertices.Add(new Vertex(newcvxa,point1)); newcvxb.Vertices.Add(new Vertex(newcvxb,point1)); for (int i = edge1; i != edge0; i = (i + 1) % edgecount) { usedindicesb.Add(convex.Edges[i].VertIndices[1]); newcvxb.Vertices.Add(new Vertex(newcvxb,convex.GetEdgeVert(i, 1))); } newcvxb.Vertices.Add(new Vertex(newcvxb,point0)); facea.VertIndices = new int[newcvxa.Vertices.Count]; faceb.VertIndices = new int[newcvxb.Vertices.Count]; for (int i = 0; i < facea.VertIndices.Length; i++) facea.VertIndices[i] = i; for (int i = 0; i < faceb.VertIndices.Length; i++) faceb.VertIndices[i] = i; newcvxa.BuildFromVertsAndFaces(); newcvxb.BuildFromVertsAndFaces(); }