protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); _shader.Use(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); SetupCamera(); // _cube.Draw(); var points = new[] { new Vector2(0, 0), new Vector2(1, 2), new Vector2(-1, 1) }; var aBezierCurve = new BezierCurve(points); GL.LineWidth(4.0f); CatmullRomSpline a = new CatmullRomSpline(); a.AddPoint(new Vector3(-1, -1, 0)); a.AddPoint(new Vector3(1, 1, 0)); a.AddPoint(new Vector3(1, -1, 0)); a.AddPoint(new Vector3(-1, 1, 0)); a.AddPoint(new Vector3(-1, -1, 0)); Vector3 vec = a.GetValue((float)_time / 10); GL.Translate(vec); _cube.Draw(); SwapBuffers(); }
/// <summary> /// Calculates the point on the given bezier curve with the specified t parameter. /// </summary> /// <param name="points">The points.</param> /// <param name="t">The t parameter, a value between 0.0f and 1.0f.</param> /// <returns>Resulting point.</returns> public static Vector2 CalculatePoint(IList <Vector2> points, float t) { return(BezierCurve.CalculatePoint(points, t, 0.0f)); }
/// <summary> /// Calculates the length of the specified bezier curve. /// </summary> /// <param name="points">The points.</param> /// <param name="precision">The precision value.</param> /// <returns>The precision gets better as the <paramref name="precision"/> /// value gets smaller.</returns> public static float CalculateLength(IList <Vector2> points, float precision) { return(BezierCurve.CalculateLength(points, precision, 0.0f)); }
/// <summary> /// Calculates the length of this bezier curve. /// </summary> /// <param name="precision">The precision.</param> /// <returns>Length of curve.</returns> /// <remarks>The precision gets better as the <paramref name="precision"/> /// value gets smaller.</remarks> public float CalculateLength(float precision) { return(BezierCurve.CalculateLength(points, precision, Parallel)); }
/// <summary> /// Calculates the point with the specified t. /// </summary> /// <param name="t">The t value, between 0.0f and 1.0f.</param> /// <returns>Resulting point.</returns> public Vector2 CalculatePoint(float t) { return(BezierCurve.CalculatePoint(points, t, Parallel)); }
public float CalculateLength(float precision) { return(BezierCurve.CalculateLength((IList <Vector2>) this.points, precision, this.Parallel)); }
public Vector2 CalculatePoint(float t) { return(BezierCurve.CalculatePoint((IList <Vector2>) this.points, t, this.Parallel)); }
public static Vector2 CalculatePoint(IList <Vector2> points, float t, float parallel) { Vector2 vector2_1 = new Vector2(); double x = 1.0 - (double)t; int k = 0; foreach (Vector2 vector2_2 in (IEnumerable <Vector2>)points) { float num = (float)MathHelper.BinomialCoefficient(points.Count - 1, k) * (float)(Math.Pow((double)t, (double)k) * Math.Pow(x, (double)(points.Count - 1 - k))); vector2_1.X += num * vector2_2.X; vector2_1.Y += num * vector2_2.Y; ++k; } if ((double)parallel == 0.0) { return(vector2_1); } Vector2 vector2_3 = new Vector2(); Vector2 vec = (double)t == 0.0 ? points[1] - points[0] : vector2_1 - BezierCurve.CalculatePointOfDerivative(points, t); return(vector2_1 + Vector2.Normalize(vec).PerpendicularRight *parallel); }
/// <summary> /// Constructs a new OpenTK.BezierCurve. /// </summary> /// <param name="points">The points.</param> public Bezier( IEnumerable<Vector2> points, int resolution ) : base(points, resolution) { m_curve = new BezierCurve( m_points ); // resolution is not used here }
/// <summary> /// Tessellates the path. /// </summary> /// <param name="path">The path.</param> public void TessellatePath(PathGeometry path) { _vertexList.Clear(); _tesselator.EmptyCache(); _tesselator.BeginPolygon(); switch(path.FillRule) { case FillRule.EvenOdd: _tesselator.WindingRule = Tesselator.Tesselator.WindingRuleType.Odd; break; case FillRule.Nonzero: _tesselator.WindingRule = Tesselator.Tesselator.WindingRuleType.NonZero; break; default: throw new ArgumentOutOfRangeException(); } foreach (var figure in path.Figures) { _tesselator.BeginContour(); foreach (var seg in figure.Segments) { if (seg is PolyLineSegment) { var polyline = seg as PolyLineSegment; polyline.Points.ForEach(AddPoint); } else if (seg is LineSegment) { AddPoint((seg as LineSegment).Point); } else if (seg is PolyBezierSegment) { var polybezier = (PolyBezierSegment) seg; var bezierCurve = new BezierCurve(polybezier.Points.Select(p => new Vector2((float) p.X, (float) p.Y))); Enumerable .Range(1, 10) .Select(i => bezierCurve.CalculatePoint(1.0f/i)) .ForEach(p => AddPoint(new Point(p.X, p.Y))); } else if (seg is BezierSegment) { var polybezier = (BezierSegment)seg; var bezierCurve = new BezierCurveCubic( LastPoint(), new Vector2((float) polybezier.Point3.X, (float) polybezier.Point3.Y), new Vector2((float) polybezier.Point1.X, (float) polybezier.Point1.Y), new Vector2((float) polybezier.Point2.X, (float) polybezier.Point2.Y) ); Enumerable .Range(1, 10) .Select(i => bezierCurve.CalculatePoint(1.0f / i)) .ForEach(p => AddPoint(new Point(p.X, p.Y))); } else { throw new ApplicationException(string.Format("segment type {0} not supported.", seg)); } } _tesselator.EndContour(); } _tesselator.EndPolygon(); }