OpenTK.BezierCurveCubic.CalculatePoint C# (CSharp) Method

CalculatePoint() public method

Calculates the point with the specified t.
public CalculatePoint ( float t ) : System.Vector2
t float The t value, between 0.0f and 1.0f.
return System.Vector2
        public Vector2 CalculatePoint(float t)
        {
            Vector2 r = new Vector2();
            float c = 1.0f - t;
            r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c)
                + EndAnchor.X * t * t * t;
            r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c)
                + EndAnchor.Y * t * t * t;
            if (Parallel == 0.0f)
                return r;
            Vector2 perpendicular = new Vector2();
            if (t == 0.0f)
                perpendicular = FirstControlPoint - StartAnchor;
            else
                perpendicular = r - CalculatePointOfDerivative(t);
            return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
        }

Usage Example

Esempio n. 1
0
		public static TweenFunc<float> CubicBezier (float mx1, float my1, float mx2, float my2) {
			var curve = new BezierCurveCubic(
				            new Vector2(0f, 0f),
				            new Vector2(1f, 1f),
				            new Vector2(mx1, my1),
				            new Vector2(mx2, my2)
			            );
			return (from, to, t) => {
				return from + (to - from) * curve.CalculatePoint(t).Y;
			};
		}
All Usage Examples Of OpenTK.BezierCurveCubic::CalculatePoint