I recently face-palmed when realizing that once again, I had set my own application up with Y as the up axis, but was importing all my assets from 3dsmax where Z is the up axis. I am using the Physx exporter and importing using the PXU library. Rather than re-write large portions of my code, I decided to just iterate through imported matricies and convert them from Z up to Y up.

When you are no matricies expert, this can be tough, there are a lot of people asking how to do this and there isn’t a whole lot out there to help you, which is why I am writing this post.

Physx uses 4×3 matricies for transformation, being a 3×3 rotation matrix with a 1×3 translation vector.

Converting the position is easy, just swap the Y and Z values:

vector3 position;

float temp = position.y;

position.y = position.z;

position.z = temp;

But transforming the rotation vector is a whole lot harder. At first thought you may think “hey, just rotate 90 degrees on the X axis” but no, unfortunately this doesn’t work. The actual solution is just like fixing the position, swap the Y and Z values.

On a 3×3 matrix this is slightly more confusing. What are the Y and Z values? Well, I will assume that you realise a 3×3 matrix is a 3×3 grid of numbers. To swap the Y and Z values, you must swap the second and third columns AND the second and third rows:

matrix33 rotation;

vector3 temp;

temp = rotation.column2;

rotation.column2 = rotation.column3;

rotation.column3 = temp;

temp = rotation.row2;

rotation.row2 = rotation.row3;

rotation.row3 = temp;

If this helps, please give me some feedback in the comments and let me know how it went. micromacro

About these ads