コード例 #1
0
    public void Update()
    {
        m_phase = 0.5f * Mathf.Sin(Time.timeSinceLevelLoad * MathUtil.Pi) + 0.5f;

        Vector3    twistAxis = m_rotInit * Vector3.up;
        Quaternion swing;
        Quaternion twist;

        QuaternionUtil.Sterp(m_rotInit, m_rotEnd, twistAxis, m_phase, out swing, out twist);

        switch (m_state)
        {
        case State.InitEnd:
        {
            m_rot0 = m_rotInit;
            m_rot1 = m_rotEnd;
            break;
        }

        case State.Comparison:
        {
            m_rot0 = Quaternion.Slerp(m_rotInit, m_rotEnd, m_phase);
            m_rot1 = swing * twist * m_rotInit;
            break;
        }

        /*
         * case State.TwistSwingTrajectory:
         * {
         * m_rot0 = Quaternion.Slerp(m_rotInit, m_rotEnd, m_phase);
         * m_rot1 = swing * twist * m_rotInit;
         *
         * const int kQueueCapacity = 20;
         * if (m_trajectory0.Count >= kQueueCapacity)
         *  m_trajectory0.Dequeue();
         * m_trajectory0.Enqueue(m_pos0 + m_rot0 * ((kRodLegnth - 0.5f * kRodThickness) * Vector3.up));
         * if (m_trajectory1.Count >= kQueueCapacity)
         *  m_trajectory1.Dequeue();
         * m_trajectory1.Enqueue(m_pos1 + m_rot1 * ((kRodLegnth - 0.5f * kRodThickness) * Vector3.up));
         *
         * Queue<Vector3> [] aTrajectory = { m_trajectory0, m_trajectory1 };
         * foreach (Queue<Vector3> trajectory in aTrajectory)
         * {
         *  Vector3 p0 = trajectory.Peek();
         *  foreach (Vector3 p1 in trajectory)
         *  {
         *    DebugUtil.DrawSphere(p0, 0.01f, 16, 32, Color.white, false, DebugUtil.Style.FlatShaded);
         *    DebugUtil.DrawCylinder(p0, p1, 0.005f, 16, Color.white, false, DebugUtil.Style.FlatShaded);
         *    p0 = p1;
         *  }
         * }
         *
         * break;
         * }
         */
        case State.TwistSwing:
        {
            m_rot0 = swing * m_rotInit;
            m_rot1 = twist * m_rotInit;
            break;
        }
        }

        DrawRod(m_pos0, m_rot0);
        DrawRod(m_pos1, m_rot1);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            ++m_state;
            if (m_state >= State.Count)
            {
                m_state = 0;
            }
        }
    }