예제 #1
0
    public bool GetCurve(float time, ref Vector3 pPos)
    {
        if (m_tcbvector.Count < 2)
        {
            return(false);
        }

        TCB3f tcb_front = m_tcbvector[0];
        TCB3f tcb_back  = m_tcbvector[m_tcbvector.Count - 1];

        if (time <= tcb_front.m_time)
        {
            pPos = tcb_front.m_cur;
            return(true);
        }

        if (time >= tcb_back.m_time)
        {
            pPos = tcb_back.m_cur;
            return(true);
        }

        int index = Utility.UpperBinarySearch(m_tcbvector, time, delegate(TCB3f a, float b)
        {
            return(a.m_time <b ? -1 : a.m_time> b ? 1 : 0);
        });

        if (index != -1)
        {
            TCB3f tcb_prev = m_tcbvector[index - 1];
            TCB3f tcb_cur  = m_tcbvector[index];

            float prev_time = tcb_prev.m_time;
            float cur_time  = tcb_cur.m_time;
            // if (prev_time == time) return tcb_prev.m_cur;

            float t = (time - prev_time) / (cur_time - prev_time);

            Vector3 p0 = tcb_prev.m_cur;
            Vector3 p1 = tcb_cur.m_cur;
            Vector3 m0 = tcb_prev.m_tangent_dest;
            Vector3 m1 = tcb_cur.m_tangent_source;

            float t2 = t * t;
            float t3 = t2 * t;

            pPos = (2.0f * t3 - 3.0f * t2 + 1.0f) * p0 +
                   (t3 - 2.0f * t2 + t) * m0 +
                   (t3 - t2) * m1 +
                   (-2.0f * t3 + 3.0f * t2) * p1;

            return(true);
        }

        return(false);
    }
예제 #2
0
    public void CalcCurve()
    {
        if (m_tcbvector.Count == 0)
        {
            return;
        }

        m_tcbvector.Sort(delegate(TCB3f a, TCB3f b)
        {
            return(a.m_time <b.m_time ? -1 : a.m_time> b.m_time ? 1 : 0);
        });

        for (int i = 0; i < m_tcbvector.Count; ++i)
        {
            TCB3f tcb_curr = m_tcbvector[i];

            if (i == 0)
            {
                tcb_curr.m_prev = tcb_curr.m_cur;
            }

            if (i > 0)
            {
                TCB3f tcb_prev = m_tcbvector[i - 1];
                tcb_curr.m_prev = tcb_prev.m_cur;
            }

            if (i + 1 < m_tcbvector.Count)
            {
                TCB3f tcb_next = m_tcbvector[i + 1];
                tcb_curr.m_next = tcb_next.m_cur;
            }

            if (i + 1 == m_tcbvector.Count)
            {
                tcb_curr.m_next = tcb_curr.m_cur;
            }

            tcb_curr.CalcTangent();
            m_tcbvector[i] = tcb_curr;
        }
    }
예제 #3
0
 public void SetTCB(int index, TCB3f p)
 {
     m_tcbvector[index] = p;
 }
예제 #4
0
 public void AddTCB(TCB3f p)
 {
     m_tcbvector.Add(p);
 }