public static unsafe List <int> TesselateSimplePoly(List <Vector3d> inputList) { TriangleListOut.Clear(); VertexList = inputList; //// fill the polygon //VertexList.Add(new Vector3d(0,0,0)); //VertexList.Add(new Vector3d(20,0,0)); //VertexList.Add(new Vector3d(0,20,0)); //VertexList.Add(new Vector3d(20,20,0)); IntPtr tess = gluNewTess(); if (tess == null) { return(null); } // register the callbacks BeginDataEvent = new TessCallback(BeginData); EdgeFlagEvent = new TessCallback(EdgeFlag); VertexEvent = new TessCallback(Vertex); EndDataEvent = new TessEndData(EndData); CombineEvent = new TessCombine(Combine); ErrorEvent = new TessCallback(GLU_ErrorEvent); gluTessCallback(tess, GLU_TESS_BEGIN_DATA, BeginDataEvent); gluTessCallback(tess, GLU_TESS_EDGE_FLAG_DATA, EdgeFlagEvent); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, VertexEvent); gluTessCallback(tess, GLU_TESS_END_DATA, EndDataEvent); gluTessCallback(tess, GLU_TESS_COMBINE_DATA, CombineEvent); gluTessBeginPolygon(tess, IntPtr.Zero); gluTessBeginContour(tess); for (int i = 0; i < VertexList.Count; i++) { Vector3d v = VertexList[i]; gluTessVertex(tess, new double[] { v.X, v.Y, v.Z }, i); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); return(TriangleListOut); }
public static unsafe List<int> TesselateSimplePoly(List<Vector3d> inputList) { TriangleListOut.Clear(); VertexList = inputList; //// fill the polygon //VertexList.Add(new Vector3d(0,0,0)); //VertexList.Add(new Vector3d(20,0,0)); //VertexList.Add(new Vector3d(0,20,0)); //VertexList.Add(new Vector3d(20,20,0)); IntPtr tess = gluNewTess(); if (tess == null) { return null; } // register the callbacks BeginDataEvent = new TessCallback(BeginData); EdgeFlagEvent = new TessCallback(EdgeFlag); VertexEvent = new TessCallback(Vertex); EndDataEvent = new TessEndData(EndData); CombineEvent = new TessCombine(Combine); ErrorEvent = new TessCallback(GLU_ErrorEvent); gluTessCallback(tess, GLU_TESS_BEGIN_DATA, BeginDataEvent); gluTessCallback(tess, GLU_TESS_EDGE_FLAG_DATA, EdgeFlagEvent); gluTessCallback(tess, GLU_TESS_VERTEX_DATA, VertexEvent); gluTessCallback(tess, GLU_TESS_END_DATA, EndDataEvent); gluTessCallback(tess, GLU_TESS_COMBINE_DATA, CombineEvent); gluTessBeginPolygon(tess, IntPtr.Zero); gluTessBeginContour(tess); for (int i = 0; i < VertexList.Count; i++) { Vector3d v = VertexList[i]; gluTessVertex(tess, new double[] { v.X, v.Y, v.Z }, i); } gluTessEndContour(tess); gluTessEndPolygon(tess); gluDeleteTess(tess); return TriangleListOut; }