コード例 #1
0
    public void EditVecKey(GameObject key, Vector3 pos)
    {
        key.transform.position = pos;
        int keyID = GetVecKeyID(key);

        CurvePlugin.EditVecKey(m_id, keyID, PluginHelpFunction.Vector3ToDoubleArray(pos));

        m_curveChanged = true;
    }
コード例 #2
0
    public void EditVecControlPoint(GameObject controlPoint, Vector3 pos)
    {
        controlPoint.transform.position = pos;
        int cpID = GetControlPointID(controlPoint);

        if (m_vecInterpolationType == VecInterpolationType.CUBIC_HERMITE)
        {
            pos -= m_keyPointList[cpID - 1].transform.position;
        }
        CurvePlugin.EditVecControlPoint(m_id, cpID, PluginHelpFunction.Vector3ToDoubleArray(pos));
        m_curveChanged = true;
    }
コード例 #3
0
    public void AppendVecKey(Vector3 pos)
    {
        GameObject keyPoint = Instantiate(m_keyPointPrefab, pos, Quaternion.identity);

        keyPoint.transform.SetParent(m_keyPointParent.transform);
        m_keyPointList.Add(keyPoint);


        CurvePlugin.AppendVecKey(m_id, PluginHelpFunction.Vector3ToDoubleArray(pos));

        m_curveChanged = true;
    }
コード例 #4
0
    //Copy transform and rigidbody data to m_actorDataArray
    public void WriteActorDataArray()
    {
        for (int i = 0; i < m_actorNum; ++i)
        {
            ref BehaviorPlugin.ActorData actorData = ref m_actorDataArray[i];

            // Get the leader's root joint transform because its controlled by keyboard
            if (m_actorList[i] == m_leader)
            {
                GameObject root = m_leader.GetComponent <FKIKCharacterController>().m_root;
                actorData.globalPosition = PluginHelpFunction.Vector3ToFloatArray(root.transform.position);
                actorData.globalRotation = PluginHelpFunction.QuaternionToFloatArray(root.transform.rotation);
            }
        }
コード例 #5
0
    // Insert a rotation key into both the euler curve and the quaternion curve
    // The keyID in these two curves should be the same
    public void InsertRotationKey(GameObject key)
    {
        if (m_rotationKeyPointList.IndexOf(key) != -1)
        {
            Debug.Log("This rotation key has been added.");
            return;
        }
        double t       = GetVecKeyID(key); // Assume t equals keyID
        int    eulerID = CurvePlugin.InsertEulerKey(m_id, t, PluginHelpFunction.Vector3ToDoubleArray(Quaternion.identity.eulerAngles));
        int    quatID  = CurvePlugin.InsertQuatKey(m_id, t, PluginHelpFunction.QuaternionToDoubleArray(Quaternion.identity));

        if (eulerID != quatID)
        {
            Debug.LogError("Euler curve ID and Quat curve ID are different");
        }
        m_rotationKeyPointList.Insert(eulerID, key);
    }
コード例 #6
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;
        }
    }
コード例 #7
0
    public void ResetPlugin()
    {
        m_actorNum = m_actorList.Count;
        BehaviorPlugin.InitializeBehaviorPlugin(m_actorNum, m_obstacleNum, (int)m_behaviorType);
        int gainNum = BehaviorPlugin.GetGainNum();

        BehaviorPlugin.SetControllerGains(m_gain.GetGainFloatArray(gainNum), gainNum);

        m_actorDataArray = new BehaviorPlugin.ActorData[m_actorNum];
        for (int i = 0; i < m_actorNum; ++i)
        {
            m_actorDataArray[i] = new BehaviorPlugin.ActorData(i);
            m_actorDataArray[i].globalPosition = PluginHelpFunction.Vector3ToFloatArray(m_actorList[i].transform.position);
            m_actorDataArray[i].globalRotation = PluginHelpFunction.QuaternionToFloatArray(m_actorList[i].transform.rotation);
        }
        SetLeader(m_leader);
        ClearObstacles();
        if (m_behaviorType == BehaviorType.AVOID)
        {
            GenerateObstacles();
        }
    }
コード例 #8
0
    public void GenerateObstacles()
    {
        Vector3[] positions = new Vector3[] { new Vector3(500, 0, 500),
                                              new Vector3(500, 0, -500), new Vector3(-500, 0, -500), new Vector3(-500, 0, 500) };
        ClearObstacles();
        m_obstacleDataArray = new BehaviorPlugin.ObstacleData[m_obstacleNum];
        for (int i = 0; i < m_obstacleNum; ++i)
        {
            // Generates random obstacles
            GameObject obstacle = GameObject.Instantiate(m_obstaclePrefab);
            Vector3    position;
            if (i <= 3)
            {
                position = positions[i];
            }
            else
            {
                position = new Vector3(Random.Range(m_obstaclePosMinMax[0], m_obstaclePosMinMax[1]),
                                       0, Random.Range(m_obstaclePosMinMax[0], m_obstaclePosMinMax[1]));
            }
            Physics.Raycast(position + new Vector3(0, 1000, 0), Vector3.down, out RaycastHit hit, Mathf.Infinity, m_environmentLayer);
            position.y = hit.point.y;

            float   randomRadius = Random.Range(m_obstacleRadiusMinMax[0], m_obstacleRadiusMinMax[1]);
            Vector3 scale        = new Vector3(randomRadius, randomRadius, randomRadius);
            obstacle.transform.position   = position;
            obstacle.transform.localScale = scale;
            obstacle.transform.rotation   = Random.rotation;
            m_obstacleList.Add(obstacle);

            // Set obstacle data
            m_obstacleDataArray[i].globalPosition = PluginHelpFunction.Vector3ToFloatArray(position);
            m_obstacleDataArray[i].radius         = randomRadius;
        }
        BehaviorPlugin.SetObstacleData(m_obstacleDataArray, m_obstacleNum);
    }
コード例 #9
0
    public void EditQuatKey(GameObject key, Quaternion quat)
    {
        int keyID = GetRotationKeyID(key);

        CurvePlugin.EditQuatKey(m_id, keyID, PluginHelpFunction.QuaternionToDoubleArray(quat));
    }
コード例 #10
0
    public void EditEulerKey(GameObject key, Vector3 euler)
    {
        int keyID = GetRotationKeyID(key);

        CurvePlugin.EditEulerKey(m_id, keyID, PluginHelpFunction.Vector3ToDoubleArray(euler));
    }
コード例 #11
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;
        }
    }