//this checks if initial data is valid private bool Setup(List <Line> lines) { if (!SetupPointGroups(lines)) { return(false); } //setup control handles Vector2D center1 = CurveTools.GetPointOnLine(pointGroup1[0], pointGroup1[segmentsCount - 1], 0.5f); Vector2D center2 = CurveTools.GetPointOnLine(pointGroup2[0], pointGroup2[segmentsCount - 1], 0.5f); Vector2D loc1 = GetHandleLocation(pointGroup1[0], pointGroup1[segmentsCount - 1], center2); Vector2D loc2 = GetHandleLocation(pointGroup2[0], pointGroup2[segmentsCount - 1], center1); ControlHandle ch1 = new ControlHandle { ControlledPoint = pointGroup1[0], RelativePosition = loc1 }; ControlHandle ch2 = new ControlHandle { ControlledPoint = pointGroup2[0], RelativePosition = loc2 }; ControlHandle ch3 = new ControlHandle { ControlledPoint = pointGroup1[segmentsCount - 1], RelativePosition = loc1 }; ControlHandle ch4 = new ControlHandle { ControlledPoint = pointGroup2[segmentsCount - 1], RelativePosition = loc2 }; ch1.Pair = ch3; ch2.Pair = ch4; ch3.Pair = ch1; ch4.Pair = ch2; controlHandles = new[] { ch1, ch2, ch3, ch4 }; //setup relative segments lengths relLenGroup1 = GetRelativeLengths(pointGroup1); relLenGroup2 = GetRelativeLengths(pointGroup2); return(true); }
//mxd public void DrawLine3DFloor(Vector2D start, Vector2D end, ref PixelColor c, PixelColor c2) { Vector2D delta = end - start; float length = delta.GetLength(); if (length < DASH_INTERVAL * 2) { DrawLineSolid((int)start.x, (int)start.y, (int)end.x, (int)end.y, ref c2); } else { float d1 = DASH_INTERVAL / length; float d2 = 1.0f - d1; Vector2D p1 = CurveTools.GetPointOnLine(start, end, d1); Vector2D p2 = CurveTools.GetPointOnLine(start, end, d2); DrawLineSolid((int)start.x, (int)start.y, (int)p1.x, (int)p1.y, ref c2); DrawLineSolid((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y, ref c); DrawLineSolid((int)p2.x, (int)p2.y, (int)end.x, (int)end.y, ref c2); } }
private void Update() { if (renderer.StartOverlay(true)) { snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid; PixelColor linesColor = snaptogrid ? General.Colors.Selection : General.Colors.Highlight; //draw curves curves = new List <Vector2D[]>(); for (int i = 0; i < segmentsCount; i++) { Vector2D cp1 = CurveTools.GetPointOnLine(controlHandles[0].Position, controlHandles[2].Position, relLenGroup1[i]); Vector2D cp2 = CurveTools.GetPointOnLine(controlHandles[1].Position, controlHandles[3].Position, relLenGroup2[i]); curves.Add(CurveTools.GetCubicCurve(pointGroup1[i], pointGroup2[i], cp1, cp2, form.Subdivisions)); for (int c = 1; c < curves[i].Length; c++) { renderer.RenderLine(curves[i][c - 1], curves[i][c], LINE_THICKNESS, linesColor, true); } } //draw connecting lines if (form.Subdivisions > 1) { for (int i = 1; i < segmentsCount; i++) { for (int c = 1; c < form.Subdivisions; c++) { renderer.RenderLine(curves[i - 1][c], curves[i][c], LINE_THICKNESS, linesColor, true); } } } //draw vertices float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale; foreach (Vector2D[] points in curves) { for (int i = 1; i < points.Length - 1; i++) { renderer.RenderRectangleFilled(new RectangleF(points[i].x - vsize, points[i].y - vsize, vsize * 2.0f, vsize * 2.0f), linesColor, true); } } //draw handle lines renderer.RenderLine(pointGroup1[0], controlHandles[0].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup2[0], controlHandles[1].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup1[segmentsCount - 1], controlHandles[2].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup2[segmentsCount - 1], controlHandles[3].Position, LINE_THICKNESS, handleColor, true); //draw handles float gripsize = GRIP_SIZE / renderer.Scale; for (int i = 0; i < 4; i++) { RectangleF handleRect = new RectangleF(controlHandles[i].Position.x - gripsize * 0.5f, controlHandles[i].Position.y - gripsize * 0.5f, gripsize, gripsize); renderer.RenderRectangleFilled(handleRect, General.Colors.Background, true); renderer.RenderRectangle(handleRect, 2, General.Colors.Highlight, true); } renderer.Finish(); } renderer.Present(); }