/// <summary> /// Tesselates the specified path, notifying the /// <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor">TesselationVisitor</see> /// as each new triangle primitive is added. /// </summary> /// <param name="path">The path to tesselate.</param> /// <param name="visitor">The tesselation visitor to notify.</param> public virtual void Tesselate(GraphicsPath path, TesselationVisitor visitor) { this.visitor = visitor; switch (path.FillMode) { case FillMode.Alternate: //even/odd P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingOdd); break; case FillMode.Winding: //nonzero P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingNonzero); break; } P3Util.GluTessBeginPolygon(tess, IntPtr.Zero); bool isClosed; GraphicsPathIterator pi = new GraphicsPathIterator(path); PointF[] points = path.PathPoints; while (pi.NextSubpath(path, out isClosed) != 0) { byte type; int start, end; while (pi.NextPathType(out type, out start, out end) != 0) { PathPointType ppType = (PathPointType)type; P3Util.GluTessBeginContour(tess); for (int i = start; i <= end; i++) { PointF point = points[i]; double[] coords = new double[3]; coords[0] = point.X; coords[1] = point.Y; coords[2] = 0; GCHandle handle = GCHandle.Alloc(coords, GCHandleType.Pinned); P3Util.GluTessVertex(tess, coords, (IntPtr)handle); handles.Add(handle); } P3Util.GluTessEndContour(tess); } } P3Util.GluTessEndPolygon(tess); ClearHandles(); }
/// <summary> /// Constructs a new Tesselator object. /// </summary> public Tesselator() { tess = P3Util.GluNewTess(); vertexCallback = new P3Util.VertexCallback(TessVertex); beginCallback = new P3Util.BeginCallback(TessBegin); endCallback = new P3Util.EndCallback(TessEnd); errorCallback = new P3Util.ErrorCallback(TessError); combineCallback = new P3Util.CombineCallback(TessCombine); P3Util.GluTessVertexCallBack(tess, P3Util.GlCallbackName.Vertex, vertexCallback); P3Util.GluTessBeginCallBack(tess, P3Util.GlCallbackName.Begin, beginCallback); P3Util.GluTessEndCallBack(tess, P3Util.GlCallbackName.End, endCallback); P3Util.GluTessErrorCallBack(tess, P3Util.GlCallbackName.Error, errorCallback); P3Util.GluTessCombineCallBack(tess, P3Util.GlCallbackName.Combine, combineCallback); P3Util.GluTessNormal(tess, 0f, 0f, -1f); }
/// <summary> /// Notifies the <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor"> /// TesselationVisitor</see> when an error is encountered. /// </summary> /// <param name="error">The type of error that occured.</param> public virtual void TessError(P3Util.GlTessError error) { visitor.TessError(error); }
/// <summary> /// Notifies the <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor"> /// TesselationVisitor</see> of the start of a (triangle) primitive. /// </summary> /// <param name="which">The type of the primitive.</param> public virtual void TessBegin(P3Util.GlPrimitiveType which) { visitor.TessBegin(which); }
/// <summary> /// Disposes the tesselation object. /// </summary> public virtual void Dispose() { P3Util.GluDeleteTess(tess); }
/// <summary> /// Implements <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor.TessError"> /// TesselationVisitor.TessError</see>. /// </summary> public virtual void TessError(P3Util.GlTessError error) { System.Console.Error.WriteLine("Glu tesselation error: " + error); }
/// <summary> /// Implements <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor.TessBegin"> /// TesselationVisitor.TessBegin</see>. /// </summary> public virtual void TessBegin(P3Util.GlPrimitiveType which) { PrimitiveType type = P3Util.GetD3DPrimitiveType(which); this.renderListTypes.Add(new PrimitiveTypeInfo(renderList.Count, renderList.Count-1, currentTesselationColor, type)); }