Search Unity

Quaternion.Euler and quaternion.euler produce radically different results.

Discussion in 'Entity Component System' started by Geminior, Dec 14, 2018.

  1. Geminior

    Geminior

    Joined:
    Feb 12, 2014
    Posts:
    322
    Title says it all. If you do e.g.
    Quaternion.Euler(55f, 0f, 0f) you get a completely different result than quaternion.euler(55f, 0f, 0f).
    Unity.Mathematics 0.0.12 preview 19
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Of course, because Quaternion.Euler use degrees and quaternion.euler use radians, use math.radians for convert.
     
    Last edited: Dec 14, 2018
  3. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    I also notice that there are some differences...

    E.g. quaternion.LookRotation() produces in some situations different results than Quaternion.LookRotation()
     
  4. Geminior

    Geminior

    Joined:
    Feb 12, 2014
    Posts:
    322
    I fail to see how this is obvious, but thanks for the clarification anyhow.
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    The Mathematics lib ones is expecting all unit vectors. If you use quaternion.LookRotationSafe then probably is the same as old version
     
    Spy-Shifty likes this.
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Not trying to be an ass or anything but this is mentioned multiple times in the XML summary for the method

    Code (CSharp):
    1.         /// <summary>
    2.         /// Returns a quaternion constructed by first performing 3 rotations around the principal axes in a given order.
    3.         /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
    4.         /// When the rotation order is known at compile time, it is recommended for performance reasons to use specific
    5.         /// Euler rotation constructors such as EulerZXY(...).
    6.         /// </summary>
    7.         /// <param name="x">The rotation angle around the x-axis in radians.</param>
    8.         /// <param name="y">The rotation angle around the y-axis in radians.</param>
    9.         /// <param name="z">The rotation angle around the z-axis in radians.</param>
    10.         /// <param name="order">The order in which the rotations are applied.</param>
    11.         [MethodImpl(MethodImplOptions.AggressiveInlining)]
    12.         public static quaternion Euler(float x, float y, float z, RotationOrder order = RotationOrder.Default)
    Usually a good place first place to look. The Mathematics library is well documented (unlike certain other parts of unity)
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Feels like the functions should be self documenting though. IE:

    Quaternion.EulerDegrees(0, 0.5f, 0);
    quaternion.EulerRadians(0, 0.5f, 0);

    Given that they look similar, I see this creating lots of bugs no matter what the documentation says. That, or get rid of one of the functions and require the user to do the conversion.
     
    PixelMind, FROS7 and SugoiDev like this.