示例#1
0
    public void GetCurveValue(float t, out Vector3 pos, out Quaternion quat)
    {
        CurvePlugin.CurveValue curveValue = new CurvePlugin.CurveValue();
        CurvePlugin.GetValue(m_id, t, ref curveValue);
        pos = PluginHelpFunction.DoubleArrayToVector3(curveValue.vec);
        switch (m_rotationMode)
        {
        case RotationMode.EULER_ANGLES:
            quat = Quaternion.Euler(PluginHelpFunction.DoubleArrayToVector3(curveValue.euler));
            break;

        case RotationMode.QUATERNION:
            quat = PluginHelpFunction.DoubleArrayToQuaternion(curveValue.quat);
            break;

        default:
            quat = Quaternion.identity;
            break;
        }
    }
示例#2
0
    public void DrawCurve()
    {
        ResetControlPoints();
        ResetLineRenderer();
        if (CurvePlugin.GetVecKeyNum(m_id) == 0)
        {
            return;
        }

        // Get cached curve points
        int    cachedPointNum = 0;
        IntPtr cachedPointPtr = IntPtr.Zero;

        CurvePlugin.GetCachedCurve(m_id, ref cachedPointNum, ref cachedPointPtr);
        if (cachedPointNum < 2)
        {
            return;
        }
        List <Vector3> cachedPoints = PluginHelpFunction.DoubleArrayPointerToVector3List(cachedPointNum, cachedPointPtr);

        // Reset LineRenderer to draw the curve
        m_curveLineRenderer.positionCount = cachedPointNum;
        m_curveLineRenderer.SetPositions(cachedPoints.ToArray());

        // Get Control Points
        if (!m_showControlPoint || m_vecInterpolationType == VecInterpolationType.LINEAR)
        {
            return;
        }
        int    controlPointNum = 0;
        IntPtr controlPointPtr = IntPtr.Zero;

        double[] startPoint = new double[3];
        double[] endPoint   = new double[3];
        CurvePlugin.GetControlPoints(m_id, startPoint, endPoint, ref controlPointNum, ref controlPointPtr);
        // The start point and the end point are not included, so the size is controlPointNum - 2
        List <Vector3> controlPoints = PluginHelpFunction.DoubleArrayPointerToVector3List(controlPointNum - 2, controlPointPtr);

        // Draw control point lines and set the position of control points
        switch (m_vecInterpolationType)
        {
        case VecInterpolationType.CUBIC_BERNSTEIN:
        case VecInterpolationType.CUBIC_CASTELJAU:
        case VecInterpolationType.CUBIC_MATRIX:
            m_controlPointLineRenderer.positionCount = controlPointNum;
            // Add the start point and the end point
            controlPoints.Insert(0, PluginHelpFunction.DoubleArrayToVector3(startPoint));
            controlPoints.Add(PluginHelpFunction.DoubleArrayToVector3(endPoint));
            m_controlPointLineRenderer.SetPositions(controlPoints.ToArray());
            // Set control points
            for (int i = 0; i < controlPoints.Count; ++i)
            {
                m_controlPointList[i].transform.position = controlPoints[i];
                // Skip key points
                if (i == 0 || (i - 1) % 4 == 1 || (i - 1) % 4 == 2 || i == controlPointNum - 1)
                {
                    m_controlPointList[i].SetActive(true);
                }
            }
            break;

        case VecInterpolationType.CUBIC_HERMITE:
            // Each key has a hermite control point line
            for (int i = 0; i < m_keyPointList.Count; ++i)
            {
                // Set the line renderer
                Vector3      slope        = controlPoints[i];
                Vector3      pos0         = m_keyPointList[i].transform.position;
                Vector3      pos1         = pos0 + slope;
                LineRenderer lineRenderer = m_hermiteControlPointLineRenderers[i];
                lineRenderer.positionCount = 2;
                lineRenderer.SetPosition(0, pos0);
                lineRenderer.SetPosition(1, pos1);
                // Set the control point
                m_controlPointList[i + 1].transform.position = pos1;
                m_controlPointList[i + 1].SetActive(true);
            }
            break;

        case VecInterpolationType.CUBIC_BSPLINE:
            // No start point and end point
            m_controlPointLineRenderer.positionCount = controlPointNum - 2;
            m_controlPointLineRenderer.SetPositions(controlPoints.ToArray());
            // Set control points
            for (int i = 0; i < controlPoints.Count; ++i)
            {
                m_controlPointList[i + 1].transform.position = controlPoints[i];
                // Skip the first and the last control points because they are at the same position as the key points
                if (!(i == 1 || i == controlPointNum - 4))
                {
                    m_controlPointList[i + 1].SetActive(true);
                }
            }
            break;

        default:
            break;
        }
    }