Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by artie · Jul 29, 2013 at 05:37 PM · transformconverteulercoordinate-systemright-hand

Need to convert to/from right-handed coordinates

I need to convert Unity's left-handed coordinates to/from right-handed for some export/import functionality. Flipping a sign is not enough, I need the rotations to be correct too. So I'm hoping for a function that converts a Transform to right-handed. I've seen some posts on the net about matrices and stuff, I'm hoping to avoid that. Just need position and euler angles to be converted. Thanks.

(Would it be enough to convert to axis/angle, flip the z-axis, then read off the eulers?)

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gardian06 · Jul 31, 2013 at 02:50 PM 0
Share

you do realize that saying right-handed/left-handed actually doesn't say much (considering that in all reality handedness only ever talks about x). all you have said is what way the positive x values point. because the conversion from left-handed physics (x-right, y-up) to right handed physics(x-left, y-up) is different from left-handed physics(x-right, y-up) to right-handed math(x-left, z-up).

can you be more specific because there is an immediate difference even in your position transformation.

avatar image artie · Aug 02, 2013 at 05:10 PM 0
Share

Right. So converting position is easy, just negate x or y or z. I negate z and all positions look ok. However, rotations are not so simple. When the local z-axis is aligned with world z, a positive rotation in LHC will result in the opposite rotation in RHC. But I can't simply negate an euler angle (at least, I have not found a combo that works in all cases). I tried converting the rotation to axis/angle, negating z, and reading out the eulers. This 'seems' to work, but it's still off, does not look right in all cases (unless I have another bug somewhere). I saw some posting in other forums about needing to know the rotation order (xyz vs zxy vs xzy etc) and there are 36 combinations of that. A bit daunting for me to try them all. I gotta figure there's an easier way than trial/error. There must be a single formula, or maybe a small series of lines of code, which can solve this. Can I play tricks with Quaternions? At this point, if anyone has any solution that works, even if it involves mucking with matrices, I'm game.

avatar image Bunny83 · Aug 03, 2013 at 09:40 AM 0
Share

You face multiple problems when converting between left and right handed systems. As you said the positions are quite easy, however it also depends on how your target system looks like. There are several representations of a right handed system.

If you search with this link:
http://www.google.com?q=convert+from+left+handed+to+right+handed

You will find this document:
http://answers.unity3d.com/storage/temp/12048-lefthandedtorighthanded.pdf

Btw: The more common system is the right-handed system. OpenGL (which is more math based) uses a righthanded system by default. DirectX (which is more problem orientated) uses a left handed system. Both can use both systems. The Left handed system is more useful for game engines because you can use x-y as the screen plane and z as depth. However even in screen space there are several ways (0,0 at left bottom or at left top).

avatar image artie · Aug 04, 2013 at 05:13 AM 0
Share

Yes I had seen that PDF. It has no Unity code in it :( and this matrix stuff is a little beyond me. It looks like the 'composite' stuff might be able to convert from left to right. I also need right to left. $$anonymous$$y target system: I don't know beyond Y up, X right, Z out (all same as Unity except the direction of Z)

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Aug 06, 2013 at 02:06 AM

I think you can convert to axis/angle and flip the z axis, but also negate the angle before putting them back. Something like (untested):

 // convert to quat (make a dummy object so you can use the transform?
 dummyGO.transform.eulerAngles = new Vector3(rX, rY, rZ);
                 
 var angle = 0.0;
 var axis = Vector3.zero;
 dummyGO.transform.rotation.ToAngleAxis(angle, axis);
 axis.z = -axis.z;
 dummyGO.transform.rotation = Quaternion.AngleAxis(-angle, axis);
 var lX = dummyGO.transform.rotation.x; // etc.

Alternately:

 dummyGO.transform.eulerAngles = Vector3.zero;
 dummyGO.transform.Rotate(0,0, rZ, Space.Self);
 dummyGO.transform.Rotate(-rX,0,0, Space.Self);
 dummyGO.transform.Rotate(0,-rY, 0, Space.Self);

or

 dummyGO.transform.eulerAngles = Vector3.zero;
 dummyGO.transform.Rotate(-rX, -ry, rZ);


You may also want to read this: http://sarveshspn.blogspot.com/2012/04/3d-graphics-left-handed-vs-right-handed.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fssdev · Aug 25, 2017 at 07:56 PM 0
Share

That is an invite only blog

avatar image
0

Answer by gardian06 · Jul 29, 2013 at 09:09 PM

because Unity Answers is supposed to be a repository of useful information that any user can plug in a question they have, and get on the right track, and also in several cases it is possible for more then one solution to be given (in several cases a more simple one)

and the reason that many of results you find are matrices is because that is the fundamental definition of a coordinate system.

if you don't want to use the matrices themselves then use the abstracted result of the matrices: take the euler angle of the quat, and then use the derived result of rotating the axes (no it is not just flip the z) then you get out a right Handed quat.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image artie · Jul 29, 2013 at 09:16 PM 0
Share

Ok thanks. All I know is the docs on the format say 'right handed' so that's why I need to convert, and I know that position can be 'fixed' by inverting Z, but rotation is trickier.

I will do matrices if really needed, but will try this euler-from-quat idea. I'm fuzzy on how to 'derive the result of rotating the axes'. Can you explain more? I'm also guessing this is not rotataing about Y 180 degrees...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot convert `UnityEngine.Transform' expression to type `UnityEngine.Vector3'(Solved) 2 Answers

Symmetry for hand 0 Answers

Quaternion, Eulers and Problems 1 Answer

Is there any way to set a Gameobject's transform matrix to be the World Space? 0 Answers

How to set euler.z to zero while keeping orientation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges