public static void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, Vector2 offset, double scale, RGBA_Bytes silhouetteColor) { graphics2D.Rasterizer.gamma(new gamma_power(.3)); PathStorage polygonProjected = new PathStorage(); foreach (Face face in meshToDraw.Faces) { if (face.normal.z > 0) { polygonProjected.remove_all(); bool first = true; foreach (FaceEdge faceEdge in face.FaceEdges()) { Vector2 position = new Vector2(faceEdge.firstVertex.Position.x, faceEdge.firstVertex.Position.y); position += offset; position *= scale; if (first) { polygonProjected.MoveTo(position.x, position.y); first = false; } else { polygonProjected.LineTo(position.x, position.y); } } graphics2D.Render(polygonProjected, silhouetteColor); } } graphics2D.Rasterizer.gamma(new gamma_none()); }
public static void Load(PathStorage vertexSource, string pathAndFileName) { vertexSource.remove_all(); string[] allLines = File.ReadAllLines(pathAndFileName); foreach (string line in allLines) { string[] elements = line.Split(','); double x = double.Parse(elements[0]); double y = double.Parse(elements[1]); ShapePath.FlagsAndCommand flagsAndCommand = (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[2].Trim()); for (int i = 3; i < elements.Length; i++) { flagsAndCommand |= (ShapePath.FlagsAndCommand)System.Enum.Parse(typeof(ShapePath.FlagsAndCommand), elements[i].Trim()); } vertexSource.Add(x, y, flagsAndCommand); } }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value); IRecieveBlenderByte NormalBlender = new BlenderBGRA(); IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma); ImageBuffer rasterGamma = new ImageBuffer(); rasterGamma.Attach(widgetsSubImage, GammaBlender); ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage); ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma); clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1)); ScanlineRasterizer rasterizer = new ScanlineRasterizer(); scanline_unpacked_8 sl = new scanline_unpacked_8(); int size_mul = (int)pixelSizeSlider.Value; renderer_enlarged ren_en = new renderer_enlarged(size_mul); rasterizer.reset(); rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul); ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black); rasterizer.gamma(new gamma_none()); PathStorage ps = new PathStorage(); Stroke pg = new Stroke(ps); pg.width(2); ps.remove_all(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); rasterizer.add_path(pg); scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new RGBA_Bytes(0, 150, 160, 200)); base.OnDraw(graphics2D); }
private void make_arrows(PathStorage ps) { ps.remove_all(); ps.MoveTo(1330.599999999999909, 1282.399999999999864); ps.LineTo(1377.400000000000091, 1282.399999999999864); ps.LineTo(1361.799999999999955, 1298.000000000000000); ps.LineTo(1393.000000000000000, 1313.599999999999909); ps.LineTo(1361.799999999999955, 1344.799999999999955); ps.LineTo(1346.200000000000045, 1313.599999999999909); ps.LineTo(1330.599999999999909, 1329.200000000000045); ps.ClosePolygon(); ps.MoveTo(1330.599999999999909, 1266.799999999999955); ps.LineTo(1377.400000000000091, 1266.799999999999955); ps.LineTo(1361.799999999999955, 1251.200000000000045); ps.LineTo(1393.000000000000000, 1235.599999999999909); ps.LineTo(1361.799999999999955, 1204.399999999999864); ps.LineTo(1346.200000000000045, 1235.599999999999909); ps.LineTo(1330.599999999999909, 1220.000000000000000); ps.ClosePolygon(); ps.MoveTo(1315.000000000000000, 1282.399999999999864); ps.LineTo(1315.000000000000000, 1329.200000000000045); ps.LineTo(1299.400000000000091, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1344.799999999999955); ps.LineTo(1252.599999999999909, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1298.000000000000000); ps.LineTo(1268.200000000000045, 1282.399999999999864); ps.ClosePolygon(); ps.MoveTo(1268.200000000000045, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1220.000000000000000); ps.LineTo(1299.400000000000091, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1204.399999999999864); ps.LineTo(1252.599999999999909, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1251.200000000000045); ps.ClosePolygon(); }
public void Line(double x1, double y1, double x2, double y2, RGBA_Bytes color, double strokeWidth = 1) { PathStorage m_LinesToDraw = new PathStorage(); m_LinesToDraw.remove_all(); m_LinesToDraw.MoveTo(x1, y1); m_LinesToDraw.LineTo(x2, y2); Stroke StrockedLineToDraw = new Stroke(m_LinesToDraw, strokeWidth); Render(StrockedLineToDraw, color); }
//直线 public UIGraphic AddLine(float x1, float y1, float x2, float y2, CCColor4B stroke, double strokeThickness = 1) { if (stroke.A > 0) { //g.Line没有厚度 PathStorage linesToDraw = new PathStorage(); linesToDraw.remove_all(); linesToDraw.MoveTo(x1, y1); linesToDraw.LineTo(x2, y2); Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness); this.graphics2D.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } return this; }
public static CCSprite CreateLine( int width, int height, CCColor4B stroke, double strokeThickness = 1 ) { ImageBuffer buffer = new ImageBuffer(width, height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); if (stroke.A > 0) { //g.Line没有厚度 PathStorage linesToDraw = new PathStorage(); linesToDraw.remove_all(); linesToDraw.MoveTo(0, 0); linesToDraw.LineTo(width, height); Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness); g.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
public static void Make(PathStorage ps) { ps.remove_all(); ps.MoveTo(poly1[0], poly1[1]); for (int i = 1; i < poly1.Length / 2; i++) { ps.LineTo(poly1[i * 2 + 0], poly1[i * 2 + 1]); } ps.ClosePolygon(); ps.MoveTo(poly2[0], poly2[1]); for (int i = 1; i < poly2.Length / 2; i++) { ps.LineTo(poly2[i * 2 + 0], poly2[i * 2 + 1]); } ps.ClosePolygon(); }
public void DrawSegments(Graphics2D graphics2D) { foreach (LineSegment lineSegment in LineSegments) { PathStorage m_LinesToDraw = new PathStorage(); m_LinesToDraw.remove_all(); m_LinesToDraw.MoveTo(lineSegment.start.x, lineSegment.start.y); m_LinesToDraw.LineTo(lineSegment.end.x, lineSegment.end.y); Stroke StrockedLineToDraw = new Stroke(m_LinesToDraw, .25); graphics2D.Render(StrockedLineToDraw, lineSegment.color); } }
public void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, RGBA_Bytes partColorIn, double minZ, double maxZ) { RGBA_Floats partColor = partColorIn.GetAsRGBA_Floats(); graphics2D.Rasterizer.gamma(new gamma_power(.3)); PathStorage polygonProjected = new PathStorage(); foreach (Face face in meshToDraw.Faces) { double averageZ = 0; Vector3 normal = Vector3.TransformVector(face.normal, trackballTumbleWidget.ModelviewMatrix).GetNormal(); if (normal.z > 0) { polygonProjected.remove_all(); bool first = true; foreach (FaceEdge faceEdge in face.FaceEdges()) { Vector2 screenPosition = trackballTumbleWidget.GetScreenPosition(faceEdge.firstVertex.Position); if (first) { polygonProjected.MoveTo(screenPosition.x, screenPosition.y); first = false; } else { polygonProjected.LineTo(screenPosition.x, screenPosition.y); } Vector3 transsformedPosition = Vector3.TransformPosition(faceEdge.firstVertex.Position, trackballTumbleWidget.ModelviewMatrix); averageZ += transsformedPosition.z; } averageZ /= 3; RGBA_Floats polyDrawColor = new RGBA_Floats(); double L = Vector3.Dot(lightNormal, normal); if (L > 0.0f) { polyDrawColor = partColor * lightIllumination * L; } polyDrawColor = RGBA_Floats.ComponentMax(polyDrawColor, partColor * ambiantIllumination); double ratio = (averageZ - minZ) / (maxZ - minZ); int ratioInt16 = (int)(ratio * 65536); //RGBA_Bytes renderColor = new RGBA_Bytes(polyDrawColor.Red0To255, ratioInt16 >> 8, ratioInt16 & 256); RGBA_Bytes renderColor = new RGBA_Bytes(ratioInt16 >> 8, ratioInt16 >> 8, ratioInt16 >> 8); //IRecieveBlenderByte oldBlender = graphics2D.DestImage.GetRecieveBlender(); //graphics2D.DestImage.SetRecieveBlender(new BlenderZBuffer()); graphics2D.Render(polygonProjected, renderColor); //graphics2D.DestImage.SetRecieveBlender(oldBlender); byte[] buffer = graphics2D.DestImage.GetBuffer(); int pixels = graphics2D.DestImage.Width * graphics2D.DestImage.Height; for (int i = 0; i < pixels; i++) { //buffer[i * 4 + 0] = buffer[i * 4 + 2]; //buffer[i * 4 + 1] = buffer[i * 4 + 2]; } } } }