private void SmoothDraw() { int width = points.GetLength(0); int height = points.GetLength(1); for (int y = 1; y < height; y++) { for (int x = 1; x < width; x++) { Vector2 left = new Vector2(), up = new Vector2(); Vector2 p = ToVec2(points[x, y].Position); if (x > 1) { left = ToVec2(points[x - 1, y].Position); float thickness = y % 3 == 1 ? maxLineWidth : minLineWidth; int clampedX = Mathf.Min(x + 1, width - 1); Vector2 mid = Interpolate.CatmullRom(ToVec2(points[x - 2, y].Position), left, p, ToVec2(points[clampedX, y].Position), 0.5f, 05f); var dist = Vector2.Distance(mid, (left + p) / 2); if (dist * dist > 1) { DrawLine(left, mid, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; DrawLine(mid, p, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; } else { DrawLine(left, p, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; } } if (y > 1) { up = ToVec2(points[x, y - 1].Position); float thickness = x % 3 == 1 ? maxLineWidth : minLineWidth; int clampedY = Mathf.Min(y + 1, height - 1); Vector2 mid = Interpolate.CatmullRom(ToVec2(points[x, y - 2].Position), up, p, ToVec2(points[x, clampedY].Position), 0.5f, 0.5f); var dist = Vector2.Distance(mid, (up + p) / 2); if (dist * dist > 1) { DrawLine(up, mid, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; DrawLine(mid, p, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; } else { DrawLine(up, p, gridColour, thickness, m_Renderers[m_LineIndex]); m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; } } if (x > 1 && y > 1) { Vector2 upLeft = ToVec2(points[x - 1, y - 1].Position); DrawLine(0.5f * (upLeft + up), 0.5f * (left + p), gridColour, minLineWidth, m_Renderers[m_LineIndex]); // vertical line m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; DrawLine(0.5f * (upLeft + left), 0.5f * (up + p), gridColour, minLineWidth, m_Renderers[m_LineIndex]); // horizontal line m_LineIndex = (m_LineIndex + 1) % m_Renderers.Length; } } } }
/** * Instead of easing based on time, generate n interpolated points (slices) * between the start and end positions. */ public static IEnumerator NewEase(Function ease, Vector3 start, Vector3 end, int slices) { IEnumerable <float> counter = Interpolate.NewCounter(0, slices + 1, 1); return(NewEase(ease, start, end, slices + 1, counter)); }
/** * Returns sequence generator from the first node to the last node over * duration time using the points in-between the first and last node * as control points of a bezier curve used to generate the interpolated points * in the sequence. If there are no control points (ie. only two nodes, first * and last) then this behaves exactly the same as NewEase(). In other words * a zero-degree bezier spline curve is just the easing method. The sequence * is generated as it is accessed using the Time.deltaTime to calculate the * portion of duration that has elapsed. */ public static IEnumerable <Vector3> NewBezier(Function ease, Transform[] nodes, float duration) { IEnumerable <float> timer = Interpolate.NewTimer(duration); return(NewBezier <Transform>(ease, nodes, TransformDotPosition, duration, timer)); }
/** * Returns sequence generator from start to end over duration using the * given easing function. The sequence is generated as it is accessed * using the Time.deltaTime to calculate the portion of duration that has * elapsed. */ public static IEnumerator NewEase(Function ease, Vector3 start, Vector3 end, float duration) { IEnumerable <float> timer = Interpolate.NewTimer(duration); return(NewEase(ease, start, end, duration, timer)); }