public void AddCurve(IEnumerable <PointF> points, float tension) { points = SplineHelper.SplineCurve(points, tension); SplineHelper.Draw(points, start => ConnectTo(start), (c1, c2, end) => { Control.AddCurveToPoint(c1.X, c1.Y, c2.X, c2.Y, end.X, end.Y); }); }
//-------------------------------------------------------- protected void _DrawSpline(int i) { //Clamp to allow looping Vector3 p0 = _GetPoint(i - 1); Vector3 p1 = _GetPoint(i); Vector3 p2 = _GetPoint(i + 1); Vector3 p3 = _GetPoint(i + 2); Vector3 lastPos = p1; float length = 0f; //t is always between 0 and 1 and determines the resolution of the spline //0 is always at p1 for (float t = SplineHelper.STEP; t < 1f; t += SplineHelper.STEP) { Vector3 newPos = SplineHelper.Get(t, p0, p1, p2, p3); Gizmos.DrawLine(lastPos, newPos); // Gizmos.DrawSphere( newPos, 0.1f ); length += (newPos - lastPos).magnitude; lastPos = newPos; } _DrawArrow(lastPos, p2); length += (p2 - lastPos).magnitude; if (lengths != null && lengths.Length > i) { lengths[i] = length; } }
public void ExecuteCurve() { var x = GetFloat(); var y = GetFloat(); SetStart(x, y); SplineHelper.Draw(GetPoints(), ConnectTo, (c1, c2, end) => Context.CurveTo(c1.ToCairo(), c2.ToCairo(), end.ToCairo())); }
public void AddCurve(IEnumerable <PointF> points, float tension = 0.5f) { points = SplineHelper.SplineCurve(points, tension); var swpoints = (from p in points select p.ToWpf()).ToArray(); ConnectTo(swpoints.First()); figure.Segments.Add(new swm.PolyBezierSegment(swpoints, true)); CurrentPoint = swpoints.Last().ToEto(); }
public void AddCurve(IEnumerable <PointF> points, float tension = 0.5f) { var pointArray = SplineHelper.SplineCurve(points, tension).ToArray(); Add(exec => { exec.SetStart(points.First()); SplineHelper.Draw(pointArray, exec.ConnectTo, (c1, c2, end) => exec.Context.CurveTo(c1.ToCairo(), c2.ToCairo(), end.ToCairo())); }, pointArray); }
public void AddCurve(IEnumerable <PointF> points, float tension = 0.5f) { _commands.Add(CommandType.Curve); foreach (var point in SplineHelper.SplineCurve(points, tension)) { AddPoint(point); } AddFloat(float.NaN); }
void TryToLeavePath() { Debug.Log("trying to leave"); if (Mathf.Abs(currentSpline.ratioAtPoint(transform.position) - 1.0f) < 0.001f) { Debug.Log("approved to leave"); LeavePath(); } else { LeanTween.moveSpline(gameObject, SplineHelper.CreateSpline(currentPathVectors), 10f).setSpeed(onPathSpeed).setOnComplete(TryToLeavePath); } }
void RidePath(RidePath ridePath, int start = 0, Vector3?startVector = null) { Vector3[] path = new Vector3[0]; // Trim beginning of vector array if starting index is not 0... if (start != 0) { int partialPathLength = ridePath.pathVectors.Length - start; int startIndex = 0; // Change starting vector if provided if (startVector != null && startVector.GetType().Equals(typeof(Vector3))) { path = new Vector3[partialPathLength + 1]; path[0] = (Vector3)startVector; startIndex = 1; } else { path = new Vector3[partialPathLength]; } // Assemble path for (int i = startIndex; i < partialPathLength + startIndex; i++) { path[i] = ridePath.pathVectors[start + i - startIndex]; } } // ...Otherwise, just ride the provided path from the beginning else { path = ridePath.pathVectors; } // Ride the path! Debug.Log("riding path!"); for (int i = 0; i < path.Length - 1; i++) { Debug.DrawLine(path[i], path[i + 1], Color.red, 5.0f); } onPath = true; currentPath = ridePath; currentPathVectors = path; currentSpline = SplineHelper.CreateSpline(path); currentPathVectorIndex = 0; currentPathVector = path[currentPathVectorIndex]; nextPathVector = path[currentPathVectorIndex + 1]; LeanTween.moveSpline(gameObject, currentSpline, 10f).setSpeed(onPathSpeed).setOnComplete(TryToLeavePath); Instantiate(startRidePS, transform.position, Quaternion.identity); }
//-------------------------------------------------------- protected void AddSubLinePoints(int i) { //Clamp to allow looping Vector3 p0 = _GetPoint(i - 1); Vector3 p1 = _GetPoint(i); Vector3 p2 = _GetPoint(i + 1); Vector3 p3 = _GetPoint(i + 2); //t is always between 0 and 1 and determines the resolution of the spline //0 is always at p1 for (float t = 0f; t < 1f; t += SplineHelper.STEP) { points.Add(SplineHelper.Get(t, p0, p1, p2, p3)); } }
// Use this for initialization void Start() { rend = GetComponent <LineRenderer>(); pathVectors = new Vector3[rend.positionCount]; numVectors = rend.GetPositions(pathVectors); // Set up collider and its requisite rigidbody rb = gameObject.AddComponent(typeof(Rigidbody2D)) as Rigidbody2D; rb.bodyType = RigidbodyType2D.Kinematic; GameObject cdGO = new GameObject("Collider"); cdGO.layer = LayerMask.NameToLayer("Path"); cdGO.transform.parent = gameObject.transform; cd = cdGO.AddComponent(typeof(EdgeCollider2D)) as EdgeCollider2D; cd.points = ConvertToVector2Array(pathVectors); cd.isTrigger = true; pathSpline = SplineHelper.CreateSpline(pathVectors); rend.sortingLayerName = "Character"; // Get position with largest x value (used to determine whether path is still on screen) maxX = GetMaximumXVector(); LevelManager lm = GameObject.FindWithTag("GameController").GetComponent <LevelManager>(); lm.paths.Add(this); if (unidirectional) { shine = new GameObject("Shine"); GameObject shineRendGO = (GameObject)Instantiate(Resources.Load("Prefabs/RoundShine")); SpriteRenderer shineRend = shineRendGO.GetComponent <SpriteRenderer>(); shineRend.sortingLayerName = "Character"; shineRend.color = new Color(rend.material.color.r, rend.material.color.g, rend.material.color.b, .75f); shine.transform.parent = gameObject.transform; shineRendGO.transform.parent = shine.transform; shineRendGO.transform.position = new Vector3(shine.transform.position.x, shine.transform.position.y, shine.transform.position.z + 1); ShinePathDirection(); } }
private void splineToolStripMenuItem_Click(object sender, EventArgs e) { var ph = new SplineHelper() { Degree = 2 }; ph.IsPeriodic = false; ph.IsNonPeriodic = true; ph.IsBSpline = true; ph.IsPolynomial = false; ph.SetKnots(new double[] { 0, 1 }); ph.SetMultiplicities(new[] { 3, 3 }); ph.SetWeights(new double[] { 1, 1, 1 }); ph.SetPoles(new Vector3d[] { new Vector3d(-3, -2.858306, 5.2154), new Vector3d(-3, -5, 5.2154), new Vector3d(-3, -5, 2.7154) }); Helpers.Add(ph); updateHelpersList(); }
public void AddCurve(IEnumerable <PointF> points, float tension = 0.5f) { points = SplineHelper.SplineCurve(points, tension); SplineHelper.Draw(points, ConnectTo, (c1, c2, end) => this.AddCurveToPoint(c1, c2, end)); }
public void AddCurve(IEnumerable <PointF> points, float tension = 0.5f) { var temp = SplineHelper.SplineCurve(points, tension); SplineHelper.Draw(temp, ConnectTo, AddBezier); }