• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Edy

Quaternions: convert between Left-Right handed without using Euler

6 posts in this topic

Hello,

 

I've written a tool that converts rotations from Right Handed (Blender) to Left Handed (Unity 3D). The tool runs in Unity 3D. I'm given a quaternion with the original rotation, and I calculate the quaternion with equivalent rotation as output. The only way I've found so far requires to extract and operate the Euler angles.

 

Actually this code runs fine:

 

// "rot" contains the input Quaternion with the original rotation

rot = Quaternion.Inverse(rot);

// Rename and invert the axes via Euler.

Vector3 euler = rot.eulerAngles;
float eulerY = euler.y;
euler.x = -euler.x;
euler.y = -euler.z;
euler.z = eulerY;

// If the model has been turned around (180º) then invert the rotations around the Y axis

if (m_zReverse)
{
    euler.x = -euler.x;
    euler.z = -euler.z;
}

// Convert the Euler angles back to Quaternion

rot = Quaternion.Euler(euler);

This converts the rotations properly on static objects. The problem is that this breaks the quaternion continuity when applied to rotation keys in animations. I suspect that the conversion back and forth Euler is the cause.

 

The question is: Could the above conversion be done without actually using Euler angles? 

 

If you want to take a look at the tool itself, it's hosted at GitHub here.

 

Thank you!

Edited by Edy
0

Share this post


Link to post
Share on other sites

Let M be the (3x3) transformation matrix between the Blender coordinate system and the Unity one. Then the axis is simply transformed using M and the angle should change sign (since M does not preserve the orientation). You thus have to negate the imaginary part and then apply M to it.

 

EDIT:

The transformation between Blender and Unity coordinate systems is, if I remember correctly, (x, y, z) -> (y, z, -x). If I thus have a quaternion q0 + q1*i + q2*j + q3*k, the corresponding quaternion should be q0 - q2*i - q3*j +q1*k.

Edited by apatriarca
1

Share this post


Link to post
Share on other sites

..when applied to rotation keys in animations

If you're talking about rotations in animation keys, normally those rotations aren't with respect to the model, they're with respect to the parent of the bone/node/frame.

 

You shouldn't have to convert those rotations, but apply the right- to left-hand conversion at the root level only.

 

It likely works for static objects because the rotations are (already) with respect to the root (or world, don't know how you're implementing it).

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

Let M be the (3x3) transformation matrix between the Blender coordinate system and the Unity one. Then the axis is simply transformed using M and the angle should change sign (since M does not preserve the orientation). You thus have to negate the imaginary part and then apply M to it.

Thank you very much for this hint!  It helped me to solve the problem. Actually the above code got simplified to this:
 

rot = new Quaternion (-rot.x, -rot.z, rot.y, -rot.w);

if (m_zReverse)
    rot = new Quaternion (-rot.x, rot.y, -rot.z, rot.w);


I think that the x,y,z components are those you mention as i,j,k in your edit. The transformation from Blender to Unity is (x, y, z) -> (-x, -z, y).

 

 

..when applied to rotation keys in animations

If you're talking about rotations in animation keys, normally those rotations aren't with respect to the model, they're with respect to the parent of the bone/node/frame.

 

You shouldn't have to convert those rotations, but apply the right- to left-hand conversion at the root level only.

 

It likely works for static objects because the rotations are (already) with respect to the root (or world, don't know how you're implementing it).

Yes, I must convert those rotations because I'm converting all meshes as well. The problem is described here. If I don't convert rotations then, for example, some animation that is intended to rotate around axis Y would be applied to the actual axis Z.

 

As long as the modifications to the rotations keys are simply changing signs and exchanging components, then I can do the same with the key's tangents and the continuity is preserved. My problem was that using Euler angles I had to apply a post-processing function to the animation curve for preserving the quaternion continuity, and this introduced noticeable smoothing to the rotations (undesirable).

 

After applying the apatriarca's hint to my importer then the 2nd level (children) objects applied the rotations perfectly. But still I have a problem with the 1st level (root) objects, as I must apply their rotations an additional rotation of +90º around the X axis. I can apply this rotation to the animation keys, but then the quaternion continuity is not preserved because I don't know how to re-arrange the tangents as result of this X+90 rotation.

 

I have a new question: How could I apply a 90º rotation around X axis to a quaternion by modifying its components directly?  (q0, q1, q2, q3, or in case of Unity: w, x, y, z)

Thank you!

 

 

0

Share this post


Link to post
Share on other sites

It is a (right or left depending on the order of transformations) multiplication by the quaternion (0, 1, 0, 0).

 

(0, 1, 0, 0) * (w, x, y, z) = (-x, w, -z, y)

(w, x, y, z) * (0, 1, 0, 0) = (-x, w, z, -y)

0

Share this post


Link to post
Share on other sites

I've tried your solution directly but it didn't work. I did some tests and found that the quaternion to multiply by is (?2/2, ?2/2, 0, 0)I found a simple description of quaternion multiplication here. The correct result is:

 

(w, x, y, z) * (?2/2, ?2/2, 0, 0) = (w-x, w+x, z+y, z-y) * ?2/2

 

Applying this result on both values and tangents of the keyframes in a quaternion-based animation worked perfectly!! 

Thank you very much for your hints! They led me to find the correct solution smile.png

 

EDIT: FYI, here you can see how the new code looks like.

Edited by Edy
0

Share this post


Link to post
Share on other sites

You are right! I forgot to divide the angle by two when computing the quaternion to use.. unsure.png

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0