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


C# ICurve.CreateControlPoint方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:BeRo1985,项目名称:LevelEditor,代码行数:52,代码来源:CurveUtils.cs


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