本文整理汇总了C#中ICurve.CreateControlPoint方法的典型用法代码示例。如果您正苦于以下问题:C# ICurve.CreateControlPoint方法的具体用法?C# ICurve.CreateControlPoint怎么用?C# ICurve.CreateControlPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICurve
的用法示例。
在下文中一共展示了ICurve.CreateControlPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddControlPoint
/// <summary>
/// Create and add new control point to the given curve at a given Vec2F gpt</summary>
/// <param name="curve">Curve to modify</param>
/// <param name="gpt">Location on the x-axis at which to add a control point. Whether
/// or not the y-coordinate is used depends on 'insert' parameter.</param>
/// <param name="insert">If true, the y-value is inserted on the existing curve, using
/// curve.Evaluate(gpt.X). If false, the y-value comes from gpt.Y.</param>
/// <param name="computeTangent">Whether ComputeTangent() should be called</param>
public static void AddControlPoint(ICurve curve, Vec2F gpt, bool insert, bool computeTangent)
{
if (curve == null)
throw new ArgumentNullException("curve");
// add/insert new control point to the given curve. Using the following rules.
// if adding then add the point at gpt and set is tangent type to spline.
// if inserting then add the point at (gpt.x,curve.eval(gpt.x)) and compute its tangent at the point.
// recompute tangents for the curve.
// find insersion index.
int index = GetValidInsertionIndex(curve, gpt.X);
if (index >= 0)
{
IControlPoint p = curve.CreateControlPoint();
p.EditorData.SelectedRegion = PointSelectionRegions.None;
if (insert)
{
p.X = gpt.X;
ICurveEvaluator cv = CurveUtils.CreateCurveEvaluator(curve);
float prevY = cv.Evaluate(gpt.X - s_epsilone);
float nextY = cv.Evaluate(gpt.X + s_epsilone);
p.Y = cv.Evaluate(gpt.X);
p.TangentInType = CurveTangentTypes.Fixed;
p.TangentOutType = CurveTangentTypes.Fixed;
Vec2F tanIn = new Vec2F(s_epsilone, p.Y - prevY);
tanIn.Normalize();
Vec2F tanOut = new Vec2F(s_epsilone, nextY - p.Y);
tanOut.Normalize();
p.TangentIn = tanIn;
p.TangentOut = tanOut;
}
else
{
p.X = gpt.X;
p.Y = gpt.Y;
p.TangentInType = CurveTangentTypes.Spline;
p.TangentOutType = CurveTangentTypes.Spline;
}
curve.InsertControlPoint(index, p);
if (computeTangent)
ComputeTangent(curve);
}
}