Math : Right-handed Y-up to Unity Left-handed Y-up

Can someone give me the transformation on Unity to convert my old data on Right-handed Y-up to the Unity Left-handed Y-up.

Thanks.

2 Answers

2

Well that depends on what you need. The difference is that one axis is inverted (or two are swapped). In most cases it's the z-axis. If your righthanded-z is also forward, since y is still up and i'll guess x is still right, you just have to invert z. In a right-handed system z will point towards you in Unity(left-handed) z points away from you.

So if you have a vector V just invert z:

//C#
Vector3 V;
V.z = -V.z;

What "data" do you talk about? A mesh? You have to be careful with meshes. The winding order is different. If you invert z the triangles will face into the opposite direction to fix that you'll have to swap two indices of each triangle.

Some more details would help ;)

Well it's a complete scene, with camera definition for instance. And actually all my rotation are wrong so i guess it's not that simple ;)

A complete scene? A scene in Unity or from another application? If it's from another application i ask myself how you import those into Unity? Scenes in Unity are actually left-handed, maybe something is rotated the wrong way (but it's left-handed). Can you explain "wrong" a bit more in detail? Most rotation errors are 90, 180, 270 around one axis.

SO i'm converting an Ogre Scene, where i have allready define some Cameras (Point Of View). Now i 'm importing my 3DObject from Max but i want to use my former Camera definition ( position / rotation). So i need to transform the position and rotation of the camera to make it like before. A simple change of the position is not sufficient as they are not looking to my objects... SO i guess there is another transformation to do in order to convert a right handed Yup to left handed Yup... Thanks a lot

Well, I haven't worked with Ogre yet so i still don't know where's forward in ogre (maybe -z like in OpenGL?). Rotations just have to be rotated (if z have to be inverted 180 if x and z are swapped 90 or 270). Just multiply the rotation by Quaternion.AngleAxis(180, Vector3.up).

So for my camera i need to do that to make it work :

transform.localPosition = new Vector3(-pos.x, pos.y, pos.z);     
 transform.localRotation = new Quaternion(-quat.x, quat.y, quat.z, -quat.w);
 transform.Rotate(new Vector3(0, 180, 0));

And for objects i don't need the last Rotate...

You might want to look at http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode.html to quickly apply this to all things in your scene.