1
\$\begingroup\$

I am trying to convert a transform from the Unity Coordinate System to the Unreal Engine Coordinate System (and others).

Ideally, I want to take a position, rotation (in Euler angles), and a scale as input.

In the past I somehow came up with a method that seemed to be working (but isn't now for some reason) so I must have misunderstood something. Math isn't my strong point, so if you can please explain the answer clearly, especially if there are some magic numbers.

In my previous attempt, I first figured out if a coordinate system was Left or Right handed, identified the directional vectors (forward, right, up) and then tried to equate them to each other. Below is an example using the coordinate systems for UE, Unity, and TouchDesigner (please excuse the omission of scale).

I should also mention that I am actually using my Unity -> UE form right now successfully, it's actually the TouchDesigner -> UE function that is having trouble. I can only assume my attempted solution accidentally works only in the Unity/UE case.

** Please note that I am using Quaternions and not Euler angles**

Source Coordinate Systems
---------------------------------
TD (Right handed)
X = right
Y = up
Z = backwards

Unreal (Left handed)
X = forwards
Y = right
Z = up

Unity (Left handed)
X = right
Y = up
Z = forwards

Position Conversions
-------------------------
UE <-> TD
TD_X = right     =  UE_Y
TD_Y = up        =  UE_Z
TD_Z = backwards = -UE_X

TD_X =  UE_Y
TD_Y =  UE_Z
TD_Z = -UE_X

UE_X = -TD_Z
UE_Y =  TD_X
UE_Z =  TD_Y

TD <-> Unity
U_X = right   =  TD_X
U_Y = up      =  TD_Y
U_Z = forward = -TD_Z

U_X =  TD_X
U_Y =  TD_Y
U_Z = -TD_Z

TD_X =  U_X
TD_Y =  U_Y
TD_Z = -U_Z

Unity -> UE
U_X = right   =  UE_Y
U_Y = up      =  UE_Z
U_Z = forward =  UE_X

U_X = UE_Y
U_Y = UE_Z
U_Z = UE_X

UE_X = U_Z
UE_Y = U_X
UE_Z = U_Y

Rotation Conversions
--------------------------
*** To switch hands multiply XYZ by -1 (leave W as is)
UE <-> TD
TD_X = right     =  UE_Y
TD_Y = up        =  UE_Z
TD_Z = backwards = -UE_X
TD_W = UE_W

// Convert coordinate space
TD_X = right     = -1 *  UE_Y
TD_Y = up        = -1 *  UE_Z
TD_Z = backwards = -1 * -UE_X
TD_W = UE_W

TD_X = -UE_Y
TD_Y = -UE_Z
TD_Z =  UE_X
TD_W =  UE_W

UE_X =  TD_Z
UE_Y = -TD_X
UE_Z = -TD_Y
UE_W =  TD_W

TD <-> Unity
U_X = right   =  TD_X
U_Y = up      =  TD_Y
U_Z = forward = -TD_Z
U_W = TD_W

//Convert coordinate space
U_X = -1 *  TD_X
U_Y = -1 *  TD_Y
U_Z = -1 * -TD_Z
U_W = TD_W

U_X = -TD_X
U_Y = -TD_Y
U_Z = TD_Z
U_W = TD_W

TD_X = -U_X
TD_Y = -U_Y
TD_Z = U_Z
TD_W = U_W

Unity -> UE
U_X = right   =  UE_Y
U_Y = up      =  UE_Z
U_Z = forward =  UE_X
U_W = UE_W

U_X = UE_Y
U_Y = UE_Z
U_Z = UE_X
U_W = UE_W

UE_X = U_Z
UE_Y = U_X
UE_Z = U_Y
UE_W = U_W
\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.