当前位置: 首页>>代码示例>>C#>>正文


C# ICurve.InsertControlPoint方法代码示例

本文整理汇总了C#中ICurve.InsertControlPoint方法的典型用法代码示例。如果您正苦于以下问题:C# ICurve.InsertControlPoint方法的具体用法?C# ICurve.InsertControlPoint怎么用?C# ICurve.InsertControlPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICurve的用法示例。


在下文中一共展示了ICurve.InsertControlPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
            }
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:52,代码来源:CurveUtils.cs

示例2: Sort

        /// <summary>
        /// Sort control points along x axis</summary>       
        /// <param name="curve">Curve whose control points are sorted</param>
        public static void Sort(ICurve curve)
        {
            if (curve == null) return;

            ReadOnlyCollection<IControlPoint> points = curve.ControlPoints;
            if (points.Count < 2)
                return;

            try
            {
                s_points.Clear();
                s_points.AddRange(points);

                // note about "insertion sort"
                // this type of sort is most efficient for Substantially sorted data
                // in this case the data is Substantially sorted, only few elements need fixing.
                for (int i = 1; i < s_points.Count; i++)
                {
                    IControlPoint val = s_points[i];
                    int j = i - 1;
                    while (j >= 0 && s_points[j].X > val.X)
                    {
                        s_points[j + 1] = s_points[j];
                        j--;
                    }
                    s_points[j + 1] = val;
                }

                for (int i = 0; i < s_points.Count; i++)
                {
                    IControlPoint scpt = s_points[i];
                    IControlPoint cpt = points[i];
                    if (scpt != cpt)
                    {                        
                        curve.InsertControlPoint(i, scpt);
                    }
                }
            }
            finally
            {
                s_points.Clear();
            }            
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:46,代码来源:CurveUtils.cs


注:本文中的ICurve.InsertControlPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。