public override void Update(float time) { if (Target != null) { float xa = 0; float xb = BezierConfig.ControlPoint1.X; float xc = BezierConfig.ControlPoint2.X; float xd = BezierConfig.EndPosition.X; float ya = 0; float yb = BezierConfig.ControlPoint1.Y; float yc = BezierConfig.ControlPoint2.Y; float yd = BezierConfig.EndPosition.Y; float x = CCSplineMath.CubicBezier(xa, xb, xc, xd, time); float y = CCSplineMath.CubicBezier(ya, yb, yc, yd, time); CCPoint currentPos = Target.Position; CCPoint diff = currentPos - PreviousPosition; StartPosition = StartPosition + diff; CCPoint newPos = StartPosition + new CCPoint(x, y); Target.Position = newPos; PreviousPosition = newPos; } }
/// <summary> /// draws a cubic bezier path /// @since v0.8 /// </summary> public static void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, CCColor4B color) { float t = 0; float increment = 1.0f / segments; var vertices = new CCPoint[segments]; vertices[0] = origin; for (int i = 1; i < segments; ++i, t += increment) { vertices[i].X = CCSplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t); vertices[i].Y = CCSplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t); } vertices[segments - 1] = destination; DrawPoly(vertices, color); }
/// <summary> /// draws a cubic bezier path /// @since v0.8 /// </summary> public void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, float lineWidth, CCColor4B color) { float t = 0; float increment = 1.0f / segments; var vertices = new CCPoint[segments]; vertices[0] = origin; for (int i = 1; i < segments; ++i, t += increment) { vertices[i].X = CCSplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t); vertices[i].Y = CCSplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t); } vertices[segments - 1] = destination; for (int i = 0; i < vertices.Length - 1; i++) { DrawLine(vertices[i], vertices[i + 1], lineWidth, color); } //DrawPolygon(vertices, vertices.Length, color, 0, CCColor4B.Transparent); }