Beispiel #1
0
        void Update()
        {
            Vector3 axis         = Vector3.down;
            float   angularSpeed = 1.0f;
            float   dt           = m_timeScale * Time.fixedDeltaTime;

            // render
            Quaternion baseRot = Quaternion.FromToRotation(Vector3.one, Vector3.up);

            DebugUtil.DrawBox(Vector3.zero, m_quatClosedForm * baseRot, Vector3.one, m_closedColor, true, DebugUtil.Style.FlatShaded);
            DebugUtil.DrawBox(Vector3.zero, m_quatPower * baseRot, 1.05f * Vector3.one, m_powerColor, true, DebugUtil.Style.Wireframe);
            DebugUtil.DrawBox(Vector3.zero, m_quatDerivative * baseRot, 1.1f * Vector3.one, m_derivativeColor, true, DebugUtil.Style.Wireframe);

            // integrate
            Quaternion v = QuaternionUtil.AxisAngle(axis, angularSpeed);
            Vector3    o = angularSpeed * axis;

            m_quatClosedForm = QuaternionUtil.Normalize(QuaternionUtil.AxisAngle(axis, (m_angle += angularSpeed * dt)));
            m_quatPower      = QuaternionUtil.Normalize(QuaternionUtil.Integrate(m_quatPower, v, dt));
            m_quatDerivative = QuaternionUtil.Normalize(QuaternionUtil.Integrate(m_quatDerivative, o, dt));

            if (Input.GetKey(KeyCode.Space))
            {
                Reset();
            }
        }