コード例 #1
0
    public void computeDebugPath()
    {
        if (GetHasControlPoints() == false)
        {
            InstallSplineNodes();
        }

        // store settings
        ePlaybackMode pbm = this.playbackMode;
        ePlaybackType pbt = this.type;

        // apply settings for path calculation
        this.playbackMode = ePlaybackMode.computingDebugPath;
        this.type         = ePlaybackType.const_dt;

        SetPlaybackMode(splineMgr.ePlaybackMode.computingDebugPath);

        for (int i = 0; i < kDebugLength; i++)
        {
            Vector3 p = getPointOnCurve();
            debugPath.SetPosition(i, p);
            if (IsFinished() == true)
            {
                debugPath.SetVertexCount(i - 1);
                break;
            }
        }

        // restore values
        playbackMode = pbm;
        type         = pbt;
    }
コード例 #2
0
    public void eval()
    {
        if (playbackMode == ePlaybackMode.paused)
        {
            vOut = Vector3.zero;
            Vector3 xp0 = ControlPoints[nHead].transform.position;
            Vector3 xp1 = ControlPoints[nHead + 1].transform.position;
            Vector3 xp2 = ControlPoints[nHead + 2].transform.position;
            Vector3 xp3 = ControlPoints[nHead + 3].transform.position;

            // update headObj
            vOut = PointOnCurve(t, xp0, xp1, xp2, xp3);
            if (HeadObj)
            {
                HeadObj.transform.position = vOut;
            }

            return;
        }

        // update state, wrap when t exceeds end of curve segment
        if ((playbackMode != ePlaybackMode.oneshot_finished) && (playbackMode != ePlaybackMode.computingDebugPath_finished))
        {
            if (type == ePlaybackType.const_dt)
            {
                t += dt;
            }
            else if (type == ePlaybackType.const_dist)
            {
                // find the delta that moves the arc_length by const_dist
                if (epsilon <= 0.0001f)
                {
                    epsilon = 0.0001f;
                }
                //dynamicdt = epsilon;//dhdh
                Vector3 tp0        = ControlPoints[nHead].transform.position;
                Vector3 tp1        = ControlPoints[nHead + 1].transform.position;
                Vector3 tp2        = ControlPoints[nHead + 2].transform.position;
                Vector3 tp3        = ControlPoints[nHead + 3].transform.position;
                float   sampleDist = 0.0f;
                while (sampleDist < target_arclength)
                {
                    Vector3 sample1       = PointOnCurve(t, tp0, tp1, tp2, tp3);
                    Vector3 sample2       = PointOnCurve(t + dynamicdt, tp0, tp1, tp2, tp3);
                    Vector3 vDisplacement = (sample1 - sample2);
                    sampleDist = vDisplacement.magnitude;
                    if (sampleDist < target_arclength)
                    {
                        dynamicdt += epsilon;
                    }
                    else if (sampleDist > target_arclength)
                    {
                        dynamicdt -= epsilon;
                    }
                }
                t += dynamicdt;
            }
        }

        if (t > 1.0f)
        {
            t -= 1.0f;
            nHead++;
            dynamicdt = epsilon;
        }

        // extract interpolated point from spline
        //Vector3 vOut = new Vector3(0.0f, 0.0f, 0.0f);
        vOut = Vector3.zero;
        Vector3 p0 = ControlPoints[nHead].transform.position;
        Vector3 p1 = ControlPoints[nHead + 1].transform.position;
        Vector3 p2 = ControlPoints[nHead + 2].transform.position;
        Vector3 p3 = ControlPoints[nHead + 3].transform.position;

        // end case of path compute mode
        if (playbackMode == ePlaybackMode.computingDebugPath)
        {
            if (nHead == (ControlPoints.Count - 4))
            {
                t            = 0.0f;
                playbackMode = ePlaybackMode.computingDebugPath_finished;
            }
        }

        // wrap nHead once we reach end
        if (nHead == (ControlPoints.Count - 4))
        {
            if (playbackMode == ePlaybackMode.loop)
            {
                t     = 0.0f;
                nHead = 0;
            }
            else if (playbackMode == ePlaybackMode.oneshot)
            {
                t            = 0.0f;
                playbackMode = ePlaybackMode.oneshot_finished;
            }
            else if (playbackMode == ePlaybackMode.computingDebugPath)
            {
                t            = 0.0f;
                playbackMode = ePlaybackMode.computingDebugPath_finished;
            }
        }

        // update headObj
        vOut = PointOnCurve(t, p0, p1, p2, p3);
        if (HeadObj)
        {
            HeadObj.transform.position = vOut;
        }

        // update lookObj
        if (TargetObj)
        {
            Vector3 tgtPos = Vector3.zero;
            tgtPos = PointOnCurve(t + dt, p0, p1, p2, p3);
            TargetObj.transform.position = tgtPos;
        }
    }
コード例 #3
0
 public void SetPlaybackMode(ePlaybackMode mode)
 {
     playbackMode = mode;
 }