Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

bezier_curve

public class BezierCurve
{
    //Starts following bezier curve.
    public void StartFollow()
    {
        //some code here.
    }
}

public class BezierCurveBatch : MonoBehaviour
{
    [SerializeField]
    List<BezierCurve> m_lstChildren;

    [SerializeField]
    float m_delayStartCurve = 10;
    float m_timeLeftToStartNextChild = 0;

    bool m_isRunBatchCurve = false;

    /// <summary>
    /// Start batch follow after each interval.
    /// </summary>
    public void StartBatch()
    {
        m_isRunBatchCurve = true;
    }

    private void Update()
    {
        if (!m_isRunBatchCurve)
            return;

        m_timeLeftToStartNextChild -= Time.deltaTime;
        if (m_timeLeftToStartNextChild <= 0.0f)
        {
            if (m_lstChildren.Count > 0) //if we have children left.
            {
                BezierCurve l_bCurveToStart = m_lstChildren[0];     //Getting top object.
                m_lstChildren.RemoveAt(0);                          //removing top object.
                l_bCurveToStart.StartFollow();                      //Start follow bezier curve
                m_timeLeftToStartNextChild = m_delayStartCurve;     //resetting time.
            }

            if (m_lstChildren.Count == 0)       //After processing last object, check if need to continue for next object.
                m_isRunBatchCurve = false;
        }
    }
}
Comment

How to draw Bezier curve?

void recursive_bezier(double x1, double y1, 
                          double x2, double y2, 
                          double x3, double y3, 
                          double x4, double y4)
    {

        // Calculate all the mid-points of the line segments
        //----------------------
        double x12   = (x1 + x2) / 2;
        double y12   = (y1 + y2) / 2;
        double x23   = (x2 + x3) / 2;
        double y23   = (y2 + y3) / 2;
        double x34   = (x3 + x4) / 2;
        double y34   = (y3 + y4) / 2;
        double x123  = (x12 + x23) / 2;
        double y123  = (y12 + y23) / 2;
        double x234  = (x23 + x34) / 2;
        double y234  = (y23 + y34) / 2;
        double x1234 = (x123 + x234) / 2;
        double y1234 = (y123 + y234) / 2;

        // Try to approximate the full cubic curve by a single straight line
        //------------------
        double dx = x4-x1;
        double dy = y4-y1;

        double d2 = fabs(((x2 - x4) * dy - (y2 - y4) * dx));
        double d3 = fabs(((x3 - x4) * dy - (y3 - y4) * dx));

        if((d2 + d3)*(d2 + d3) < m_distance_tolerance * (dx*dx + dy*dy))
        {
            add_point(x1234, y1234);
            return;
        }

        // Continue subdivision
        //----------------------
        recursive_bezier(x1, y1, x12, y12, x123, y123, x1234, y1234); 
        recursive_bezier(x1234, y1234, x234, y234, x34, y34, x4, y4); 
    }


    void bezier(double x1, double y1, 
                double x2, double y2, 
                double x3, double y3, 
                double x4, double y4)
    {
        add_point(x1, y1);
        recursive_bezier(x1, y1, x2, y2, x3, y3, x4, y4);
        add_point(x4, y4);
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: overridable method C# 
Csharp :: Implementing video array in unity 
Csharp :: Reporting Progress from Async Tasks c# 
Csharp :: calculate string length vs pixels c# 
Csharp :: C3 compare hour 
Csharp :: Convert a string to Integer in C# without library function 
Csharp :: jobject alternative in system.text.json 
Csharp :: what does focusbale do in listview WPF 
Csharp :: wpf rounded button 
Csharp :: remove numericUpDown white space 
Csharp :: wpf fixed window size 
Csharp :: C# print all properties of an object including children objects 
Csharp :: fix autofill issue asp.net mvc 
Csharp :: how to make enemy killed by bullet unity2D 
Csharp :: c# iterate xml 
Csharp :: asp.net session empty cehck 
Csharp :: deploy c# applications on ubuntu 
Csharp :: save string to file c# 
Csharp :: c# ushort 
Csharp :: angular === vs == 
Csharp :: handle multiple threads c# 
Csharp :: get appsetting.json config .net 
Csharp :: use string[] args c# 
Csharp :: what is the difference between rotation rotation axis and equator 
Csharp :: Filter list contents with predicate (anonymous method) 
Csharp :: c# task call more web api in parallel 
Csharp :: generate random light color android 
Csharp :: unity disable the display of the camera frustrum 
Csharp :: Service Locator, Unity 
Csharp :: shell32.dll c# example 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =