protected void TriangleContext(Pointdata a, Pointdata b, Pointdata c) { //clear history if (Vertices != null) { Vertices.Dispose(); Layout.Dispose(); Vertexbuffer.Dispose(); } Vertices = new DataStream(12 * 3, true, true); Vertices.Write(new Vector3(a.x, a.y, a.z)); Vertices.Write(new Vector3(b.x, b.y, b.z)); Vertices.Write(new Vector3(c.x, c.y, c.z)); Vertices.Position = 0; // create the vertex layout and buffer var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0) }; Layout = new InputLayout(_device, InputSignature, elements); Vertexbuffer = new Buffer(_device, Vertices, 12 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); // configure the Input Assembler portion of the pipeline with the vertex data Devicecontext.InputAssembler.InputLayout = Layout; Devicecontext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; Devicecontext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(Vertexbuffer, 12, 0)); // set the shaders Devicecontext.VertexShader.Set(Vertexshader); Devicecontext.PixelShader.Set(Pixelshader); // draw the triangle Devicecontext.Draw(3, 0); }
public static List <Pointdata> GetCircle(Pointdata p, Strokedata s, int precise) { List <Pointdata> pointlist = new List <Pointdata>(); for (float i = 0; i < precise * 2; i++) { pointlist.Add(new Pointdata(GetRelateX((float)(GetRealX(p) + s.Line * (1f) * Math.Cos(Math.PI * i / precise))), GetRelateY((float)(GetRealY(p) + s.Line * (1f) * Math.Sin(Math.PI * i / precise))))); } return(pointlist); }
protected void Createvertex(Strokedata stroke) { Pointdata a = null, b = null, c = null, d = null; // create test vertex data, making sure to rewind the stream afterward lock (stroke.Plist) { int count = 0; int precise = 5; List <Pointdata> list = CloneTool.Clone(stroke.Plist); Pointdata last = list[0]; for (int j = 0; j < list.Count; j++) { Pointdata p = list[j]; if (j >= stroke.Index) { List <Pointdata> pointCircle = MathTool.GetCircle(p, stroke, precise); for (int i = 0; i < precise * 2; i++) { TriangleContext(p, pointCircle[(i + 1) % (precise * 2)], pointCircle[i]); } if (count > 0) { if (last.y.Equals(p.y)) { a = new Pointdata(last.x, MathTool.GetRelateY(MathTool.GetRealY(last) + stroke.Line * (1f))); b = new Pointdata(last.x, MathTool.GetRelateY(MathTool.GetRealY(last) - stroke.Line * (1f))); c = new Pointdata(p.x, MathTool.GetRelateY(MathTool.GetRealY(p) + stroke.Line * (1f))); d = new Pointdata(p.x, MathTool.GetRelateY(MathTool.GetRealY(p) - stroke.Line * (1f))); } else { a = MathTool.GetpointA(last, p, stroke.Line); b = MathTool.GetpointB(last, p, stroke.Line); c = MathTool.GetpointC(last, p, stroke.Line); d = MathTool.GetpointD(last, p, stroke.Line); } } count++; if (a != null) { TriangleContext(a, c, b); TriangleContext(a, b, c); TriangleContext(c, d, b); TriangleContext(c, b, d); } last = p; stroke.Index = j; } } } }
public static Pointdata GetpointD(Pointdata last, Pointdata p, int line) { float rotate1cos = (GetRealX(p) - GetRealX(last)) / (float)Math.Sqrt(Math.Pow(GetRealX(p) - GetRealX(last), 2) + Math.Pow(GetRealY(p) - GetRealY(last), 2)); float rotate1sin = (GetRealY(last) - GetRealY(p)) / (float)Math.Sqrt(Math.Pow(GetRealX(p) - GetRealX(last), 2) + Math.Pow(GetRealY(p) - GetRealY(last), 2)); float rotate2cos = rotate1cos; float rotate2sin = -rotate1sin; float NewcenX = GetRealX(p) * rotate1cos - GetRealY(p) * rotate1sin; float NewcenY = GetRealX(p) * rotate1sin + GetRealY(p) * rotate1cos; float A1x = NewcenX * rotate2cos - (NewcenY + line * (1f)) * rotate2sin; float A2x = NewcenX * rotate2cos - (NewcenY - line * (1f)) * rotate2sin; float Ax, Ay; if (A1x < A2x) { Ax = A2x; Ay = NewcenX * rotate2sin + (NewcenY - line * (1f)) * rotate2cos; } else { Ax = A1x; Ay = NewcenX * rotate2sin + (NewcenY + line * (1f)) * rotate2cos; } return(new Pointdata(GetRelateX(Ax), GetRelateY(Ay))); }
public static bool ClockWise(Pointdata a, Pointdata b, Pointdata c) { float[] x = { GetRealX(a), GetRealX(b), GetRealX(c) }; float[] y = { GetRealY(a), GetRealY(b), GetRealY(c) }; if (!x[0].Equals(x[1]) && !x[0].Equals(x[2])) { if (x[0] < x[1] && x[1] < x[2]) { return(true); } if (x[0] < x[1] && x[2] < x[0]) { return(true); } if (x[0] > x[2] && x[2] > x[1]) { return(true); } } else { if (!y[0].Equals(y[1]) && !y[1].Equals(y[2])) { if (y[0] < y[1] && y[1] < y[2]) { return(true); } if (y[0] < y[1] && y[2] < y[0]) { return(true); } if (y[0] > y[2] && y[2] > y[1]) { return(true); } } else { if (y[0].Equals(y[1])) { if (x[0] > x[1] && x[2] < y[0]) { return(true); } if (x[0] < x[1] && x[2] > y[0]) { return(true); } } if (y[0].Equals(y[2])) { if (x[0] > x[2] && x[1] > y[0]) { return(true); } if (x[0] < x[2] && x[1] < y[0]) { return(true); } } } } return(false); }
public static float GetRealY(Pointdata p) { return(Canvainfo.height * p.y / 2); }
public static float GetRealX(Pointdata p) { return(Canvainfo.width * p.x / 2); }