Exemple #1
0
        /// <summary>
        /// Compute the length on a catmull rom spline between control point 1 and 2 </summary>
        /// <param name="theP0"> control point 0 </param>
        /// <param name="theP1"> control point 1 </param>
        /// <param name="theP2"> control point 2 </param>
        /// <param name="theP3"> control point 3 </param>
        /// <param name="theStartRange"> the starting range on the segment (use 0) </param>
        /// <param name="theEndRange"> the end range on the segment (use 1) </param>
        /// <param name="theCurveTension"> the curve tension </param>
        /// <returns> the length of the segment </returns>
        private float CatmullRomLength(Vector3 theP0, Vector3 theP1, Vector3 theP2, Vector3 theP3, float theStartRange, float theEndRange, float theCurveTension)
        {
            float   epsilon     = 0.001f;
            float   middleValue = (theStartRange + theEndRange) * 0.5f;
            Vector3 start       = theP1;

            if (theStartRange != 0)
            {
                start = CCVector3.CatmulRomPoint(theP0, theP1, theP2, theP3, theStartRange, theCurveTension);
            }
            Vector3 end = theP2;

            if (theEndRange != 1)
            {
                end = CCVector3.CatmulRomPoint(theP0, theP1, theP2, theP3, theEndRange, theCurveTension);
            }
            Vector3 middle = CCVector3.CatmulRomPoint(theP0, theP1, theP2, theP3, middleValue, theCurveTension);
            float   l      = Vector3.Distance(end, start);
            float   l1     = Vector3.Distance(middle, start);
            float   l2     = Vector3.Distance(end, middle);
            float   len    = l1 + l2;

            if (l + epsilon < len)
            {
                l1 = CatmullRomLength(theP0, theP1, theP2, theP3, theStartRange, middleValue, theCurveTension);
                l2 = CatmullRomLength(theP0, theP1, theP2, theP3, middleValue, theEndRange, theCurveTension);
            }
            l = l1 + l2;
            return(l);
        }
 public override Vector3 Interpolate(float value, int currentControlPoint)
 {
     if (currentControlPoint + 3 >= _myPoints.Count)
     {
         return(_myPoints[currentControlPoint]);
     }
     return(CCVector3.BezierPoint(_myPoints[currentControlPoint], _myPoints[currentControlPoint + 1], _myPoints[currentControlPoint + 2], _myPoints[currentControlPoint + 3], value));
 }
Exemple #3
0
 public override Vector3 Interpolate(float value, int currentControlPoint)
 {
     EndEditSpline();
     if (currentControlPoint + 3 >= _myPoints.Count)
     {
         return(_myPoints[currentControlPoint]);
     }
     return(CCVector3.CatmulRomPoint(_myPoints[currentControlPoint], _myPoints[currentControlPoint + 1], _myPoints[currentControlPoint + 2], _myPoints[currentControlPoint + 3], value, _myCurveTension));
 }
        /// <summary>
        /// Compute the length on a bezier spline between control point 1 and 2 </summary>
        /// <param name="theP0"> control point 0 </param>
        /// <param name="theP1"> control point 1 </param>
        /// <param name="theP2"> control point 2 </param>
        /// <param name="theP3"> control point 3 </param>
        /// <returns> the length of the segment </returns>
        public static float BezierLength(Vector3 theP0, Vector3 theP1, Vector3 theP2, Vector3 theP3)
        {
            float   delta = 0.01f, t = 0.0f, result = 0.0f;
            Vector3 v1 = theP0, v2 = new Vector3();

            while (t <= 1.0f)
            {
                v2      = CCVector3.BezierPoint(theP0, theP1, theP2, theP3, t);
                result += Vector3.Distance(v1, v2);
                v1.Set(v2.x, v2.y, v2.z);
                t += delta;
            }
            return(result);
        }