Ejemplo n.º 1
0
    float Ang(Quaternion rotationA, Quaternion rotationB, MegaLinkSrc t)
    {
        Vector3 forwardA = rotationA * Vector3.forward;
        Vector3 forwardB = rotationB * Vector3.forward;

        float angleA = 0.0f;
        float angleB = 0.0f;

        switch (t)
        {
        case MegaLinkSrc.RotationXY:
            angleA = Mathf.Atan2(forwardA.x, forwardA.y) * Mathf.Rad2Deg;
            angleB = Mathf.Atan2(forwardB.x, forwardB.y) * Mathf.Rad2Deg;
            break;

        case MegaLinkSrc.RotationXZ:
            angleA = Mathf.Atan2(forwardA.x, forwardA.z) * Mathf.Rad2Deg;
            angleB = Mathf.Atan2(forwardB.x, forwardB.z) * Mathf.Rad2Deg;
            break;

        case MegaLinkSrc.RotationYZ:
            angleA = Mathf.Atan2(forwardA.y, forwardA.z) * Mathf.Rad2Deg;
            angleB = Mathf.Atan2(forwardB.y, forwardB.z) * Mathf.Rad2Deg;
            break;
        }

        return(Mathf.DeltaAngle(angleA, angleB));
    }
Ejemplo n.º 2
0
    float Ang(Quaternion rotationA, Quaternion rotationB, MegaLinkSrc t)
    {
        Vector3 forwardA = rotationA * Vector3.forward;
        Vector3 forwardB = rotationB * Vector3.forward;

        float angleA = 0.0f;
        float angleB = 0.0f;

        switch ( t )
        {
            case MegaLinkSrc.RotationXY:
                angleA = Mathf.Atan2(forwardA.x, forwardA.y) * Mathf.Rad2Deg;
                angleB = Mathf.Atan2(forwardB.x, forwardB.y) * Mathf.Rad2Deg;
                break;

            case MegaLinkSrc.RotationXZ:
                angleA = Mathf.Atan2(forwardA.x, forwardA.z) * Mathf.Rad2Deg;
                angleB = Mathf.Atan2(forwardB.x, forwardB.z) * Mathf.Rad2Deg;
                break;

            case MegaLinkSrc.RotationYZ:
                angleA = Mathf.Atan2(forwardA.y, forwardA.z) * Mathf.Rad2Deg;
                angleB = Mathf.Atan2(forwardB.y, forwardB.z) * Mathf.Rad2Deg;
                break;
        }

        return Mathf.DeltaAngle(angleA, angleB);
    }