Search Unity

Converting to and from a Right Handed Coordinate system

Discussion in 'Scripting' started by milali, Dec 8, 2011.

  1. milali

    milali

    Joined:
    Nov 1, 2011
    Posts:
    16
    Hello.

    I originally posted this in Unity Answers but its going more towards a discussion thread so I have started one.
    old thread: http://answers.unity3d.com/questions/192354/converting-xzy-to-xyz-co-ordinate-space.html

    To continue on this. I have 2 conversion functions for the XYZ to XZY translation

    Code (csharp):
    1.  
    2. // @param in 3d position vector in Right handed Coordinate System
    3. // @param out 3d position vector in Unity Coordinate System
    4. void RHSToUnity(Vector3 in, ref Vector3 out)
    5. {
    6.   out[0] = in[1];
    7.   out[1] = in[2];
    8.   out[2] = -in[0];
    9. }
    10.  
    11. // @param in 3d position vector in Unity Coordinate System
    12. // @param out 3d position vector in Right handed Coordinate System
    13. void UnityToRHS(Vector3 in, ref Vector3 out)
    14. {
    15.   out[0] = -in[2];
    16.   out[1] = in[0];
    17.   out[2] = in[1];
    18. }
    They feel right to me as the RHS +y moves forward while +x is in unity isn't it?

    Which leaves me with the Rotation issues I have a PYR for the helicopter.

    How should it convert? its local space so technically it should just be 'right' between the two the only change would be pitch needing to be inverted yaw is around the y, roll is around the z axis? I mean roll is roll yeah? irrespective of the axis you derive it from?

    I can't get me head around this. :(
     
  2. milali

    milali

    Joined:
    Nov 1, 2011
    Posts:
    16
    Is Z forward in Unity? Or is +X? transform.forward appears to return the Z axis.

    but all my code currently works with forward being X. which doesn't feel right to me :(